MessageHandler.c 777 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int localversion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //=============================================
  81. // OCPP HeartBeat Response Not Receive Counts
  82. //============================================
  83. static int HeartBeatWithNOResponse = 0;
  84. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  85. extern sqlite3 *db;
  86. int TransactionMessageAttemptsGet(void);
  87. int TransactionMessageRetryIntervalGet(void);
  88. int GetOcppConnStatus(void);
  89. void SetOcppConnStatus(uint8_t status);
  90. int setKeyValue(char *key, char *value);
  91. void OCPP_get_TableAuthlocalAllData(void);
  92. void processUnkownKey(void);
  93. struct StructOCPPMeterValue
  94. {
  95. unsigned char TimeStamp[28];
  96. struct StructSampledValue SampledValue[10];
  97. };
  98. struct ClientTime
  99. {
  100. unsigned int Heartbeat;
  101. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  102. unsigned int StartTransaction;
  103. unsigned int StopTransaction;
  104. unsigned int MeterValues[CONNECTOR_QUANTITY];
  105. }clientTime;
  106. typedef union
  107. {
  108. //Operations Initiated by Central System
  109. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  110. struct
  111. {
  112. //CsMsgValue[0]
  113. unsigned char StatusNotificationReq:1; //bit 0,
  114. unsigned char StatusNotificationConf:1; //bit 1,
  115. unsigned char TriggerMeterValue:1; //bit 2,
  116. unsigned char :5; //bit 5~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // Save configuration
  356. //=========================================
  357. int runShellCmd(const char*cmd)
  358. {
  359. int result = FAIL;
  360. char buf[256];
  361. FILE *fp;
  362. fp = popen(cmd, "r");
  363. if(fp != NULL)
  364. {
  365. while(fgets(buf, sizeof(buf), fp) != NULL)
  366. {
  367. DEBUG_INFO("%s\n", buf);
  368. }
  369. result = PASS;
  370. }
  371. pclose(fp);
  372. return result;
  373. }
  374. int StoreUsrConfigData(struct SysConfigData *UsrData)
  375. {
  376. int result = PASS;
  377. int fd,wrd;
  378. unsigned int i,Chk;
  379. unsigned char *ptr, *BufTmp;
  380. int MtdBlockSize = 0x300000;
  381. Chk=0;
  382. ptr=(unsigned char *)UsrData;
  383. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  384. {
  385. memset(BufTmp,0,MtdBlockSize);
  386. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  387. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  388. Chk+=*(BufTmp+i);
  389. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  390. // Output configuration to file.
  391. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  392. if (fd < 0)
  393. {
  394. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  395. free(BufTmp);
  396. return 0;
  397. }
  398. wrd=write(fd, BufTmp, MtdBlockSize);
  399. close(fd);
  400. if(wrd<MtdBlockSize)
  401. {
  402. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  407. DEBUG_INFO("Erase /dev/mtd10.\n");
  408. runShellCmd("flash_erase /dev/mtd10 0 0");
  409. DEBUG_INFO("Write /dev/mtd10.\n");
  410. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  411. DEBUG_INFO("Erase /dev/mtd11.\n");
  412. runShellCmd("flash_erase /dev/mtd11 0 0");
  413. DEBUG_INFO("Write /dev/mtd11.\n");
  414. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  415. system("rm -f /mnt/EvseConfig.bin");
  416. DEBUG_INFO("EvseConfig write to flash OK\n");
  417. }
  418. else
  419. {
  420. DEBUG_ERROR("alloc BlockSize NG\r\n");
  421. result = FAIL;
  422. }
  423. if(BufTmp!=NULL)
  424. free(BufTmp);
  425. return result;
  426. }
  427. //=========================================
  428. // Sqlite3 related function
  429. //=========================================
  430. static int selectSqlCount = 0;
  431. static int callback(void *data, int argc, char **argv, char **azColName){
  432. int i;
  433. //printf("%s: ", (const char*)data);
  434. selectSqlCount = argc;
  435. for(i = 0; i<argc; i++){
  436. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  437. }
  438. //printf("\n");
  439. return 0;
  440. }
  441. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  442. //int i;
  443. //printf("%s:\n", (const char*)data);
  444. localversion = argv[5] ? atoi(argv[5]) : 0;
  445. //printf("localversion=%d\n", localversion);
  446. return 0;
  447. }
  448. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  449. //printf("%s:\n", (const char*)data);
  450. //idTag
  451. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  452. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  453. //parentIdTag
  454. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  455. //expir_date
  456. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  457. //status
  458. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  459. //version
  460. if(columenCount > 5)
  461. idTagQuery.listVersionInt = atoi(columnValue[5]);
  462. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  463. return 0;
  464. }
  465. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  466. {
  467. // localversion = argv[5] ? atoi(argv[5]) : 0;
  468. // printf("localversion=%d\n", localversion);
  469. return 0;
  470. }
  471. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  472. {
  473. for (int i = 0; i < n_columns; i++)
  474. {
  475. DEBUG_INFO("%s\t", col_values[i]);
  476. }
  477. DEBUG_INFO("\n");
  478. return 0;
  479. }
  480. int OCPP_cleanLocalCache()
  481. {
  482. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  483. char *errMsg = 0;
  484. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  485. if (SQLITE_OK != rc)
  486. {
  487. DEBUG_INFO("SQL error: %s\n",errMsg);
  488. return FALSE;
  489. }
  490. return TRUE;
  491. }
  492. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  493. {
  494. int isSuccess = TRUE;
  495. int ret = 0;
  496. //const char* data = "Callback function called";
  497. char sql[300];
  498. char zErrMsg[200];
  499. memset(sql, 0, 300);
  500. memset(zErrMsg, 0, 200);
  501. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  502. //* Execute SQL statement */
  503. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  504. if( ret != SQLITE_OK )
  505. {
  506. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  507. isSuccess = FALSE;
  508. }
  509. return isSuccess;
  510. }
  511. void OCPP_getIdTagFromLocalCache(char idTag[])
  512. {
  513. int rc = 0;
  514. char sql[100];
  515. char zErrMsg[100];
  516. memset(sql, 0, 100);
  517. memset(zErrMsg, 0, 100);
  518. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  519. memset(&idTagQuery, 0, sizeof(idTagQuery));
  520. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  521. /* Execute SQL statement */
  522. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  523. if( rc != SQLITE_OK )
  524. {
  525. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  526. }
  527. }
  528. void OCPP_getListVerion()
  529. {
  530. int rc = 0;
  531. // const char* data = "Callback function called";
  532. char sql[100];
  533. char zErrMsg[100];
  534. memset(sql, 0, 100);
  535. memset(zErrMsg, 0, 100);
  536. strcpy(sql, "select * from ocpp_auth_local order by idx");
  537. /* Execute SQL statement */
  538. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  539. if( rc != SQLITE_OK )
  540. {
  541. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  542. }
  543. }
  544. void OCPP_get_TableAuthlocalAllData(void)
  545. {
  546. int rc = 0;
  547. char sql[100];
  548. char zErrMsg[100];
  549. memset(sql, 0, 100);
  550. memset(zErrMsg, 0, 100);
  551. sprintf(sql,"select * from ocpp_auth_local ");
  552. /* Execute SQL statement */
  553. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  554. if( rc != SQLITE_OK )
  555. {
  556. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  557. }
  558. //return ver;
  559. }
  560. int OCPP_cleanLocalList()
  561. {
  562. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  563. char *errMsg = 0;
  564. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  565. if (SQLITE_OK != rc)
  566. {
  567. DEBUG_INFO("%s\n",errMsg);
  568. return FALSE;
  569. }
  570. return TRUE;
  571. }
  572. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  573. {
  574. int isSuccess = FALSE;
  575. int ret = 0;
  576. //const char* data = "Callback function called";
  577. char sql[300];
  578. char zErrMsg[200];
  579. memset(sql, 0, 300);
  580. memset(zErrMsg, 0, 200);
  581. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  582. //* Execute SQL statement */
  583. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  584. if( ret != SQLITE_OK )
  585. {
  586. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  587. return isSuccess;
  588. }
  589. memset(sql, 0, 300);
  590. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  591. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. isSuccess = TRUE;
  598. return isSuccess;
  599. }
  600. void OCPP_getIdTagFromLocalList(char idTag[])
  601. {
  602. int rc = 0;
  603. // const char* data = "Callback function called";
  604. char sql[100];
  605. char zErrMsg[100];
  606. memset(sql, 0, 100);
  607. memset(zErrMsg, 0, 100);
  608. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  609. memset(&idTagQuery, 0, sizeof(idTagQuery));
  610. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  611. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  612. /* Execute SQL statement */
  613. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  614. if( rc != SQLITE_OK )
  615. {
  616. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  617. }
  618. //return ver;
  619. }
  620. void OCPP_deleteIdTagFromLocalList(char idTag[])
  621. {
  622. //int ver = 0;
  623. //int isSuccess = FALSE;
  624. int rc = 0;
  625. char sql[100];
  626. char zErrMsg[100];
  627. memset(sql, 0, 100);
  628. memset(zErrMsg, 0, 100);
  629. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  630. //* Execute SQL statement */
  631. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  632. if( rc != SQLITE_OK )
  633. {
  634. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  635. }
  636. }
  637. int getCurrentYear()
  638. {
  639. int result = 0;
  640. time_t CurrentTime;
  641. struct tm *tm;
  642. CurrentTime = time(NULL);
  643. tm=localtime(&CurrentTime);
  644. result = (tm->tm_year + 1900);
  645. return result;
  646. }
  647. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  648. {
  649. int result = PASS;
  650. char* errMsg = NULL;
  651. char sqlStr[8192];
  652. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  653. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  654. {
  655. result = FAIL;
  656. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  657. }
  658. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  659. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  660. {
  661. result = FAIL;
  662. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  663. }
  664. return result;
  665. }
  666. //==========================================
  667. // Check time passed since today
  668. //==========================================
  669. long long DiffTimebWithNow(struct timeb ST)
  670. {
  671. //return milli-second
  672. struct timeb ET;
  673. long long StartTime,StopTime;
  674. ftime(&ET);
  675. StartTime=(long long)ST.time;
  676. StopTime=(long long)ET.time;
  677. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  678. }
  679. int getTimePassSinceToday(uint8_t gun_index)
  680. {
  681. int result = -1;
  682. static time_t lastTime[4];
  683. time_t t;
  684. struct tm *tmStartToday;
  685. struct timeb tbStartToday;
  686. t=time(NULL);
  687. if(difftime(t, lastTime[gun_index])>0)
  688. {
  689. tmStartToday=localtime(&t);
  690. tmStartToday->tm_hour = 0;
  691. tmStartToday->tm_min = 0;
  692. tmStartToday->tm_sec = 0;
  693. tbStartToday.time = mktime(tmStartToday);
  694. tbStartToday.millitm = 0;
  695. result = DiffTimebWithNow(tbStartToday)/1000;
  696. lastTime[gun_index] = t;
  697. }
  698. return result;
  699. }
  700. void getNowDatetime(uint8_t *data)
  701. {
  702. time_t t = time(NULL);
  703. struct tm tm = *localtime(&t);
  704. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  705. }
  706. int syncDateTimeRTC(uint8_t *data)
  707. {
  708. struct ParsingResult
  709. {
  710. int result;
  711. int scanedElement;
  712. int year;
  713. int month;
  714. int mday;
  715. int hour;
  716. int min;
  717. int sec;
  718. int tz_hour;
  719. int tz_min;
  720. float minSec;
  721. }result;
  722. struct tm tmOrg;
  723. struct tm *tmTarget;
  724. struct timeb tbTarget;
  725. char buf[128];
  726. memset(&result, 0x00, sizeof(struct ParsingResult));
  727. result.result = PASS;
  728. if(strstr((char*)data, ".") != NULL)
  729. {
  730. // Original data with mini second
  731. if(strstr((char*)data, "Z") != NULL)
  732. {
  733. // Original data with Z
  734. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  735. &result.year,
  736. &result.month,
  737. &result.mday,
  738. &result.hour,
  739. &result.min,
  740. &result.sec,
  741. &result.minSec);
  742. }
  743. else
  744. {
  745. // Original data without Z
  746. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  747. &result.year,
  748. &result.month,
  749. &result.mday,
  750. &result.hour,
  751. &result.min,
  752. &result.sec,
  753. &result.minSec,
  754. &result.tz_hour,
  755. &result.tz_min);
  756. }
  757. }
  758. else
  759. {
  760. // Original data without mini second
  761. if(strstr((char*)data, "Z") != NULL)
  762. {
  763. // Original data with Z
  764. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  765. &result.year,
  766. &result.month,
  767. &result.mday,
  768. &result.hour,
  769. &result.min,
  770. &result.sec);
  771. }
  772. else
  773. {
  774. // Original data without Z
  775. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  776. &result.year,
  777. &result.month,
  778. &result.mday,
  779. &result.hour,
  780. &result.min,
  781. &result.sec,
  782. &result.tz_hour,
  783. &result.tz_min);
  784. }
  785. }
  786. tmOrg.tm_year = result.year - 1900;
  787. tmOrg.tm_mon = result.month - 1;
  788. tmOrg.tm_mday = result.mday;
  789. tmOrg.tm_hour = result.hour;
  790. tmOrg.tm_min = result.min;
  791. tmOrg.tm_sec = result.sec;
  792. tmOrg.tm_gmtoff = 0;
  793. tbTarget.time = mktime(&tmOrg);
  794. tbTarget.timezone = 0;
  795. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  796. tmTarget = gmtime(&tbTarget.time);
  797. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  798. //DEBUG_INFO(" org date time: %s\n", data);
  799. //DEBUG_INFO("parse date time: %s\n", buf);
  800. system(buf);
  801. system("/sbin/hwclock -w --systohc");
  802. if(result.scanedElement < 6)
  803. result.result = FAIL;
  804. return result.result;
  805. }
  806. //==========================================
  807. // GetCompositeSchedule logic related function
  808. //==========================================
  809. int DiffTimebSec(struct timeb ST, struct timeb ET)
  810. {
  811. //return milli-second
  812. unsigned int StartTime,StopTime;
  813. StartTime=(unsigned int)ST.time;
  814. StopTime=(unsigned int)ET.time;
  815. return (StopTime-StartTime);
  816. }
  817. int DiffTimebWithNowSec(struct timeb ST)
  818. {
  819. //return milli-second
  820. struct timeb ET;
  821. unsigned int StartTime,StopTime;
  822. ftime(&ET);
  823. StartTime=(unsigned int)ST.time;
  824. StopTime=(unsigned int)ET.time;
  825. return (StopTime-StartTime);
  826. }
  827. int getStartStop(uint8_t *start, uint8_t *stop)
  828. {
  829. int result = -1;
  830. struct tm tmStart;
  831. struct timeb tbStart;
  832. struct tm tmStop;
  833. struct timeb tbStop;
  834. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  835. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  836. {
  837. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  838. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  839. tmStart.tm_year -= 1900;
  840. tmStart.tm_mon -= 1;
  841. tbStart.time = mktime(&tmStart);
  842. tbStart.millitm = 0;
  843. tmStop.tm_year -= 1900;
  844. tmStop.tm_mon -= 1;
  845. tbStop.time = mktime(&tmStop);
  846. tbStop.millitm = 0;
  847. result = DiffTimebSec(tbStart, tbStop);
  848. //DEBUG_INFO("getStartStop(): %d\n", result);
  849. }
  850. else
  851. {
  852. DEBUG_WARN("Start or stop date parsing error.\r\n");
  853. }
  854. return result;
  855. }
  856. int isOvertNow(uint8_t *start)
  857. {
  858. int result = NO;
  859. struct tm tmStart;
  860. struct timeb tbStart;
  861. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  862. {
  863. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  864. tmStart.tm_year -= 1900;
  865. tmStart.tm_mon -= 1;
  866. tbStart.time = mktime(&tmStart);
  867. tbStart.millitm = 0;
  868. if(DiffTimebWithNowSec(tbStart) <= 0)
  869. result = NO;
  870. else
  871. result = YES;
  872. }
  873. else
  874. {
  875. DEBUG_WARN("Start date parsing error.\n");
  876. }
  877. return result;
  878. }
  879. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  880. {
  881. int result = -1;
  882. struct tm tmStart;
  883. struct timeb tbStart;
  884. struct tm tmStop;
  885. struct timeb tbStop;
  886. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  887. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  888. {
  889. tmStart.tm_year -= 1900;
  890. tmStart.tm_mon -= 1;
  891. tbStart.time = mktime(&tmStart);
  892. tbStart.millitm = 0;
  893. tmStop.tm_year -= 1900;
  894. tmStop.tm_mon -= 1;
  895. tbStop.time = mktime(&tmStop);
  896. tbStop.millitm = 0;
  897. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  898. }
  899. return result;
  900. }
  901. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  902. {
  903. FILE *fp;
  904. char profileFileName[128];
  905. char *line = NULL;
  906. size_t len = 0;
  907. time_t CurrentTime;
  908. struct tm *tmComposite;
  909. struct StructChargingProfile maxProfile;
  910. struct StructChargingProfile defaultTxProfile;
  911. struct StructChargingProfile txProfile;
  912. struct StructChargingSchedulePeriod tmpPeriod;
  913. uint8_t limitMax=0;
  914. uint8_t limitDef=0;
  915. uint8_t limitTx=0;
  916. int compositePeriodIdx = 0;
  917. CurrentTime = time(NULL);
  918. tmComposite=localtime(&CurrentTime);
  919. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  920. if(isUnitA)
  921. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  922. else
  923. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  924. compositeProfile->ChargingSchedule.Duration = durationReq;
  925. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  926. {
  927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  928. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  929. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  930. }
  931. compositeProfile->ChargingProfileId = 0;
  932. compositeProfile->StackLevel = 99 ;
  933. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  934. maxProfile.ChargingProfileId = -1;
  935. defaultTxProfile.ChargingProfileId = -1;
  936. txProfile.ChargingProfileId = -1;
  937. maxProfile.ChargingSchedule.Duration = -1;
  938. defaultTxProfile.ChargingSchedule.Duration = -1;
  939. txProfile.ChargingSchedule.Duration = -1;
  940. system("rm -f /tmp/*.json");
  941. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  942. /*
  943. * Search valid charging profile
  944. */
  945. //DEBUG_INFO("====================================\n");
  946. // Search tx profile
  947. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  948. if((access(profileFileName, F_OK))!=-1)
  949. {
  950. fp = fopen(profileFileName, "r");
  951. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  952. {
  953. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  954. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  955. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  956. }
  957. txProfile.ChargingProfileId = -1;
  958. txProfile.StackLevel = -1;
  959. while(getline(&line, &len, fp) != -1)
  960. {
  961. json_object *obj = NULL;
  962. obj = json_tokener_parse(line);
  963. if(is_error(obj))
  964. {
  965. DEBUG_ERROR("Parse txProfile from file error.\n");
  966. }
  967. else
  968. {
  969. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  970. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  971. )
  972. {
  973. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  974. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  975. )
  976. {
  977. struct tm tmFrom, tmTo;
  978. struct timeb tbFrom, tbTo;
  979. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  980. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  981. {
  982. tmFrom.tm_year -= 1900;
  983. tmFrom.tm_mon -= 1;
  984. tbFrom.time = mktime(&tmFrom);
  985. tmTo.tm_year -= 1900;
  986. tmTo.tm_mon -= 1;
  987. tbTo.time = mktime(&tmTo);
  988. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  989. {
  990. if(txProfile.ChargingProfileId == -1)
  991. DEBUG_INFO("TxProfile found.\n");
  992. else
  993. DEBUG_INFO("TxProfile updated.\n");
  994. // Required item
  995. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  996. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  997. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  998. if(isUnitA)
  999. {
  1000. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1001. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1002. {
  1003. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1004. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1005. 3:
  1006. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1007. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1008. }
  1009. }
  1010. else
  1011. {
  1012. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1013. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1014. {
  1015. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1016. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1017. 3:
  1018. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1019. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1020. }
  1021. }
  1022. // Optional item
  1023. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1024. {
  1025. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1026. }
  1027. else
  1028. {
  1029. sprintf((char*)txProfile.ValidFrom, " ");
  1030. }
  1031. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1032. {
  1033. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1034. }
  1035. else
  1036. {
  1037. sprintf((char*)txProfile.ValidTo, " ");
  1038. }
  1039. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1040. {
  1041. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1042. }
  1043. else
  1044. {
  1045. sprintf((char*)txProfile.RecurrencyKind, " ");
  1046. }
  1047. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1048. {
  1049. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1050. }
  1051. else
  1052. {
  1053. txProfile.TransactionId = -1;
  1054. }
  1055. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1056. {
  1057. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1058. }
  1059. else
  1060. {
  1061. txProfile.ChargingSchedule.Duration = 86400;
  1062. }
  1063. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1064. {
  1065. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1066. }
  1067. else
  1068. {
  1069. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1070. }
  1071. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1072. {
  1073. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1074. }
  1075. else
  1076. {
  1077. txProfile.ChargingSchedule.MinChargingRate = -1;
  1078. }
  1079. }
  1080. }
  1081. }
  1082. else
  1083. {
  1084. if(txProfile.ChargingProfileId == -1)
  1085. DEBUG_INFO("TxProfile found.\n");
  1086. else
  1087. DEBUG_INFO("TxProfile updated.\n");
  1088. // Required item
  1089. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1090. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1091. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1092. if(isUnitA)
  1093. {
  1094. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1095. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1096. {
  1097. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1098. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1099. 3:
  1100. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1101. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1102. }
  1103. }
  1104. else
  1105. {
  1106. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1107. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1108. {
  1109. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1110. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1111. 3:
  1112. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1113. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1114. }
  1115. }
  1116. // Optional item
  1117. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1118. {
  1119. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1120. }
  1121. else
  1122. {
  1123. sprintf((char*)txProfile.ValidFrom, " ");
  1124. }
  1125. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1126. {
  1127. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1128. }
  1129. else
  1130. {
  1131. sprintf((char*)txProfile.ValidTo, " ");
  1132. }
  1133. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1134. {
  1135. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1136. }
  1137. else
  1138. {
  1139. sprintf((char*)txProfile.RecurrencyKind, " ");
  1140. }
  1141. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1142. {
  1143. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1144. }
  1145. else
  1146. {
  1147. txProfile.TransactionId = -1;
  1148. }
  1149. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1150. {
  1151. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1152. }
  1153. else
  1154. {
  1155. txProfile.ChargingSchedule.Duration = 86400;
  1156. }
  1157. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1158. {
  1159. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1160. }
  1161. else
  1162. {
  1163. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1164. }
  1165. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1166. {
  1167. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1168. }
  1169. else
  1170. {
  1171. txProfile.ChargingSchedule.MinChargingRate = -1;
  1172. }
  1173. }
  1174. }
  1175. }
  1176. json_object_put(obj);
  1177. }
  1178. fclose(fp);
  1179. /*
  1180. if(txProfile.ChargingProfileId != -1)
  1181. {
  1182. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1183. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1184. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1185. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1186. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1187. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1188. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1189. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1190. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1191. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1192. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1193. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1194. {
  1195. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1196. {
  1197. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1198. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1199. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1200. }
  1201. }
  1202. }
  1203. else
  1204. DEBUG_INFO("TxProfile not found.\n");*/
  1205. }
  1206. // Search default tx profile
  1207. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1208. if((access(profileFileName, F_OK))==-1)
  1209. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1210. if((access(profileFileName, F_OK))!=-1)
  1211. {
  1212. fp = fopen(profileFileName, "r");
  1213. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1214. {
  1215. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1216. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1217. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1218. }
  1219. defaultTxProfile.ChargingProfileId = -1;
  1220. defaultTxProfile.StackLevel = -1;
  1221. while(getline(&line, &len, fp) != -1)
  1222. {
  1223. json_object *obj = NULL;
  1224. obj = json_tokener_parse(line);
  1225. if(is_error(obj))
  1226. {
  1227. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1228. }
  1229. else
  1230. {
  1231. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1232. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1233. )
  1234. {
  1235. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1236. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1237. )
  1238. {
  1239. struct tm tmFrom, tmTo;
  1240. struct timeb tbFrom, tbTo;
  1241. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1242. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1243. {
  1244. tmFrom.tm_year -= 1900;
  1245. tmFrom.tm_mon -= 1;
  1246. tbFrom.time = mktime(&tmFrom);
  1247. tmTo.tm_year -= 1900;
  1248. tmTo.tm_mon -= 1;
  1249. tbTo.time = mktime(&tmTo);
  1250. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1251. {
  1252. if(defaultTxProfile.ChargingProfileId == -1)
  1253. DEBUG_INFO("TxDefaultProfile found.\n");
  1254. else
  1255. DEBUG_INFO("TxDefaultProfile updated.\n");
  1256. // Required item
  1257. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1258. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1259. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1260. if(isUnitA)
  1261. {
  1262. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1263. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1264. {
  1265. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1266. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1267. 3:
  1268. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1269. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1270. }
  1271. }
  1272. else
  1273. {
  1274. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1275. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1276. {
  1277. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1278. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1279. 3:
  1280. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1281. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1282. }
  1283. }
  1284. // Optional item
  1285. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1286. {
  1287. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1288. }
  1289. else
  1290. {
  1291. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1292. }
  1293. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1294. {
  1295. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1296. }
  1297. else
  1298. {
  1299. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1300. }
  1301. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1302. {
  1303. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1304. }
  1305. else
  1306. {
  1307. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1308. }
  1309. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1310. {
  1311. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1312. }
  1313. else
  1314. {
  1315. defaultTxProfile.TransactionId = -1;
  1316. }
  1317. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1318. {
  1319. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1320. }
  1321. else
  1322. {
  1323. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1324. }
  1325. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1326. {
  1327. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1328. }
  1329. else
  1330. {
  1331. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1332. }
  1333. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1334. {
  1335. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1336. }
  1337. else
  1338. {
  1339. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1340. }
  1341. }
  1342. }
  1343. }
  1344. else
  1345. {
  1346. if(defaultTxProfile.ChargingProfileId == -1)
  1347. DEBUG_INFO("TxDefaultProfile found.\n");
  1348. else
  1349. DEBUG_INFO("TxDefaultProfile updated.\n");
  1350. // Required item
  1351. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1352. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1353. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1354. if(isUnitA)
  1355. {
  1356. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1357. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1358. {
  1359. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1360. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1361. 3:
  1362. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1363. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1364. }
  1365. }
  1366. else
  1367. {
  1368. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1369. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1370. {
  1371. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1372. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1373. 3:
  1374. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1375. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1376. }
  1377. }
  1378. // Optional item
  1379. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1380. {
  1381. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1382. }
  1383. else
  1384. {
  1385. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1386. }
  1387. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1388. {
  1389. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1390. }
  1391. else
  1392. {
  1393. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1394. }
  1395. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1396. {
  1397. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1398. }
  1399. else
  1400. {
  1401. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1402. }
  1403. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1404. {
  1405. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1406. }
  1407. else
  1408. {
  1409. defaultTxProfile.TransactionId = -1;
  1410. }
  1411. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1412. {
  1413. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1414. }
  1415. else
  1416. {
  1417. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1418. }
  1419. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1420. {
  1421. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1422. }
  1423. else
  1424. {
  1425. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1426. }
  1427. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1428. {
  1429. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1430. }
  1431. else
  1432. {
  1433. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1434. }
  1435. }
  1436. }
  1437. }
  1438. json_object_put(obj);
  1439. }
  1440. fclose(fp);
  1441. /*
  1442. if(defaultTxProfile.ChargingProfileId != -1)
  1443. {
  1444. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1445. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1446. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1447. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1448. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1449. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1450. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1451. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1452. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1453. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1454. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1456. {
  1457. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1458. {
  1459. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1460. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1461. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1462. }
  1463. }
  1464. }
  1465. else
  1466. DEBUG_INFO("TxDefaultProfile not found.\n");
  1467. DEBUG_INFO("------------------------------------\n");*/
  1468. }
  1469. // Search max profile
  1470. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1471. if((access(profileFileName, F_OK))!=-1)
  1472. {
  1473. fp = fopen(profileFileName, "r");
  1474. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1475. {
  1476. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1478. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1479. }
  1480. maxProfile.ChargingProfileId = -1;
  1481. maxProfile.StackLevel = -1;
  1482. while(getline(&line, &len, fp) != -1)
  1483. {
  1484. json_object *obj = NULL;
  1485. obj = json_tokener_parse(line);
  1486. if(is_error(obj))
  1487. {
  1488. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1489. }
  1490. else
  1491. {
  1492. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1493. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1494. )
  1495. {
  1496. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1497. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1498. )
  1499. {
  1500. struct tm tmFrom, tmTo;
  1501. struct timeb tbFrom, tbTo;
  1502. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1503. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1504. {
  1505. tmFrom.tm_year -= 1900;
  1506. tmFrom.tm_mon -= 1;
  1507. tbFrom.time = mktime(&tmFrom);
  1508. tmTo.tm_year -= 1900;
  1509. tmTo.tm_mon -= 1;
  1510. tbTo.time = mktime(&tmTo);
  1511. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1512. {
  1513. if(maxProfile.ChargingProfileId == -1)
  1514. DEBUG_INFO("MaxProfile found.\n");
  1515. else
  1516. DEBUG_INFO("MaxProfile updated.\n");
  1517. // Required item
  1518. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1519. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1520. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1521. if(isUnitA)
  1522. {
  1523. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1524. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1525. {
  1526. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1527. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1528. 3:
  1529. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1530. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1531. }
  1532. }
  1533. else
  1534. {
  1535. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1536. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1537. {
  1538. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1539. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1540. 3:
  1541. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1542. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1543. }
  1544. }
  1545. // Optional item
  1546. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1547. {
  1548. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1549. }
  1550. else
  1551. {
  1552. sprintf((char*)maxProfile.ValidFrom, " ");
  1553. }
  1554. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1555. {
  1556. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1557. }
  1558. else
  1559. {
  1560. sprintf((char*)maxProfile.ValidTo, " ");
  1561. }
  1562. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1563. {
  1564. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1565. }
  1566. else
  1567. {
  1568. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1569. }
  1570. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1571. {
  1572. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1573. }
  1574. else
  1575. {
  1576. maxProfile.TransactionId = -1;
  1577. }
  1578. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1579. {
  1580. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1581. }
  1582. else
  1583. {
  1584. maxProfile.ChargingSchedule.Duration = 86400;
  1585. }
  1586. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1587. {
  1588. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1589. }
  1590. else
  1591. {
  1592. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1593. }
  1594. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1595. {
  1596. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1597. }
  1598. else
  1599. {
  1600. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1601. }
  1602. }
  1603. }
  1604. }
  1605. else
  1606. {
  1607. if(maxProfile.ChargingProfileId == -1)
  1608. DEBUG_INFO("MaxProfile found.\n");
  1609. else
  1610. DEBUG_INFO("MaxProfile updated.\n");
  1611. // Required item
  1612. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1613. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1614. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1615. if(isUnitA)
  1616. {
  1617. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1618. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1619. {
  1620. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1621. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1622. 3:
  1623. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1624. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1625. }
  1626. }
  1627. else
  1628. {
  1629. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1630. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1631. {
  1632. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1633. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1634. 3:
  1635. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1636. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1637. }
  1638. }
  1639. // Optional item
  1640. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1641. {
  1642. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1643. }
  1644. else
  1645. {
  1646. sprintf((char*)maxProfile.ValidFrom, " ");
  1647. }
  1648. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1649. {
  1650. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1651. }
  1652. else
  1653. {
  1654. sprintf((char*)maxProfile.ValidTo, " ");
  1655. }
  1656. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1657. {
  1658. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1659. }
  1660. else
  1661. {
  1662. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1663. }
  1664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1665. {
  1666. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1667. }
  1668. else
  1669. {
  1670. maxProfile.TransactionId = -1;
  1671. }
  1672. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1673. {
  1674. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1675. }
  1676. else
  1677. {
  1678. maxProfile.ChargingSchedule.Duration = 86400;
  1679. }
  1680. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1681. {
  1682. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1683. }
  1684. else
  1685. {
  1686. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1687. }
  1688. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1689. {
  1690. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1691. }
  1692. else
  1693. {
  1694. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1695. }
  1696. }
  1697. }
  1698. }
  1699. json_object_put(obj);
  1700. }
  1701. fclose(fp);
  1702. /*
  1703. if(maxProfile.ChargingProfileId !=-1)
  1704. {
  1705. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1706. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1707. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1708. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1709. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1710. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1711. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1712. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1713. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1714. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1715. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1716. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1717. {
  1718. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1719. {
  1720. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1721. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1722. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1723. }
  1724. }
  1725. }
  1726. else
  1727. DEBUG_INFO("MaxProfile not found.\n");
  1728. DEBUG_INFO("------------------------------------\n");*/
  1729. }
  1730. /*
  1731. * Align found profile start schedule & periods
  1732. */
  1733. //DEBUG_INFO("====================================\n");
  1734. /*
  1735. // For local test usage, force modify found profile start schedule info
  1736. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1737. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1738. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1739. */
  1740. if(txProfile.ChargingProfileId != -1)
  1741. {
  1742. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1743. {
  1744. if(txProfile.ChargingSchedule.Duration != -1)
  1745. {
  1746. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1747. 0:
  1748. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1749. }
  1750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1751. {
  1752. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1753. {
  1754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1755. 0:
  1756. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1757. if(idxPeriod > 0)
  1758. {
  1759. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1760. {
  1761. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1762. }
  1763. }
  1764. }
  1765. }
  1766. }
  1767. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1768. {
  1769. if(txProfile.ChargingSchedule.Duration != -1)
  1770. {
  1771. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1772. 0:
  1773. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1774. }
  1775. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1776. {
  1777. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1778. {
  1779. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1780. 0:
  1781. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1782. if(idxPeriod > 0)
  1783. {
  1784. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1785. {
  1786. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1787. }
  1788. }
  1789. }
  1790. }
  1791. }
  1792. else
  1793. {
  1794. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1795. {
  1796. if(txProfile.ChargingSchedule.Duration != -1)
  1797. {
  1798. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1799. 0:
  1800. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1801. }
  1802. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1803. {
  1804. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1805. {
  1806. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1807. 0:
  1808. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1809. if(idxPeriod > 0)
  1810. {
  1811. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1812. {
  1813. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1814. }
  1815. }
  1816. }
  1817. }
  1818. }
  1819. else
  1820. {
  1821. if(txProfile.ChargingSchedule.Duration != -1)
  1822. {
  1823. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1824. 0:
  1825. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1826. }
  1827. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1828. {
  1829. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1830. {
  1831. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1832. 0:
  1833. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1834. if(idxPeriod > 0)
  1835. {
  1836. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1837. {
  1838. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1839. }
  1840. }
  1841. }
  1842. }
  1843. }
  1844. }
  1845. /*
  1846. DEBUG_INFO("txProfile after align.\n");
  1847. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1848. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1849. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1850. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1851. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1852. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1853. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1854. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1855. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1856. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1857. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1858. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1859. {
  1860. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1861. {
  1862. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1863. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1864. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1865. }
  1866. }*/
  1867. }
  1868. if(defaultTxProfile.ChargingProfileId != -1)
  1869. {
  1870. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1871. {
  1872. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1873. {
  1874. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1875. 0:
  1876. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1877. }
  1878. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1879. {
  1880. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1881. {
  1882. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1883. 0:
  1884. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1885. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1886. {
  1887. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1888. }
  1889. if(idxPeriod > 0)
  1890. {
  1891. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1892. {
  1893. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1894. }
  1895. }
  1896. }
  1897. }
  1898. }
  1899. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1900. {
  1901. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1902. {
  1903. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1904. 0:
  1905. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1906. }
  1907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1908. {
  1909. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1910. {
  1911. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1912. 0:
  1913. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1914. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1915. {
  1916. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1917. }
  1918. if(idxPeriod > 0)
  1919. {
  1920. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1921. {
  1922. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1923. }
  1924. }
  1925. }
  1926. }
  1927. }
  1928. else
  1929. {
  1930. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1931. {
  1932. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1933. {
  1934. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1935. 0:
  1936. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1937. }
  1938. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1939. {
  1940. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1941. {
  1942. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1943. 0:
  1944. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1945. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1946. {
  1947. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1948. }
  1949. if(idxPeriod > 0)
  1950. {
  1951. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1952. {
  1953. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1954. }
  1955. }
  1956. }
  1957. }
  1958. }
  1959. else
  1960. {
  1961. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1962. {
  1963. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1964. 0:
  1965. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1966. }
  1967. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1968. {
  1969. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1970. {
  1971. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1972. 0:
  1973. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1974. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1975. {
  1976. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1977. }
  1978. if(idxPeriod > 0)
  1979. {
  1980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1981. {
  1982. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1983. }
  1984. }
  1985. }
  1986. }
  1987. }
  1988. }
  1989. /*
  1990. DEBUG_INFO("defaultTxProfile after align.\n");
  1991. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1992. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1993. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1994. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1995. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1996. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1997. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1998. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1999. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2000. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2001. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2002. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2003. {
  2004. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2005. {
  2006. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2007. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2008. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2009. }
  2010. }
  2011. DEBUG_INFO("------------------------------------\n");*/
  2012. }
  2013. if(maxProfile.ChargingProfileId != -1)
  2014. {
  2015. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2016. {
  2017. if(maxProfile.ChargingSchedule.Duration != -1)
  2018. {
  2019. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2020. 0:
  2021. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2022. }
  2023. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2024. {
  2025. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2026. {
  2027. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2028. 0:
  2029. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2030. if(idxPeriod > 0)
  2031. {
  2032. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2033. {
  2034. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2035. }
  2036. }
  2037. }
  2038. }
  2039. }
  2040. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2041. {
  2042. if(maxProfile.ChargingSchedule.Duration != -1)
  2043. {
  2044. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2045. 0:
  2046. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2047. }
  2048. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2049. {
  2050. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2051. {
  2052. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2053. 0:
  2054. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2055. if(idxPeriod > 0)
  2056. {
  2057. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2058. {
  2059. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. else
  2066. {
  2067. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2068. {
  2069. if(maxProfile.ChargingSchedule.Duration != -1)
  2070. {
  2071. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2072. 0:
  2073. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2074. }
  2075. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2076. {
  2077. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2078. {
  2079. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2080. 0:
  2081. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2082. if(idxPeriod > 0)
  2083. {
  2084. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2085. {
  2086. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2087. }
  2088. }
  2089. }
  2090. }
  2091. }
  2092. else
  2093. {
  2094. if(maxProfile.ChargingSchedule.Duration != -1)
  2095. {
  2096. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2097. 0:
  2098. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2099. }
  2100. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2101. {
  2102. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2103. {
  2104. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2105. 0:
  2106. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2107. if(idxPeriod > 0)
  2108. {
  2109. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2110. {
  2111. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2112. }
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. /*
  2119. DEBUG_INFO("MaxProfile after align.\n");
  2120. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2121. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2122. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2123. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2124. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2125. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2126. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2127. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2128. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2129. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2130. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2131. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2132. {
  2133. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2134. {
  2135. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2136. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2137. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2138. }
  2139. }
  2140. DEBUG_INFO("------------------------------------\n");*/
  2141. }
  2142. /*
  2143. * Merge to conposite schedule
  2144. */
  2145. //DEBUG_INFO("====================================\n");
  2146. // Find each profile period quantity
  2147. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2148. {
  2149. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2150. limitMax = idx+1;
  2151. }
  2152. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2153. {
  2154. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2155. limitDef = idx+1;
  2156. }
  2157. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2158. {
  2159. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2160. limitTx = idx+1;
  2161. }
  2162. // TxProfile found, composite schedule based on it
  2163. if(txProfile.ChargingProfileId != -1)
  2164. {
  2165. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2166. {
  2167. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2168. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2169. (txProfile.ChargingSchedule.Duration > 0))
  2170. {
  2171. if(maxProfile.ChargingProfileId != -1)
  2172. {
  2173. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2174. {
  2175. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2176. {
  2177. if((maxProfile.ChargingSchedule.Duration > 0))
  2178. {
  2179. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2180. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2181. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2182. }
  2183. else
  2184. {
  2185. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2186. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2187. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2188. }
  2189. }
  2190. if(idxMaxPeriod == (limitMax-1))
  2191. {
  2192. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2193. {
  2194. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2195. {
  2196. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2197. compositePeriodIdx++;
  2198. }
  2199. else
  2200. {
  2201. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. else
  2208. {
  2209. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2210. {
  2211. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2212. compositePeriodIdx++;
  2213. }
  2214. else
  2215. {
  2216. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2217. }
  2218. }
  2219. }
  2220. if(idxTxPeriod == (limitTx-1))
  2221. {
  2222. if(defaultTxProfile.ChargingProfileId != -1)
  2223. {
  2224. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2225. {
  2226. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2227. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2228. (defaultTxProfile.ChargingSchedule.Duration>0))
  2229. {
  2230. if(maxProfile.ChargingProfileId != -1)
  2231. {
  2232. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2233. {
  2234. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2235. {
  2236. if((maxProfile.ChargingSchedule.Duration > 0))
  2237. {
  2238. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2239. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2240. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2241. }
  2242. else
  2243. {
  2244. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2245. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2246. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2247. }
  2248. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2249. {
  2250. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2251. {
  2252. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2253. compositePeriodIdx++;
  2254. }
  2255. else
  2256. {
  2257. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2258. }
  2259. }
  2260. // Delete duplicate period
  2261. if(compositePeriodIdx > 1)
  2262. {
  2263. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2264. {
  2265. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2266. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2267. compositePeriodIdx -= 1;
  2268. }
  2269. }
  2270. }
  2271. else
  2272. break;
  2273. }
  2274. }
  2275. else
  2276. {
  2277. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2278. {
  2279. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2280. compositePeriodIdx++;
  2281. }
  2282. else
  2283. {
  2284. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2285. }
  2286. }
  2287. }
  2288. }
  2289. }
  2290. }
  2291. }
  2292. }
  2293. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2294. else if(defaultTxProfile.ChargingProfileId != -1)
  2295. {
  2296. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2297. {
  2298. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2299. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2300. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2301. {
  2302. if(maxProfile.ChargingProfileId != -1)
  2303. {
  2304. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2305. {
  2306. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2307. {
  2308. if((maxProfile.ChargingSchedule.Duration > 0))
  2309. {
  2310. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2311. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2312. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2313. }
  2314. else
  2315. {
  2316. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2317. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2318. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2319. }
  2320. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2321. {
  2322. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2323. {
  2324. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2325. compositePeriodIdx++;
  2326. }
  2327. else
  2328. {
  2329. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2330. }
  2331. }
  2332. // Delete duplicate period
  2333. if(compositePeriodIdx > 1)
  2334. {
  2335. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2336. {
  2337. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2338. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2339. compositePeriodIdx -= 1;
  2340. }
  2341. }
  2342. }
  2343. else
  2344. break;
  2345. }
  2346. }
  2347. else
  2348. {
  2349. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2350. {
  2351. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2352. compositePeriodIdx++;
  2353. }
  2354. else
  2355. {
  2356. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2357. }
  2358. }
  2359. }
  2360. }
  2361. }
  2362. // Fill other period by MaxProfile
  2363. if(maxProfile.ChargingProfileId != -1)
  2364. {
  2365. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2366. {
  2367. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2368. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2369. (maxProfile.ChargingSchedule.Duration > 0))
  2370. {
  2371. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2372. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2373. {
  2374. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2375. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2376. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2377. }
  2378. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2379. {
  2380. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2381. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2382. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2383. }
  2384. if(tmpPeriod.Limit != -1)
  2385. {
  2386. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2387. {
  2388. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2389. {
  2390. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2391. compositePeriodIdx++;
  2392. }
  2393. else
  2394. {
  2395. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2396. }
  2397. }
  2398. // Delete duplicate period
  2399. if(compositePeriodIdx > 1)
  2400. {
  2401. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2402. {
  2403. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2404. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2405. compositePeriodIdx -= 1;
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2413. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2414. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2415. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2416. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2417. {
  2418. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2419. {
  2420. compositeProfile->ChargingProfileId = 1;
  2421. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2422. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2423. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2424. }
  2425. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2426. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2427. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2428. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2429. }
  2430. if(line)
  2431. free(line);
  2432. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2433. }
  2434. //==========================================
  2435. // Init all share memory
  2436. //==========================================
  2437. int InitShareMemory()
  2438. {
  2439. int result = PASS;
  2440. int MeterSMId;
  2441. //creat ShmSysConfigAndInfo
  2442. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2443. {
  2444. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2445. result = FAIL;
  2446. }
  2447. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2448. {
  2449. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2450. result = FAIL;
  2451. }
  2452. else
  2453. {}
  2454. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2455. {
  2456. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2457. result = FAIL;
  2458. }
  2459. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2460. {
  2461. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2462. result = FAIL;
  2463. }
  2464. else
  2465. {}
  2466. //creat ShmPsuData
  2467. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2468. {
  2469. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2470. result = FAIL;
  2471. }
  2472. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2473. {
  2474. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2475. result = FAIL;
  2476. }
  2477. else
  2478. {}
  2479. //link ShmOCPP16Data
  2480. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2481. {
  2482. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2483. result = FAIL;
  2484. }
  2485. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2486. {
  2487. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2488. result = FAIL;
  2489. }
  2490. else
  2491. {}
  2492. //creat ShmOCPP16DataPH
  2493. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  2494. {
  2495. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  2496. result = FAIL;
  2497. }
  2498. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2499. {
  2500. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  2501. result = FAIL;
  2502. }
  2503. else
  2504. {}
  2505. /****************************** For Initial Settings************************************************/
  2506. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  2507. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  2508. // allocate Configuration memory address
  2509. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  2510. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2511. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2512. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2513. //offline MeterValue Interval
  2514. TempMeterValueInterval = 0;
  2515. return result;
  2516. }
  2517. int ProcessShareMemory()
  2518. {
  2519. if(InitShareMemory() == FAIL)
  2520. {
  2521. DEBUG_ERROR("InitShareMemory NG\n");
  2522. if(ShmStatusCodeData!=NULL)
  2523. {
  2524. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2525. }
  2526. sleep(5);
  2527. return FAIL;
  2528. }
  2529. return PASS;
  2530. }
  2531. void CheckSystemValue(void)
  2532. {
  2533. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2534. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2535. char filenmae[100]={0};
  2536. char str[100]={0};
  2537. int tempIndex = 0;
  2538. //===============================
  2539. // send Heartbeat
  2540. //===============================
  2541. //HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  2542. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2543. {
  2544. clientTime.Heartbeat=time((time_t*)NULL);
  2545. if(server_sign == TRUE)
  2546. {
  2547. HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  2548. }
  2549. else
  2550. {
  2551. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2552. }
  2553. }
  2554. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2555. {
  2556. //parameter for test
  2557. sendHeartbeatRequest(0);
  2558. //==============================================
  2559. // Reset Waiting Time
  2560. //==============================================
  2561. HeartBeatWithNOResponse += 2;
  2562. }
  2563. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2564. {
  2565. //==========================================
  2566. // csu trigger DataTransferReq
  2567. //==========================================
  2568. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  2569. {
  2570. sendDataTransferRequest(gun_index);
  2571. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  2572. }
  2573. //===============================
  2574. // CSU Trigger Authorize Request
  2575. //===============================
  2576. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2577. {
  2578. sendAuthorizeRequest(0);
  2579. authorizeRetryTimes = authorizeRetryTimes + 1;
  2580. if(authorizeRetryTimes < 3)
  2581. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  2582. }
  2583. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2584. {
  2585. authorizeRetryTimes = 0;
  2586. SetOcppConnStatus(FALSE);
  2587. server_sign = FALSE;
  2588. }
  2589. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0)&& (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1))
  2590. {
  2591. sendAuthorizeRequest(0);
  2592. }
  2593. //==============================================
  2594. // CSU Trigger Smart Charging Profilw
  2595. //==============================================
  2596. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2597. {
  2598. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  2599. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2600. }
  2601. //==============================================
  2602. // Charger start transaction
  2603. //==============================================
  2604. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2605. {
  2606. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2607. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  2608. sendStartTransactionRequest(gun_index);
  2609. clientTime.StartTransaction = time((time_t*)NULL);
  2610. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2611. storeTempStopTransaction(gun_index);
  2612. }
  2613. //==============================================
  2614. // Charger stop transaction
  2615. //==============================================
  2616. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2617. {
  2618. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2619. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  2620. sendStopTransactionRequest(gun_index);
  2621. clientTime.StopTransaction = time((time_t*)NULL);
  2622. }
  2623. //==============================================
  2624. // Charger status report
  2625. //==============================================
  2626. //--- Check Mode Change ---//
  2627. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2628. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2629. {
  2630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2631. {
  2632. tempIndex = ((gun_index==2) ? 1: 0);
  2633. }
  2634. else
  2635. {
  2636. tempIndex = gun_index;
  2637. }
  2638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2639. {
  2640. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2641. {
  2642. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2643. {
  2644. // Sent unplug message for California pricing logic
  2645. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2646. {
  2647. uint8_t ts[20];
  2648. getNowDatetime(ts);
  2649. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2650. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2651. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2652. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2653. }
  2654. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2655. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2656. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2657. statusModeChage[gun_index] = TRUE;
  2658. }
  2659. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2660. {
  2661. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2662. if((access(filenmae,F_OK))!=-1)
  2663. {
  2664. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2665. sprintf(str,"rm -f %s",filenmae);
  2666. system(str);
  2667. }
  2668. }
  2669. #if 1 // for TempStopTransaction
  2670. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2671. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2672. {
  2673. checkTempStopTransaction(gun_index);
  2674. }
  2675. #endif
  2676. }
  2677. }
  2678. }
  2679. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2680. {
  2681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2682. {
  2683. tempIndex = ((gun_index==2) ? 1: 0);
  2684. }
  2685. else
  2686. {
  2687. tempIndex = gun_index;
  2688. }
  2689. for (int index = 0; index < CCS_QUANTITY; index++)
  2690. {
  2691. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2692. {
  2693. 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]*/ )
  2694. {
  2695. // Sent unplug message for California pricing logic
  2696. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2697. {
  2698. uint8_t ts[20];
  2699. getNowDatetime(ts);
  2700. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2701. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2702. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2703. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2704. }
  2705. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2706. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2707. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2708. statusModeChage[gun_index] = TRUE;
  2709. }
  2710. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2711. {
  2712. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2713. if((access(filenmae,F_OK))!=-1)
  2714. {
  2715. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2716. sprintf(str,"rm -f %s",filenmae);
  2717. system(str);
  2718. }
  2719. }
  2720. #if 1 // for TempStopTransaction
  2721. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2722. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2723. {
  2724. checkTempStopTransaction(gun_index);
  2725. }
  2726. #endif
  2727. }
  2728. }
  2729. }
  2730. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2731. {
  2732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2733. {
  2734. tempIndex = ((gun_index==2) ? 1: 0);
  2735. }
  2736. else
  2737. {
  2738. tempIndex = gun_index;
  2739. }
  2740. for (int index = 0; index < GB_QUANTITY; index++)
  2741. {
  2742. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2743. {
  2744. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2745. {
  2746. // Sent unplug message for California pricing logic
  2747. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2748. {
  2749. uint8_t ts[20];
  2750. getNowDatetime(ts);
  2751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2754. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2755. }
  2756. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2757. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2758. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2759. statusModeChage[gun_index] = TRUE;
  2760. }
  2761. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2762. {
  2763. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2764. if((access(filenmae,F_OK))!=-1)
  2765. {
  2766. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2767. sprintf(str,"rm -f %s",filenmae);
  2768. system(str);
  2769. }
  2770. }
  2771. #if 1 // for TempStopTransaction
  2772. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2773. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2774. {
  2775. checkTempStopTransaction(gun_index);
  2776. }
  2777. #endif
  2778. }
  2779. }
  2780. }
  2781. else if(gunType[gun_index] == GUN_TYPE_DO)
  2782. {
  2783. tempIndex = gun_index;
  2784. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2785. {
  2786. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2787. {
  2788. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2789. {
  2790. // Sent unplug message for California pricing logic
  2791. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2792. {
  2793. uint8_t ts[20];
  2794. getNowDatetime(ts);
  2795. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2796. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2797. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2798. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2799. }
  2800. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2801. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2802. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2803. statusModeChage[gun_index] = TRUE;
  2804. }
  2805. 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
  2806. {
  2807. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2808. if((access(filenmae,F_OK))!=-1)
  2809. {
  2810. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2811. sprintf(str,"rm -f %s",filenmae);
  2812. system(str);
  2813. }
  2814. }
  2815. #if 1 // for TempStopTransaction
  2816. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  2817. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2818. {
  2819. checkTempStopTransaction(gun_index);
  2820. }
  2821. #endif
  2822. }
  2823. }
  2824. }
  2825. else
  2826. {
  2827. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2828. {
  2829. tempIndex = 2;
  2830. }
  2831. else
  2832. {
  2833. tempIndex = gun_index;
  2834. }
  2835. for (int index = 0; index < AC_QUANTITY; index++)
  2836. {
  2837. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2838. {
  2839. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2840. {
  2841. // Sent unplug message for California pricing logic
  2842. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2843. {
  2844. uint8_t ts[20];
  2845. getNowDatetime(ts);
  2846. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2847. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2848. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2849. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2850. }
  2851. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2852. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2853. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2854. statusModeChage[gun_index] = TRUE;
  2855. }
  2856. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2857. {
  2858. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2859. if((access(filenmae,F_OK))!=-1)
  2860. {
  2861. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2862. sprintf(str,"rm -f %s",filenmae);
  2863. system(str);
  2864. }
  2865. }
  2866. #if 1 // for TempStopTransaction
  2867. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2868. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2869. {
  2870. checkTempStopTransaction(gun_index);
  2871. }
  2872. #endif
  2873. }
  2874. }// END
  2875. }
  2876. if(isWebsocketSendable && (server_sign == TRUE) &&
  2877. (
  2878. (statusModeChage[gun_index] == TRUE) ||
  2879. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2880. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5))
  2881. )
  2882. )
  2883. {
  2884. if(SystemInitial > 0)
  2885. SystemInitial -= 1;
  2886. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  2887. sendStatusNotificationRequest(gun_index);
  2888. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2889. statusModeChage[gun_index] = FALSE;
  2890. }
  2891. //==============================================
  2892. // Meter report
  2893. //==============================================
  2894. // Trigger MeterValue
  2895. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2896. {
  2897. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2898. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2899. }
  2900. // ClockAlign MeterValue
  2901. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2902. {
  2903. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2904. {
  2905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2906. {
  2907. tempIndex = ((gun_index==2) ? 1: 0);
  2908. }
  2909. else
  2910. {
  2911. tempIndex = gun_index;
  2912. }
  2913. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2914. {
  2915. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2916. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2917. {
  2918. reqClockAlignMeter[gun_index] = 1;
  2919. }
  2920. }// End for CHAdeMO
  2921. }
  2922. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2923. {
  2924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2925. {
  2926. tempIndex = ((gun_index==2) ? 1: 0);
  2927. }
  2928. else
  2929. {
  2930. tempIndex = gun_index;
  2931. }
  2932. for (int index = 0; index < CCS_QUANTITY; index++)
  2933. {
  2934. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2935. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2936. {
  2937. reqClockAlignMeter[gun_index] = 1;
  2938. }
  2939. } // End for CCS
  2940. }
  2941. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2942. {
  2943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2944. {
  2945. tempIndex = ((gun_index==2) ? 1: 0);
  2946. }
  2947. else
  2948. {
  2949. tempIndex = gun_index;
  2950. }
  2951. for (int index = 0; index < GB_QUANTITY; index++)
  2952. {
  2953. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2954. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2955. {
  2956. reqClockAlignMeter[gun_index] = 1;
  2957. }
  2958. }// End for GB
  2959. }
  2960. else if(gunType[gun_index] == GUN_TYPE_DO)
  2961. {
  2962. tempIndex = gun_index;
  2963. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2964. {
  2965. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2966. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2967. {
  2968. reqClockAlignMeter[gun_index] = 1;
  2969. }
  2970. }
  2971. }
  2972. else
  2973. {
  2974. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2975. {
  2976. tempIndex = 2;
  2977. }
  2978. else
  2979. {
  2980. tempIndex = gun_index;
  2981. }
  2982. for (int index = 0; index < AC_QUANTITY; index++)
  2983. {
  2984. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2985. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2986. {
  2987. reqClockAlignMeter[gun_index] = 1;
  2988. }
  2989. }//End for AC
  2990. }
  2991. if(reqClockAlignMeter[gun_index] == 1)
  2992. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2993. }
  2994. // Sample period MeterValue
  2995. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  2996. {
  2997. //check Transaction active
  2998. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2999. {
  3000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3001. {
  3002. tempIndex = ((gun_index==2) ? 1: 0);
  3003. }
  3004. else
  3005. {
  3006. tempIndex = gun_index;
  3007. }
  3008. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3009. {
  3010. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3011. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3012. {
  3013. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3014. {
  3015. reqSampleMeter[gun_index] = 1;
  3016. }
  3017. }
  3018. }// End for CHAdeMO
  3019. }
  3020. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3021. {
  3022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3023. {
  3024. tempIndex = ((gun_index==2) ? 1: 0);
  3025. }
  3026. else
  3027. {
  3028. tempIndex = gun_index;
  3029. }
  3030. for (int index = 0; index < CCS_QUANTITY; index++)
  3031. {
  3032. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3033. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3034. {
  3035. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3036. {
  3037. reqSampleMeter[gun_index] = 1;
  3038. }
  3039. }
  3040. } // End for CCS
  3041. }
  3042. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3043. {
  3044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3045. {
  3046. tempIndex = ((gun_index==2) ? 1: 0);
  3047. }
  3048. else
  3049. {
  3050. tempIndex = gun_index;
  3051. }
  3052. for (int index = 0; index < GB_QUANTITY; index++)
  3053. {
  3054. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3055. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3056. {
  3057. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3058. {
  3059. reqSampleMeter[gun_index] = 1;
  3060. }
  3061. }
  3062. }// End for GB
  3063. }
  3064. else if(gunType[gun_index] == GUN_TYPE_DO)
  3065. {
  3066. tempIndex = gun_index;
  3067. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3068. {
  3069. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3070. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3071. {
  3072. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3073. {
  3074. reqSampleMeter[gun_index] = 1;
  3075. }
  3076. }
  3077. }
  3078. }
  3079. else
  3080. {
  3081. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3082. {
  3083. tempIndex = 2;
  3084. }
  3085. else
  3086. {
  3087. tempIndex = gun_index;
  3088. }
  3089. for (int index = 0; index < AC_QUANTITY; index++)
  3090. {
  3091. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3092. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3093. {
  3094. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3095. {
  3096. reqSampleMeter[gun_index] = 1;
  3097. }
  3098. }
  3099. }//End for AC
  3100. }
  3101. if(reqSampleMeter[gun_index] == 1)
  3102. {
  3103. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3104. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3105. storeTempStopTransaction(gun_index);
  3106. }
  3107. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3108. }
  3109. //==============================================
  3110. // Check Connector reserved
  3111. //==============================================
  3112. //===============================
  3113. // Check if Reserve is expired
  3114. //===============================
  3115. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3116. {
  3117. double diff_t;
  3118. struct tm tp;
  3119. // current time
  3120. time_t t = time(NULL);
  3121. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3122. tp.tm_isdst = -1;
  3123. time_t utc = mktime(&tp);
  3124. diff_t = difftime(utc, t);
  3125. if(diff_t <= 0)
  3126. {
  3127. DEBUG_INFO("reserve expired.\n");
  3128. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  3129. }
  3130. }//END OF Check if Reserve is expired
  3131. //==========================================
  3132. // csu trigger FirmwareStatusNotificationReq
  3133. //==========================================
  3134. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3135. {
  3136. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  3137. }
  3138. //==========================================
  3139. // csu trigger DiagnosticsStatusNotificationReq
  3140. //==========================================
  3141. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3142. {
  3143. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  3144. }
  3145. //==========================================
  3146. // csu trigger CancelReservationConf
  3147. //==========================================
  3148. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3149. {
  3150. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  3151. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3152. }
  3153. //==========================================
  3154. // csu trigger ChangeAvailabilityConf
  3155. //==========================================
  3156. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3157. {
  3158. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  3159. }
  3160. //==========================================
  3161. // csu trigger UnlockConnectorConf
  3162. //==========================================
  3163. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3164. {
  3165. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  3166. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3167. }
  3168. //==========================================
  3169. // csu trigger ReserveNowConf
  3170. //==========================================
  3171. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3172. {
  3173. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  3174. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3175. }
  3176. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  3177. {
  3178. sendSignCertificateRequest();
  3179. }
  3180. }
  3181. }
  3182. //==========================================
  3183. // send request routine
  3184. //==========================================
  3185. int sendAuthorizeRequest(int gun_index)
  3186. {
  3187. mtrace();
  3188. int result = FAIL;
  3189. char message[100]={0};
  3190. char guid[37];
  3191. char tempdata[65]={0};
  3192. DEBUG_INFO("sendAuthorizeRequest...\n");
  3193. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3194. //Local Authorize
  3195. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  3196. {
  3197. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3198. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3199. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3200. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3201. result = PASS;
  3202. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3203. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3204. authorizeRetryTimes = 0;
  3205. return result;
  3206. }
  3207. else if(((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0))||
  3208. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3209. {
  3210. // Query from cache
  3211. DEBUG_INFO("Authorize from cache.\n");
  3212. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3213. // Query from list
  3214. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3215. {
  3216. DEBUG_INFO("Authorize from list.\n");
  3217. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3218. }
  3219. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3220. {
  3221. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3222. {
  3223. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3224. }
  3225. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3226. {
  3227. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3228. }
  3229. if(!GetOcppConnStatus())
  3230. {
  3231. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3232. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3233. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3234. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3235. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3236. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3237. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3238. authorizeRetryTimes = 0;
  3239. return result;
  3240. }
  3241. }
  3242. else
  3243. {
  3244. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3245. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3246. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3247. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3248. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  3249. else
  3250. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3251. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3252. result = PASS;
  3253. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3254. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3255. authorizeRetryTimes = 0;
  3256. return result;
  3257. }
  3258. }
  3259. //initialize struct Authorize
  3260. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  3261. //get data from shared memory
  3262. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3263. random_uuid(guid);
  3264. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  3265. LWS_Send(message);
  3266. sprintf(tempdata, "Authorize,%d", gun_index);
  3267. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3268. {
  3269. result = PASS;
  3270. DEBUG_INFO("Authorize mapItem pass\n");
  3271. }
  3272. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3273. return result;
  3274. }
  3275. int sendBootNotificationRequest(void)
  3276. {
  3277. mtrace();
  3278. int result = FAIL;
  3279. char message[500]={0}, payload[700]={0};
  3280. char guid[37]={0};
  3281. char tempdata[65]={0};
  3282. // Fill BootNotification fields
  3283. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  3284. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3285. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3286. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3287. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3288. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3289. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3290. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3291. ShmOCPP16DataPH->ChargeBoxId
  3292. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3293. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3294. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3295. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  3296. ,ShmOCPP16DataPH->BootNotification.CpIccid
  3297. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  3298. random_uuid(guid);
  3299. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3300. LWS_Send(message);
  3301. sprintf(tempdata, "BootNotification,0");
  3302. 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*/)
  3303. {
  3304. result = PASS;
  3305. }
  3306. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3307. strcpy(queuedata,message);
  3308. return result;
  3309. }
  3310. int sendDataTransferRequest(int gun_index)
  3311. {
  3312. mtrace();
  3313. char message[1000]={0};
  3314. char guid[37]={0};
  3315. char tempdata[65]={0};
  3316. int result = FAIL;
  3317. random_uuid(guid);
  3318. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3319. MESSAGE_TYPE_CALL,
  3320. guid,
  3321. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  3322. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  3323. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  3324. LWS_Send(message);
  3325. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3326. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3327. {
  3328. result = PASS;
  3329. DEBUG_INFO("DataTransfer mapItem pass\n");
  3330. }
  3331. return result;
  3332. }
  3333. int sendDiagnosticsStatusNotificationRequest(char *status)
  3334. {
  3335. mtrace();
  3336. int result = FAIL;
  3337. char message[110]={0};
  3338. char guid[37]={0};
  3339. char tempdata[65]={0};
  3340. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3341. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3342. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3343. random_uuid(guid);
  3344. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3345. LWS_SendNow(message);
  3346. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3347. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3348. {
  3349. result = PASS;
  3350. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3351. }
  3352. //#ifdef SystemLogMessage
  3353. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3354. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3355. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3356. //#endif
  3357. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3358. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3359. //record status
  3360. if(strcmp(status,"Idle")==0)
  3361. {
  3362. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3363. }
  3364. else if(strcmp(status,"Uploaded")==0)
  3365. {
  3366. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3367. }
  3368. else if(strcmp(status,"UploadFailed")==0)
  3369. {
  3370. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3371. }
  3372. else if(strcmp(status,"Uploading")==0)
  3373. {
  3374. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3375. }
  3376. return result;
  3377. }
  3378. int sendFirmwareStatusNotificationRequest(char *status)
  3379. {
  3380. mtrace();
  3381. int result = FAIL;
  3382. char message[110]={0};
  3383. char guid[37]={0};
  3384. char tempdata[65]={0};
  3385. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3386. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3387. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3388. random_uuid(guid);
  3389. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3390. LWS_SendNow(message);
  3391. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3392. 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*/)
  3393. {
  3394. result = PASS;
  3395. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3396. }
  3397. //#ifdef SystemLogMessage
  3398. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3399. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3400. //#endif
  3401. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3402. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3403. //record status
  3404. if(strcmp(status,"Downloaded")==0)
  3405. {
  3406. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3407. }
  3408. else if(strcmp(status,"DownloadFailed")==0)
  3409. {
  3410. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3411. }
  3412. else if(strcmp(status,"Downloading")==0)
  3413. {
  3414. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3415. }
  3416. else if(strcmp(status,"Idle")==0)
  3417. {
  3418. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3419. }
  3420. else if(strcmp(status,"InstallationFailed")==0)
  3421. {
  3422. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3423. }
  3424. else if(strcmp(status,"Installing")==0)
  3425. {
  3426. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3427. }
  3428. else if(strcmp(status,"Installed")==0)
  3429. {
  3430. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3431. }
  3432. return result;
  3433. }
  3434. int sendHeartbeatRequest(int gun_index)
  3435. {
  3436. mtrace();
  3437. int result = FAIL;
  3438. char message[80]={0};
  3439. char guid[37]={0};
  3440. char tempdata[65]={0};
  3441. random_uuid(guid);
  3442. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3443. , MESSAGE_TYPE_CALL
  3444. , guid );
  3445. LWS_Send(message);
  3446. sprintf(tempdata, "Heartbeat,%d", 0);
  3447. 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*/)
  3448. {
  3449. result = PASS;
  3450. }
  3451. return result;
  3452. }
  3453. int sendStartTransactionRequest(int gun_index)
  3454. {
  3455. mtrace();
  3456. int result = FAIL;
  3457. char message[250]={0};
  3458. char guid[37]={0};
  3459. struct timeval tmnow;
  3460. struct tm *tm;
  3461. char buf[28];//, usec_buf[6];
  3462. char tempdata[65]={0};
  3463. int tempIndex = 0;
  3464. DEBUG_INFO("sendStartTransactionRequest...\n");
  3465. gettimeofday(&tmnow, NULL);
  3466. time_t t;
  3467. t = time(NULL);
  3468. /*UTC time and date*/
  3469. tm = gmtime(&t);
  3470. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3471. #if 0 // remove temporally
  3472. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3473. strcat(buf,".");
  3474. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3475. strcat(buf,usec_buf);
  3476. #endif
  3477. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3478. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  3479. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3480. // clear StartTransaction Response
  3481. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3482. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3483. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3484. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  3485. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3486. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3487. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3488. {
  3489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3490. {
  3491. tempIndex = ((gun_index==2) ? 1: 0);
  3492. }
  3493. else
  3494. {
  3495. tempIndex = gun_index;
  3496. }
  3497. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3498. {
  3499. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3500. {
  3501. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3502. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3503. }
  3504. }
  3505. }
  3506. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3507. {
  3508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3509. {
  3510. tempIndex = ((gun_index==2) ? 1: 0);
  3511. }
  3512. else
  3513. {
  3514. tempIndex = gun_index;
  3515. }
  3516. for (int index = 0; index < CCS_QUANTITY; index++)
  3517. {
  3518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3519. {
  3520. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3521. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3522. }
  3523. }
  3524. }
  3525. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3526. {
  3527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3528. {
  3529. tempIndex = ((gun_index==2) ? 1: 0);
  3530. }
  3531. else
  3532. {
  3533. tempIndex = gun_index;
  3534. }
  3535. for (int index = 0; index < GB_QUANTITY; index++)
  3536. {
  3537. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3538. {
  3539. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3540. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3541. }
  3542. }
  3543. }
  3544. else if(gunType[gun_index] == GUN_TYPE_DO)
  3545. {
  3546. tempIndex = gun_index;
  3547. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3548. {
  3549. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3550. {
  3551. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3552. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3553. }
  3554. }
  3555. }
  3556. else
  3557. {
  3558. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3559. {
  3560. tempIndex = 2;
  3561. }
  3562. else
  3563. {
  3564. tempIndex = gun_index;
  3565. }
  3566. for (int index = 0; index < AC_QUANTITY; index++)
  3567. {
  3568. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3569. {
  3570. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3571. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3572. }
  3573. }
  3574. }
  3575. random_uuid(guid);
  3576. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3577. {
  3578. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3579. , gun_index +1
  3580. , MESSAGE_TYPE_CALL
  3581. , guid
  3582. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  3583. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  3584. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  3585. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  3586. }
  3587. else
  3588. {
  3589. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3590. , gun_index +1
  3591. , MESSAGE_TYPE_CALL
  3592. , guid
  3593. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  3594. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  3595. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  3596. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  3597. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  3598. }
  3599. #if 1
  3600. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3601. 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*/)
  3602. {
  3603. result = PASS;
  3604. }
  3605. #endif
  3606. strcpy(queuedata, message);
  3607. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3608. OCPP_insert_transaction_msg(YES, queuedata);
  3609. return result;
  3610. }
  3611. int sendStatusNotificationRequest(int gun_index)
  3612. {
  3613. mtrace();
  3614. int result = FAIL;
  3615. char message[600]={0};
  3616. char guid[37];
  3617. int currentStatus = 0;
  3618. struct timeval tmnow;
  3619. struct tm *tm;
  3620. char buf[28];//, usec_buf[6];
  3621. char tempdata[65]={0};
  3622. int tempIndex = 0;
  3623. uint8_t isStateChanged = TRUE;
  3624. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3625. gettimeofday(&tmnow, NULL);
  3626. time_t t;
  3627. t = time(NULL);
  3628. /*UTC time and date*/
  3629. tm = gmtime(&t);
  3630. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3631. #if 0 // remove temporally
  3632. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3633. strcat(buf,".");
  3634. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3635. strcat(buf,usec_buf);
  3636. #endif
  3637. printf("%s",buf);
  3638. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3639. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3640. // it's option
  3641. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  3642. /*
  3643. enum _SYSTEM_STATUS
  3644. {
  3645. S_BOOTING = 0,
  3646. S_IDLE, = 1
  3647. S_AUTHORIZING, =2
  3648. S_REASSIGN_CHECK, =3
  3649. S_REASSIGN, =4
  3650. S_PRECHARGE, =5
  3651. S_PREPARING_FOR_EV, =6
  3652. S_PREPARING_FOR_EVSE, =7
  3653. S_CHARGING, =8
  3654. S_TERMINATING, =9
  3655. S_COMPLETE, =10
  3656. S_ALARM, =11
  3657. S_FAULT =12
  3658. }
  3659. */
  3660. //check Transaction active
  3661. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3662. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3663. {
  3664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3665. {
  3666. tempIndex = ((gun_index==2) ? 1: 0);
  3667. }
  3668. else
  3669. {
  3670. tempIndex = gun_index;
  3671. }
  3672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3673. {
  3674. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3675. {
  3676. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3677. {
  3678. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3679. {
  3680. currentStatus = Preparing; //OCPP Status: Preparing
  3681. }
  3682. else
  3683. {
  3684. currentStatus = Available; //OCPP Status: Available
  3685. }
  3686. }
  3687. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3688. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3689. ) //S_PRECHARGE
  3690. {
  3691. currentStatus = Preparing; //OCPP Status: Preparing
  3692. }
  3693. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3694. {
  3695. currentStatus = Charging; //OCPP Status: Charging
  3696. }
  3697. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3698. {
  3699. currentStatus = Finishing; //OCPP Status: Finishing
  3700. }
  3701. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3702. {
  3703. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3704. }
  3705. 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
  3706. {
  3707. currentStatus = Unavailable; //OCPP Status: Unavailable
  3708. }
  3709. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3710. {
  3711. currentStatus = Faulted; //OCPP Status: Faulted
  3712. }
  3713. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3714. {
  3715. currentStatus = Reserved; //OCPP Status: Reserved
  3716. }
  3717. } //end of the same index
  3718. }//end of for CHAdeMO_QUANTITY
  3719. }
  3720. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3721. {
  3722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3723. {
  3724. tempIndex = ((gun_index==2) ? 1: 0);
  3725. }
  3726. else
  3727. {
  3728. tempIndex = gun_index;
  3729. }
  3730. for (int index = 0; index < CCS_QUANTITY; index++)
  3731. {
  3732. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3733. {
  3734. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3735. {
  3736. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3737. {
  3738. currentStatus = Preparing; //OCPP Status: Preparing
  3739. }
  3740. else
  3741. {
  3742. currentStatus = Available; //OCPP Status: Available
  3743. }
  3744. }
  3745. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3746. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3747. ) //S_PRECHARGE
  3748. {
  3749. currentStatus = Preparing; //OCPP Status: Preparing
  3750. }
  3751. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3752. {
  3753. currentStatus = Charging; //OCPP Status: Charging
  3754. }
  3755. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3756. {
  3757. currentStatus = Finishing; //OCPP Status: Finishing
  3758. }
  3759. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3760. {
  3761. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3762. }
  3763. 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
  3764. {
  3765. currentStatus = Unavailable; //OCPP Status : Unavailable
  3766. }
  3767. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3768. {
  3769. currentStatus = Faulted; //OCPP Status: Faulted
  3770. }
  3771. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3772. {
  3773. currentStatus = Reserved; //OCPP Status: Reserved
  3774. }
  3775. } //end of the same index
  3776. } // end of for CCS_QUANTITY
  3777. }
  3778. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3779. {
  3780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3781. {
  3782. tempIndex = ((gun_index==2) ? 1: 0);
  3783. }
  3784. else
  3785. {
  3786. tempIndex = gun_index;
  3787. }
  3788. for (int index = 0; index < GB_QUANTITY; index++)
  3789. {
  3790. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3791. {
  3792. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3793. {
  3794. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3795. {
  3796. currentStatus = Preparing; //OCPP Status: Preparing
  3797. }
  3798. else
  3799. {
  3800. currentStatus = Available; //OCPP Status: Available
  3801. }
  3802. }
  3803. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3804. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3805. ) //S_PRECHARGE
  3806. {
  3807. currentStatus = Preparing; //OCPP Status: Preparing
  3808. }
  3809. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3810. {
  3811. currentStatus = Charging; //OCPP Status: Charging
  3812. }
  3813. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3814. {
  3815. currentStatus = Finishing; //OCPP Status: Finishing
  3816. }
  3817. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3818. {
  3819. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3820. }
  3821. 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
  3822. {
  3823. currentStatus = Unavailable; //OCPP Status: Unavailable
  3824. }
  3825. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3826. {
  3827. currentStatus = Faulted; //OCPP Status: Faulted
  3828. }
  3829. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3830. {
  3831. currentStatus = Reserved; //OCPP Status: Reserved
  3832. }
  3833. } //end of the same index
  3834. } // end of for GB_QUANTITY
  3835. }
  3836. else if(gunType[gun_index] == GUN_TYPE_DO)
  3837. {
  3838. tempIndex = gun_index;
  3839. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3840. {
  3841. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3842. {
  3843. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3844. {
  3845. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3846. {
  3847. currentStatus = Preparing; //OCPP Status: Preparing
  3848. }
  3849. else
  3850. {
  3851. currentStatus = Available; //OCPP Status: Available
  3852. }
  3853. }
  3854. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3855. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3856. ) //S_PRECHARGE
  3857. {
  3858. currentStatus = Preparing; //OCPP Status: Preparing
  3859. }
  3860. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3861. {
  3862. currentStatus = Charging; //OCPP Status: Charging
  3863. }
  3864. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3865. {
  3866. currentStatus = Finishing; //OCPP Status: Finishing
  3867. }
  3868. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3869. {
  3870. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3871. }
  3872. 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
  3873. {
  3874. currentStatus = Unavailable; //OCPP Status: Unavailable
  3875. }
  3876. 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
  3877. {
  3878. currentStatus = Faulted; //OCPP Status: Faulted
  3879. }
  3880. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3881. {
  3882. currentStatus = Reserved; //OCPP Status: Reserved
  3883. }
  3884. } //end of the same index
  3885. }
  3886. }
  3887. else
  3888. {
  3889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3890. {
  3891. tempIndex = 2;
  3892. }
  3893. else
  3894. {
  3895. tempIndex = gun_index;
  3896. }
  3897. for (int index = 0; index < AC_QUANTITY; index++)
  3898. {
  3899. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3900. {
  3901. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3902. {
  3903. 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))
  3904. {
  3905. currentStatus = Preparing; //OCPP Status: Preparing
  3906. }
  3907. else
  3908. {
  3909. currentStatus = Available; //OCPP Status: Available
  3910. }
  3911. }
  3912. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3913. {
  3914. currentStatus = Preparing; //OCPP Status: Preparing
  3915. }
  3916. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3917. {
  3918. currentStatus = Charging; //OCPP Status: Charging
  3919. }
  3920. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3921. {
  3922. currentStatus = Finishing; //OCPP Status: Finishing
  3923. }
  3924. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3925. {
  3926. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3927. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3928. else
  3929. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3930. }
  3931. 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
  3932. {
  3933. currentStatus = Unavailable; //OCPP Status: Unavailable
  3934. }
  3935. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3936. {
  3937. currentStatus = Faulted; //OCPP Status: Faulted
  3938. }
  3939. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3940. {
  3941. currentStatus = Reserved; //OCPP Status: Reserved
  3942. }
  3943. }//end of the same index
  3944. }//end of for AC_QUANTITY
  3945. }
  3946. //it's option
  3947. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3948. !ShmOCPP16DataPH->CsMsg.bits[gun_index].TriggerMessageReq)
  3949. {
  3950. isStateChanged = FALSE;
  3951. }
  3952. ShmOCPP16DataPH->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3953. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  3954. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3955. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3956. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  3957. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  3958. random_uuid(guid);
  3959. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3960. , MESSAGE_TYPE_CALL
  3961. , guid
  3962. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  3963. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  3964. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  3965. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  3966. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  3967. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  3968. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  3969. if((server_sign == TRUE) && isStateChanged)
  3970. {
  3971. LWS_Send(message);
  3972. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3973. 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*/)
  3974. {
  3975. //DEBUG_ERROR("statusNotification mapitem pass");
  3976. result = PASS;
  3977. }
  3978. }
  3979. else
  3980. {
  3981. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3982. result = PASS;
  3983. }
  3984. return result;
  3985. }
  3986. int sendStopTransactionRequest(int gun_index)
  3987. {
  3988. mtrace();
  3989. int result = FAIL;
  3990. //char message[1500]={0};
  3991. char guid[37]={0};
  3992. char tempdata[65]={0};
  3993. int tempIndex = 0;
  3994. char TempStopTransaction[256];
  3995. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  3996. //int idx_sample=0;
  3997. DEBUG_INFO("sendStopTransactionRequest \n");
  3998. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3999. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4000. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4001. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4002. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4003. {
  4004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4005. {
  4006. tempIndex = ((gun_index==2) ? 1: 0);
  4007. }
  4008. else
  4009. {
  4010. tempIndex = gun_index;
  4011. }
  4012. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4013. {
  4014. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4015. {
  4016. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4017. }
  4018. }// END OF CHAdeMO_QUANTITY
  4019. }
  4020. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4021. {
  4022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4023. {
  4024. tempIndex = ((gun_index==2) ? 1: 0);
  4025. }
  4026. else
  4027. {
  4028. tempIndex = gun_index;
  4029. }
  4030. for (int index = 0; index < CCS_QUANTITY; index++)
  4031. {
  4032. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4033. {
  4034. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4035. }
  4036. }// END OF CCS_QUANTITY
  4037. }
  4038. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4039. {
  4040. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4041. {
  4042. tempIndex = ((gun_index==2) ? 1: 0);
  4043. }
  4044. else
  4045. {
  4046. tempIndex = gun_index;
  4047. }
  4048. for (int index = 0; index < GB_QUANTITY; index++)
  4049. {
  4050. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4051. {
  4052. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4053. }
  4054. }// END OF GB_QUANTITY
  4055. }
  4056. else if(gunType[gun_index] == GUN_TYPE_DO)
  4057. {
  4058. tempIndex = gun_index;
  4059. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4060. {
  4061. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4062. {
  4063. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4064. }
  4065. }// END OF GB_QUANTITY
  4066. }
  4067. else
  4068. {
  4069. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4070. {
  4071. tempIndex = 2;
  4072. }
  4073. else
  4074. {
  4075. tempIndex = gun_index;
  4076. }
  4077. for (int index = 0; index < AC_QUANTITY; index++)
  4078. {
  4079. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4080. {
  4081. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4082. }
  4083. }// END OF AC_QUANTITY
  4084. }
  4085. //====================================== Stop Transaction Time =====================================================
  4086. struct timeval tmnow;
  4087. struct tm *tm;
  4088. char buf[28];//, usec_buf[6];
  4089. gettimeofday(&tmnow, NULL);
  4090. time_t t;
  4091. t = time(NULL);
  4092. /*UTC time and date*/
  4093. tm = gmtime(&t);
  4094. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4095. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  4096. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  4097. random_uuid(guid);
  4098. /***********************************transactionData******************************************************/
  4099. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4100. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4101. //=================================
  4102. // Transaction_Begin
  4103. //=================================
  4104. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4105. {
  4106. //============================================ Energy.Active.Import.Interval ================================
  4107. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4108. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4109. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4110. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  4111. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4112. 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))
  4113. {
  4114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4115. }
  4116. else
  4117. {
  4118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4119. }
  4120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4122. }
  4123. //=================================
  4124. // Transaction_End
  4125. //=================================
  4126. // ================================= Current.Import L1 ===============================================
  4127. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4128. {
  4129. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4130. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4131. {
  4132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4133. {
  4134. tempIndex = ((gun_index==2) ? 1: 0);
  4135. }
  4136. else
  4137. {
  4138. tempIndex = gun_index;
  4139. }
  4140. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4141. {
  4142. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4143. {
  4144. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4145. }
  4146. }// End of for CHAdeMO_QUANTITY
  4147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4148. }
  4149. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4150. {
  4151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4152. {
  4153. tempIndex = ((gun_index==2) ? 1: 0);
  4154. }
  4155. else
  4156. {
  4157. tempIndex = gun_index;
  4158. }
  4159. for (int index = 0; index < CCS_QUANTITY; index++)
  4160. {
  4161. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4162. {
  4163. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4164. }
  4165. }// End of for CCS_QUANTITY
  4166. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4167. }
  4168. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4169. {
  4170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4171. {
  4172. tempIndex = ((gun_index==2) ? 1: 0);
  4173. }
  4174. else
  4175. {
  4176. tempIndex = gun_index;
  4177. }
  4178. for (int index = 0; index < GB_QUANTITY; index++)
  4179. {
  4180. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4181. {
  4182. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4183. }
  4184. }// End of for GB_QUANTITY
  4185. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4186. }
  4187. else if(gunType[gun_index] == GUN_TYPE_DO)
  4188. {
  4189. tempIndex = gun_index;
  4190. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4191. {
  4192. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4193. {
  4194. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4195. }
  4196. }
  4197. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4198. }
  4199. else
  4200. {
  4201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4202. {
  4203. tempIndex = 2;
  4204. }
  4205. else
  4206. {
  4207. tempIndex = gun_index;
  4208. }
  4209. for (int index = 0; index < AC_QUANTITY; index++)
  4210. {
  4211. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4212. {
  4213. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4214. }
  4215. }// End of for AC_QUANTITY
  4216. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4217. }
  4218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4220. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4221. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4222. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4223. }
  4224. // ================================= Energy.Active.Import.Interval ==============================================
  4225. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4226. {
  4227. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4228. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4229. {
  4230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4231. {
  4232. tempIndex = ((gun_index==2) ? 1: 0);
  4233. }
  4234. else
  4235. {
  4236. tempIndex = gun_index;
  4237. }
  4238. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4239. {
  4240. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4241. {
  4242. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4243. }
  4244. }// END OF CHAdeMO_QUANTITY
  4245. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4246. }
  4247. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4248. {
  4249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4250. {
  4251. tempIndex = ((gun_index==2) ? 1: 0);
  4252. }
  4253. else
  4254. {
  4255. tempIndex = gun_index;
  4256. }
  4257. for (int index = 0; index < CCS_QUANTITY; index++)
  4258. {
  4259. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4260. {
  4261. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4262. }
  4263. }// END OF CCS_QUANTITY
  4264. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4265. }
  4266. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4267. {
  4268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4269. {
  4270. tempIndex = ((gun_index==2) ? 1: 0);
  4271. }
  4272. else
  4273. {
  4274. tempIndex = gun_index;
  4275. }
  4276. for (int index = 0; index < GB_QUANTITY; index++)
  4277. {
  4278. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4279. {
  4280. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4281. }
  4282. }// END OF GB_QUANTITY
  4283. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4284. }
  4285. else if(gunType[gun_index] == GUN_TYPE_DO)
  4286. {
  4287. tempIndex = gun_index;
  4288. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4289. {
  4290. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4291. {
  4292. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4293. }
  4294. }
  4295. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4296. }
  4297. else
  4298. {
  4299. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4300. {
  4301. tempIndex = 2;
  4302. }
  4303. else
  4304. {
  4305. tempIndex = gun_index;
  4306. }
  4307. for (int index = 0; index < AC_QUANTITY; index++)
  4308. {
  4309. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4310. {
  4311. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4312. }
  4313. }// END OF AC_QUANTITY
  4314. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4315. }
  4316. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4317. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4318. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4319. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4320. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4321. }
  4322. //=================================== Power.Active.Import ==================================================
  4323. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4324. {
  4325. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4326. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4327. {
  4328. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4329. {
  4330. tempIndex = ((gun_index==2) ? 1: 0);
  4331. }
  4332. else
  4333. {
  4334. tempIndex = gun_index;
  4335. }
  4336. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4337. {
  4338. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4339. {
  4340. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4341. }
  4342. } // End for CHAdeMO_QUANTITY
  4343. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4344. }
  4345. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4346. {
  4347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4348. {
  4349. tempIndex = ((gun_index==2) ? 1: 0);
  4350. }
  4351. else
  4352. {
  4353. tempIndex = gun_index;
  4354. }
  4355. for (int index = 0; index < CCS_QUANTITY; index++)
  4356. {
  4357. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4358. {
  4359. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4360. }
  4361. } // END for CCS_QUANTITY
  4362. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4363. }
  4364. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4365. {
  4366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4367. {
  4368. tempIndex = ((gun_index==2) ? 1: 0);
  4369. }
  4370. else
  4371. {
  4372. tempIndex = gun_index;
  4373. }
  4374. for (int index = 0; index < GB_QUANTITY; index++)
  4375. {
  4376. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4377. {
  4378. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4379. }
  4380. }// END for GB_QUANTITY
  4381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4382. }
  4383. else if(gunType[gun_index] == GUN_TYPE_DO)
  4384. {
  4385. tempIndex = gun_index;
  4386. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4387. {
  4388. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4389. {
  4390. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4391. }
  4392. }
  4393. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4394. }
  4395. else
  4396. {
  4397. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4398. {
  4399. tempIndex = 2;
  4400. }
  4401. else
  4402. {
  4403. tempIndex = gun_index;
  4404. }
  4405. for (int index = 0; index < AC_QUANTITY; index++)
  4406. {
  4407. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4408. {
  4409. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4410. }
  4411. } // END for AC_QUANTITY
  4412. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4413. }
  4414. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4415. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4416. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4417. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4418. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4419. }
  4420. //============================ Voltage L1 ====================================
  4421. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4422. {
  4423. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4424. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4425. {
  4426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4427. {
  4428. tempIndex = ((gun_index==2) ? 1: 0);
  4429. }
  4430. else
  4431. {
  4432. tempIndex = gun_index;
  4433. }
  4434. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4435. {
  4436. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4437. {
  4438. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4439. }
  4440. } // END OF FOR CHAdeMO_QUANTITY
  4441. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4442. }
  4443. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4444. {
  4445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4446. {
  4447. tempIndex = ((gun_index==2) ? 1: 0);
  4448. }
  4449. else
  4450. {
  4451. tempIndex = gun_index;
  4452. }
  4453. for (int index = 0; index < CCS_QUANTITY; index++)
  4454. {
  4455. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4456. {
  4457. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4458. }
  4459. } // END OF FOR CCS_QUANTITY
  4460. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4461. }
  4462. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4463. {
  4464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4465. {
  4466. tempIndex = ((gun_index==2) ? 1: 0);
  4467. }
  4468. else
  4469. {
  4470. tempIndex = gun_index;
  4471. }
  4472. for (int index = 0; index < GB_QUANTITY; index++)
  4473. {
  4474. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4475. {
  4476. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4477. }
  4478. } // END OF FOR GB_QUANTITY
  4479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4480. }
  4481. else if(gunType[gun_index] == GUN_TYPE_DO)
  4482. {
  4483. tempIndex = gun_index;
  4484. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4485. {
  4486. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4487. {
  4488. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4489. }
  4490. }
  4491. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4492. }
  4493. else
  4494. {
  4495. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4496. {
  4497. tempIndex = 2;
  4498. }
  4499. else
  4500. {
  4501. tempIndex = gun_index;
  4502. }
  4503. for (int index = 0; index < AC_QUANTITY; index++)
  4504. {
  4505. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4506. {
  4507. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4508. }
  4509. } // END OF FOR AC_QUANTITY
  4510. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4511. }
  4512. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4513. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4514. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4515. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4516. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4517. }
  4518. //====================== End SoC ================================
  4519. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4520. {
  4521. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4522. 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))
  4523. {
  4524. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4525. {
  4526. tempIndex = ((gun_index==2) ? 1: 0);
  4527. }
  4528. else
  4529. {
  4530. tempIndex = gun_index;
  4531. }
  4532. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4533. {
  4534. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4535. {
  4536. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4537. {
  4538. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4539. }
  4540. }
  4541. }
  4542. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4543. {
  4544. for (int index = 0; index < CCS_QUANTITY; index++)
  4545. {
  4546. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4547. {
  4548. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4549. }
  4550. }
  4551. }
  4552. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4553. {
  4554. for (int index = 0; index < GB_QUANTITY; index++)
  4555. {
  4556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4557. {
  4558. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4559. }
  4560. }
  4561. }
  4562. else if(gunType[gun_index] == GUN_TYPE_DO)
  4563. {
  4564. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4565. {
  4566. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4567. {
  4568. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4569. }
  4570. }
  4571. }
  4572. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4573. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4574. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4575. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4576. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4577. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4578. } // END FOR DC CASE
  4579. }
  4580. // ================================= Current.Import L2 ===============================================
  4581. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4582. {
  4583. // AC 3 phse L2 current
  4584. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4585. {
  4586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4587. {
  4588. tempIndex = 2;
  4589. }
  4590. else
  4591. {
  4592. tempIndex = gun_index;
  4593. }
  4594. for (int index = 0; index < AC_QUANTITY; index++)
  4595. {
  4596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4597. {
  4598. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4599. }
  4600. }// End of for AC_QUANTITY
  4601. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4602. }
  4603. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4604. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4605. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4608. }
  4609. // ================================= Current.Import L3 ===============================================
  4610. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4611. {
  4612. // AC 3 phse L3 current
  4613. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4614. {
  4615. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4616. {
  4617. tempIndex = 2;
  4618. }
  4619. else
  4620. {
  4621. tempIndex = gun_index;
  4622. }
  4623. for (int index = 0; index < AC_QUANTITY; index++)
  4624. {
  4625. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4626. {
  4627. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4628. }
  4629. }// End of for AC_QUANTITY
  4630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4631. }
  4632. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4633. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4634. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4635. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4636. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4637. }
  4638. //============================ Voltage L2 ====================================
  4639. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4640. {
  4641. // AC 3 phse L2 voltage
  4642. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4643. {
  4644. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4645. {
  4646. tempIndex = 2;
  4647. }
  4648. else
  4649. {
  4650. tempIndex = gun_index;
  4651. }
  4652. for (int index = 0; index < AC_QUANTITY; index++)
  4653. {
  4654. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4655. {
  4656. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4657. }
  4658. } // END OF FOR AC_QUANTITY
  4659. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4660. }
  4661. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4662. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4663. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4664. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4665. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4666. }
  4667. //============================ Voltage L3 ====================================
  4668. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4669. {
  4670. // AC 3 phse L3 voltage
  4671. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4672. {
  4673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4674. {
  4675. tempIndex = 2;
  4676. }
  4677. else
  4678. {
  4679. tempIndex = gun_index;
  4680. }
  4681. for (int index = 0; index < AC_QUANTITY; index++)
  4682. {
  4683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4684. {
  4685. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4686. }
  4687. } // END OF FOR AC_QUANTITY
  4688. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4689. }
  4690. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4691. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4692. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4693. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4694. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4695. }
  4696. //====================== Start SoC ================================
  4697. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4698. {
  4699. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4700. 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))
  4701. {
  4702. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4703. {
  4704. tempIndex = ((gun_index==2) ? 1: 0);
  4705. }
  4706. else
  4707. {
  4708. tempIndex = gun_index;
  4709. }
  4710. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4711. {
  4712. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4713. {
  4714. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4715. {
  4716. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4717. }
  4718. }
  4719. }
  4720. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4721. {
  4722. for (int index = 0; index < CCS_QUANTITY; index++)
  4723. {
  4724. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4725. {
  4726. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4727. }
  4728. }
  4729. }
  4730. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4731. {
  4732. for (int index = 0; index < GB_QUANTITY; index++)
  4733. {
  4734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4735. {
  4736. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4737. }
  4738. }
  4739. }
  4740. else if(gunType[gun_index] == GUN_TYPE_DO)
  4741. {
  4742. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4743. {
  4744. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4745. {
  4746. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4747. }
  4748. }
  4749. }
  4750. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4751. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4753. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4754. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4756. } // END FOR DC CASE
  4757. }
  4758. //================================================ Message create ====================================================
  4759. json_object *StopTransaction = json_object_new_object();
  4760. json_object *transactionDatas = json_object_new_array();
  4761. json_object *sampledValues = json_object_new_array();
  4762. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  4763. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  4764. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  4765. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  4766. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  4767. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  4768. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  4769. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  4770. {
  4771. json_object *transactionData = json_object_new_object();
  4772. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4773. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4774. {
  4775. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4776. {
  4777. json_object *sampledValue = json_object_new_object();
  4778. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4779. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4780. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4781. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4782. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4783. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4784. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4785. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4786. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4787. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4788. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4789. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4790. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4791. json_object_array_add(sampledValues, sampledValue);
  4792. }
  4793. }
  4794. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4795. json_object_array_add(transactionDatas, transactionData);
  4796. }
  4797. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4798. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4799. ,MESSAGE_TYPE_CALL
  4800. ,guid
  4801. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4802. json_object_put(StopTransaction);
  4803. #if 1 // for TempStopTransaction
  4804. //Delete TempStopTransaction
  4805. if((access(TempStopTransaction,F_OK))!=-1)
  4806. {
  4807. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4808. }
  4809. #endif
  4810. #if 1
  4811. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4812. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4813. {
  4814. result = PASS;
  4815. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4816. }
  4817. #endif
  4818. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4819. OCPP_insert_transaction_msg(NO, queuedata);
  4820. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4821. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  4822. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  4823. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4824. {
  4825. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  4826. }
  4827. //for test
  4828. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4829. return result;
  4830. }
  4831. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4832. {
  4833. mtrace();
  4834. int result = FAIL;
  4835. char guid[37]={0};
  4836. char tempdata[65]={0};
  4837. int tempIndex = 0;
  4838. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4839. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4840. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4841. //set value
  4842. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4843. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  4844. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  4845. -1);
  4846. random_uuid(guid);
  4847. //UTC Date time
  4848. struct timeval tmnow;
  4849. struct tm *tm;
  4850. char buf[28];//, usec_buf[6];
  4851. gettimeofday(&tmnow, NULL);
  4852. time_t t;
  4853. t = time(NULL);
  4854. /*UTC time and date*/
  4855. tm = gmtime(&t);
  4856. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4857. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4858. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4859. //********************************(1)Current.Import L1************************************************/
  4860. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4861. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4862. (dataType == ReadingContext_Trigger))
  4863. {
  4864. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4865. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4866. {
  4867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4868. {
  4869. tempIndex = ((gun_index==2) ? 1: 0);
  4870. }
  4871. else
  4872. {
  4873. tempIndex = gun_index;
  4874. }
  4875. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4876. {
  4877. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4878. {
  4879. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4880. }
  4881. }
  4882. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4883. }
  4884. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4885. {
  4886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4887. {
  4888. tempIndex = ((gun_index==2) ? 1: 0);
  4889. }
  4890. else
  4891. {
  4892. tempIndex = gun_index;
  4893. }
  4894. for (int index = 0; index < CCS_QUANTITY; index++)
  4895. {
  4896. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4897. {
  4898. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4899. }
  4900. }
  4901. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4902. }
  4903. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4904. {
  4905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4906. {
  4907. tempIndex = ((gun_index==2) ? 1: 0);
  4908. }
  4909. else
  4910. {
  4911. tempIndex = gun_index;
  4912. }
  4913. for (int index = 0; index < GB_QUANTITY; index++)
  4914. {
  4915. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4916. {
  4917. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4918. }
  4919. }
  4920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4921. }
  4922. else if(gunType[gun_index] == GUN_TYPE_DO)
  4923. {
  4924. tempIndex = gun_index;
  4925. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4926. {
  4927. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4928. {
  4929. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4930. }
  4931. }
  4932. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4933. }
  4934. else
  4935. {
  4936. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4937. {
  4938. tempIndex = 2;
  4939. }
  4940. else
  4941. {
  4942. tempIndex = gun_index;
  4943. }
  4944. for (int index = 0; index < AC_QUANTITY; index++)
  4945. {
  4946. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4947. {
  4948. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4949. }
  4950. }
  4951. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4952. }
  4953. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4954. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4955. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4956. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4957. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4958. }
  4959. //********************************(2)Energy.Active.Import.Register ************************************************/
  4960. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4961. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4962. (dataType == ReadingContext_Trigger))
  4963. {
  4964. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4965. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4966. {
  4967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4968. {
  4969. tempIndex = ((gun_index==2) ? 1: 0);
  4970. }
  4971. else
  4972. {
  4973. tempIndex = gun_index;
  4974. }
  4975. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4976. {
  4977. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4978. {
  4979. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4980. }
  4981. }
  4982. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4983. }
  4984. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4985. {
  4986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4987. {
  4988. tempIndex = ((gun_index==2) ? 1: 0);
  4989. }
  4990. else
  4991. {
  4992. tempIndex = gun_index;
  4993. }
  4994. for (int index = 0; index < CCS_QUANTITY; index++)
  4995. {
  4996. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4997. {
  4998. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4999. }
  5000. }
  5001. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5002. }
  5003. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5004. {
  5005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5006. {
  5007. tempIndex = ((gun_index==2) ? 1: 0);
  5008. }
  5009. else
  5010. {
  5011. tempIndex = gun_index;
  5012. }
  5013. for (int index = 0; index < GB_QUANTITY; index++)
  5014. {
  5015. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5016. {
  5017. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5018. }
  5019. }
  5020. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5021. }
  5022. else if(gunType[gun_index] == GUN_TYPE_DO)
  5023. {
  5024. tempIndex = gun_index;
  5025. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5026. {
  5027. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5028. {
  5029. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5030. }
  5031. }
  5032. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5033. }
  5034. else
  5035. {
  5036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5037. {
  5038. tempIndex = 2;
  5039. }
  5040. else
  5041. {
  5042. tempIndex = gun_index;
  5043. }
  5044. for (int index = 0; index < AC_QUANTITY; index++)
  5045. {
  5046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5047. {
  5048. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5049. }
  5050. }
  5051. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5052. }
  5053. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5054. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5055. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5056. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5057. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5058. }
  5059. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5060. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5061. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5062. (dataType == ReadingContext_Trigger))
  5063. {
  5064. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5065. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5066. {
  5067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5068. {
  5069. tempIndex = ((gun_index==2) ? 1: 0);
  5070. }
  5071. else
  5072. {
  5073. tempIndex = gun_index;
  5074. }
  5075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5076. {
  5077. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5078. {
  5079. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5080. }
  5081. } // END OF FOR CHAdeMO_QUANTITY
  5082. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5083. }
  5084. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5085. {
  5086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5087. {
  5088. tempIndex = ((gun_index==2) ? 1: 0);
  5089. }
  5090. else
  5091. {
  5092. tempIndex = gun_index;
  5093. }
  5094. for (int index = 0; index < CCS_QUANTITY; index++)
  5095. {
  5096. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5097. {
  5098. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5099. }
  5100. } // END OF CCS_QUANTITY
  5101. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5102. }
  5103. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5104. {
  5105. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5106. {
  5107. tempIndex = ((gun_index==2) ? 1: 0);
  5108. }
  5109. else
  5110. {
  5111. tempIndex = gun_index;
  5112. }
  5113. for (int index = 0; index < GB_QUANTITY; index++)
  5114. {
  5115. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5116. {
  5117. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5118. }
  5119. } // END OF GB_QUANTITY
  5120. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5121. }
  5122. else if(gunType[gun_index] == GUN_TYPE_DO)
  5123. {
  5124. tempIndex = gun_index;
  5125. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5126. {
  5127. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5128. {
  5129. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5130. }
  5131. }
  5132. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5133. }
  5134. else
  5135. {
  5136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5137. {
  5138. tempIndex = 2;
  5139. }
  5140. else
  5141. {
  5142. tempIndex = gun_index;
  5143. }
  5144. for (int index = 0; index < AC_QUANTITY; index++)
  5145. {
  5146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5147. {
  5148. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5149. }
  5150. }
  5151. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5152. }
  5153. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5154. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5155. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5156. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5157. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5158. }
  5159. //********************************(4)Power.Active.Import************************************************/
  5160. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5161. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5162. (dataType == ReadingContext_Trigger))
  5163. {
  5164. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5165. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5166. {
  5167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5168. {
  5169. tempIndex = ((gun_index==2) ? 1: 0);
  5170. }
  5171. else
  5172. {
  5173. tempIndex = gun_index;
  5174. }
  5175. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5176. {
  5177. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5178. {
  5179. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5180. }
  5181. } // END OF FOR
  5182. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5183. }
  5184. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5185. {
  5186. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5187. {
  5188. tempIndex = ((gun_index==2) ? 1: 0);
  5189. }
  5190. else
  5191. {
  5192. tempIndex = gun_index;
  5193. }
  5194. for (int index = 0; index < CCS_QUANTITY; index++)
  5195. {
  5196. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5197. {
  5198. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5199. }
  5200. }
  5201. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5202. }
  5203. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5204. {
  5205. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5206. {
  5207. tempIndex = ((gun_index==2) ? 1: 0);
  5208. }
  5209. else
  5210. {
  5211. tempIndex = gun_index;
  5212. }
  5213. for (int index = 0; index < GB_QUANTITY; index++)
  5214. {
  5215. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5216. {
  5217. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5218. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5219. }
  5220. }
  5221. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5222. }
  5223. else if(gunType[gun_index] == GUN_TYPE_DO)
  5224. {
  5225. tempIndex = gun_index;
  5226. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5227. {
  5228. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5229. {
  5230. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5231. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5232. }
  5233. }
  5234. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5235. }
  5236. else
  5237. {
  5238. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5239. {
  5240. tempIndex = 2;
  5241. }
  5242. else
  5243. {
  5244. tempIndex = gun_index;
  5245. }
  5246. for (int index = 0; index < AC_QUANTITY; index++)
  5247. {
  5248. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5249. {
  5250. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5251. }
  5252. }
  5253. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5254. }
  5255. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5256. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5257. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5258. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5259. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5260. }
  5261. //***********************************************(5)VOLTAGE L1******************************************************/
  5262. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5263. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5264. (dataType == ReadingContext_Trigger))
  5265. {
  5266. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5267. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5268. {
  5269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5270. {
  5271. tempIndex = ((gun_index==2) ? 1: 0);
  5272. }
  5273. else
  5274. {
  5275. tempIndex = gun_index;
  5276. }
  5277. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5278. {
  5279. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5280. {
  5281. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5282. }
  5283. }
  5284. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5285. }
  5286. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5287. {
  5288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5289. {
  5290. tempIndex = ((gun_index==2) ? 1: 0);
  5291. }
  5292. else
  5293. {
  5294. tempIndex = gun_index;
  5295. }
  5296. for (int index = 0; index < CCS_QUANTITY; index++)
  5297. {
  5298. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5299. {
  5300. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5301. }
  5302. }
  5303. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5304. }
  5305. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5306. {
  5307. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5308. {
  5309. tempIndex = ((gun_index==2) ? 1: 0);
  5310. }
  5311. else
  5312. {
  5313. tempIndex = gun_index;
  5314. }
  5315. for (int index = 0; index < GB_QUANTITY; index++)
  5316. {
  5317. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5318. {
  5319. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5320. }
  5321. }
  5322. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5323. }
  5324. else if(gunType[gun_index] == GUN_TYPE_DO)
  5325. {
  5326. tempIndex = gun_index;
  5327. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5328. {
  5329. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5330. {
  5331. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5332. }
  5333. }
  5334. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5335. }
  5336. else
  5337. {
  5338. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5339. {
  5340. tempIndex = 2;
  5341. }
  5342. else
  5343. {
  5344. tempIndex = gun_index;
  5345. }
  5346. for (int index = 0; index < AC_QUANTITY; index++)
  5347. {
  5348. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5349. {
  5350. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5351. }
  5352. }
  5353. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5354. }
  5355. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5356. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5357. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5358. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5359. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5360. }
  5361. //***********************************************(6)SOC******************************************************/
  5362. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5363. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5364. (dataType == ReadingContext_Trigger))
  5365. {
  5366. 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))
  5367. {
  5368. //idx_sample=5;
  5369. //sampledValue = NULL;
  5370. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5371. {
  5372. tempIndex = ((gun_index==2) ? 1: 0);
  5373. }
  5374. else
  5375. {
  5376. tempIndex = gun_index;
  5377. }
  5378. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5379. {
  5380. //tempIndex = ((gun_index==2) ? 1: 0);
  5381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5382. {
  5383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5384. {
  5385. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5386. }
  5387. }
  5388. }
  5389. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5390. {
  5391. //tempIndex = ((gun_index==2) ? 1: 0);
  5392. for (int index = 0; index < CCS_QUANTITY; index++)
  5393. {
  5394. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5395. {
  5396. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5397. }
  5398. }
  5399. }
  5400. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5401. {
  5402. //tempIndex = ((gun_index==2) ? 1: 0);
  5403. for (int index = 0; index < GB_QUANTITY; index++)
  5404. {
  5405. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5406. {
  5407. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5408. }
  5409. }
  5410. }
  5411. else if(gunType[gun_index] == GUN_TYPE_DO)
  5412. {
  5413. //tempIndex = ((gun_index==2) ? 1: 0);
  5414. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5415. {
  5416. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5417. {
  5418. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5419. }
  5420. }
  5421. }
  5422. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5423. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5424. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5425. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5426. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5427. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5428. }
  5429. }
  5430. //********************************(7)Current.Import L2************************************************/
  5431. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5432. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5433. (dataType == ReadingContext_Trigger))
  5434. {
  5435. // Only for AC 3 phase
  5436. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5437. {
  5438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5439. {
  5440. tempIndex = 2;
  5441. }
  5442. else
  5443. {
  5444. tempIndex = gun_index;
  5445. }
  5446. for (int index = 0; index < AC_QUANTITY; index++)
  5447. {
  5448. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5449. {
  5450. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5451. }
  5452. }
  5453. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5454. }
  5455. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5456. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5457. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5458. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5459. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5460. }
  5461. //********************************(8)Current.Import L3************************************************/
  5462. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5463. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5464. (dataType == ReadingContext_Trigger))
  5465. {
  5466. // Only for AC 3 phase
  5467. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5468. {
  5469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5470. {
  5471. tempIndex = 2;
  5472. }
  5473. else
  5474. {
  5475. tempIndex = gun_index;
  5476. }
  5477. for (int index = 0; index < AC_QUANTITY; index++)
  5478. {
  5479. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5480. {
  5481. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5482. }
  5483. }
  5484. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5485. }
  5486. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5487. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5488. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5489. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5490. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5491. }
  5492. //***********************************************(9)VOLTAGE L2******************************************************/
  5493. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5494. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5495. (dataType == ReadingContext_Trigger))
  5496. {
  5497. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5498. {
  5499. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5500. {
  5501. tempIndex = 2;
  5502. }
  5503. else
  5504. {
  5505. tempIndex = gun_index;
  5506. }
  5507. for (int index = 0; index < AC_QUANTITY; index++)
  5508. {
  5509. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5510. {
  5511. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5512. }
  5513. }
  5514. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5515. }
  5516. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5517. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5518. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5519. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5520. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5521. }
  5522. //***********************************************(10)VOLTAGE L3******************************************************/
  5523. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5524. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5525. (dataType == ReadingContext_Trigger))
  5526. {
  5527. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5528. {
  5529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5530. {
  5531. tempIndex = 2;
  5532. }
  5533. else
  5534. {
  5535. tempIndex = gun_index;
  5536. }
  5537. for (int index = 0; index < AC_QUANTITY; index++)
  5538. {
  5539. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5540. {
  5541. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5542. }
  5543. }
  5544. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5545. }
  5546. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5547. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5548. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5549. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5550. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5551. }
  5552. // Message create ====================================================================================================
  5553. if(TRUE)
  5554. {
  5555. json_object *MeterValueReq = json_object_new_object();
  5556. json_object *MeterValues = json_object_new_array();
  5557. json_object *sampledValues = json_object_new_array();
  5558. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  5559. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  5560. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  5561. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  5562. {
  5563. json_object *MeterValue = json_object_new_object();
  5564. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5565. {
  5566. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5567. {
  5568. json_object *sampledValue = json_object_new_object();
  5569. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5570. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5571. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5572. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5573. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5574. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5575. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5576. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5577. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5578. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5579. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5580. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5581. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5582. json_object_array_add(sampledValues, sampledValue);
  5583. }
  5584. }
  5585. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5586. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5587. json_object_array_add(MeterValues, MeterValue);
  5588. }
  5589. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5590. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5591. ,gun_index + 1
  5592. ,MESSAGE_TYPE_CALL
  5593. ,guid
  5594. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5595. json_object_put(MeterValueReq);
  5596. }
  5597. // Put request guid to hash map
  5598. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5599. 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*/)
  5600. {
  5601. result = PASS;
  5602. //DEBUG_INFO("MeterValues mapitem pass\n");
  5603. }
  5604. if((dataType != ReadingContext_Trigger) &&
  5605. (dataType != ReadingContext_Sample_Clock) &&
  5606. (ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1))
  5607. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5608. else
  5609. {
  5610. if(FirstHeartBeat)
  5611. LWS_Send(queuedata +2);
  5612. }
  5613. return result;
  5614. }
  5615. int sendLogStatusNotificationRequest(char *status)
  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 *LogStatusNotification = json_object_new_object();
  5623. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5624. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  5625. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  5626. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  5627. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  5628. random_uuid(guid);
  5629. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5630. json_object_put(LogStatusNotification);
  5631. LWS_Send(message);
  5632. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5633. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5634. {
  5635. result = PASS;
  5636. }
  5637. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  5638. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  5639. return result;
  5640. }
  5641. int sendSecurityEventNotificationRequest()
  5642. {
  5643. mtrace();
  5644. int result = PASS;
  5645. char message[4096]={0};
  5646. char guid[37]={0};
  5647. char tempdata[128]={0};
  5648. json_object *SecurityEventNotification = json_object_new_object();
  5649. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5650. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  5651. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  5652. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  5653. random_uuid(guid);
  5654. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5655. json_object_put(SecurityEventNotification);
  5656. LWS_Send(message);
  5657. sprintf(tempdata, "SecurityEventNotification,0");
  5658. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5659. {
  5660. result = PASS;
  5661. }
  5662. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  5663. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  5664. return result;
  5665. }
  5666. int sendSignCertificateRequest()
  5667. {
  5668. mtrace();
  5669. int result = PASS;
  5670. char message[4096]={0};
  5671. char guid[37]={0};
  5672. char tempdata[128]={0};
  5673. json_object *SignCertificate = json_object_new_object();
  5674. DEBUG_INFO("sendSignCertificateRequest...\n");
  5675. // Read csr file content
  5676. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  5677. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  5678. char *line = NULL;
  5679. size_t len = 0;
  5680. while(getline(&line, &len, fp) != -1)
  5681. {
  5682. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5683. {
  5684. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  5685. }
  5686. }
  5687. fclose(fp);
  5688. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  5689. random_uuid(guid);
  5690. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5691. json_object_put(SignCertificate);
  5692. LWS_Send(message);
  5693. sprintf(tempdata, "SignCertificate,0");
  5694. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5695. {
  5696. result = PASS;
  5697. }
  5698. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  5699. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  5700. return result;
  5701. }
  5702. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5703. {
  5704. mtrace();
  5705. int result = PASS;
  5706. char message[110]={0};
  5707. char guid[37]={0};
  5708. char tempdata[65]={0};
  5709. json_object *FirmwareStatusNotification = json_object_new_object();
  5710. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5711. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5712. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  5713. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  5714. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  5715. random_uuid(guid);
  5716. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5717. json_object_put(FirmwareStatusNotification);
  5718. LWS_Send(message);
  5719. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5720. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5721. {
  5722. result = PASS;
  5723. }
  5724. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5725. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5726. return result;
  5727. }
  5728. //==========================================
  5729. // send confirm routine
  5730. //==========================================
  5731. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5732. {
  5733. mtrace();
  5734. int result = FAIL;
  5735. char message[100]={0};
  5736. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5737. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5738. LWS_Send(message);
  5739. result = TRUE;
  5740. return result;
  5741. }
  5742. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5743. {
  5744. mtrace();
  5745. int result = FAIL;
  5746. char message[100]={0};
  5747. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5748. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5749. LWS_Send(message);
  5750. result = TRUE;
  5751. return result;
  5752. }
  5753. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5754. {
  5755. mtrace();
  5756. int result = FAIL;
  5757. char message[100]={0};
  5758. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5759. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5760. LWS_Send(message);
  5761. result = TRUE;
  5762. return result;
  5763. }
  5764. int sendClearCacheConfirmation(char *uuid,char *payload)
  5765. {
  5766. mtrace();
  5767. int result = FAIL;
  5768. char message[500]={0};
  5769. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5770. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5771. LWS_Send(message);
  5772. return result;
  5773. }
  5774. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5775. {
  5776. mtrace();
  5777. int result = FAIL;
  5778. char message[500]={0};
  5779. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5780. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5781. LWS_Send(message);
  5782. return result;
  5783. }
  5784. int sendDataTransferConfirmation(char *uuid,char *payload)
  5785. {
  5786. mtrace();
  5787. char statusStr[20]={0};
  5788. char dataStr[10]={0};
  5789. char sstr[20]={0};
  5790. int c = 0;
  5791. char *loc;
  5792. int result = FAIL;
  5793. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5794. /**********************status**************************/
  5795. loc = strstr(payload, "status");
  5796. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5797. c = 0;
  5798. while (loc[3+strlen("status")+c] != '\"')
  5799. {
  5800. sstr[c] = loc[3+strlen("status")+c];
  5801. c++;
  5802. }
  5803. sstr[c] = '\0';
  5804. strcpy(statusStr, sstr);
  5805. /**********************data**************************/
  5806. loc = strstr(payload, "data");
  5807. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5808. c = 0;
  5809. while (loc[3+strlen("data")+c] != '\"')
  5810. {
  5811. sstr[c] = loc[3+strlen("data")+c];
  5812. c++;
  5813. }
  5814. sstr[c] = '\0';
  5815. strcpy(dataStr, sstr);
  5816. return result;
  5817. }
  5818. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5819. {
  5820. mtrace();
  5821. int result = FAIL;
  5822. char message[1000]={0};
  5823. int CompositeScheduleIndex = 0;
  5824. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5825. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5826. if(nPeriod == 0)
  5827. {
  5828. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5829. {
  5830. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5831. ,MESSAGE_TYPE_CALLRESULT
  5832. ,uuid
  5833. ,payload
  5834. ,connectorIdInt);
  5835. }
  5836. else
  5837. {
  5838. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5839. ,MESSAGE_TYPE_CALLRESULT
  5840. ,uuid
  5841. ,payload
  5842. ,connectorIdInt
  5843. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5844. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5845. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5846. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5847. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5848. }
  5849. }
  5850. else
  5851. {
  5852. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5853. ,MESSAGE_TYPE_CALLRESULT
  5854. ,uuid
  5855. ,payload
  5856. ,connectorIdInt
  5857. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5858. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5859. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5860. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5861. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5862. {
  5863. if (idx_sample == 0)
  5864. {
  5865. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5866. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5867. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5868. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5869. }
  5870. else
  5871. {
  5872. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5873. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5874. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5875. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5876. }
  5877. }
  5878. sprintf(message + strlen(message), "]}}]");
  5879. }
  5880. LWS_Send(message);
  5881. result = TRUE;
  5882. return result;
  5883. }
  5884. int sendGetConfigurationConfirmation(char *uuid)
  5885. {
  5886. mtrace();
  5887. int result = FAIL;
  5888. int MaxKeySupported = 0;
  5889. int sentConfigurationNumber= 0;
  5890. int sentunConfigurationNumber= 0;
  5891. char message[4000]={0};
  5892. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5893. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5894. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5895. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5896. ,MESSAGE_TYPE_CALLRESULT
  5897. ,uuid );
  5898. //configuration key
  5899. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5900. {
  5901. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5902. {
  5903. if (sentConfigurationNumber == 0)
  5904. {
  5905. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5906. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5907. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5908. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5909. }
  5910. else
  5911. {
  5912. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5913. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5914. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5915. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5916. }
  5917. sentConfigurationNumber = sentConfigurationNumber + 1;
  5918. }
  5919. }
  5920. sprintf(message + strlen(message), "]");
  5921. if(UnknownKeynum != 0)
  5922. {
  5923. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5924. //unkown key
  5925. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5926. {
  5927. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5928. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5929. if(sentunConfigurationNumber == 0)
  5930. {
  5931. sprintf(message + strlen(message), "\"%s\""
  5932. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5933. }
  5934. else
  5935. {
  5936. sprintf(message + strlen(message), ",\"%s\""
  5937. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5938. }
  5939. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5940. }
  5941. sprintf(message + strlen(message), "]");
  5942. }
  5943. sprintf(message + strlen(message), "}]");
  5944. LWS_Send(message);
  5945. return result;
  5946. }
  5947. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5948. {
  5949. mtrace();
  5950. int result = FAIL;
  5951. char message[400]={0};
  5952. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5953. if(strcmp(payload,"")==0)
  5954. {
  5955. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5956. }
  5957. else
  5958. {
  5959. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5960. }
  5961. LWS_Send(message);
  5962. result = TRUE;
  5963. return result;
  5964. }
  5965. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5966. {
  5967. mtrace();
  5968. int result = FAIL;
  5969. char message[80]={0};
  5970. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5971. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  5972. LWS_Send(message);
  5973. result = TRUE;
  5974. return result;
  5975. }
  5976. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5977. {
  5978. mtrace();
  5979. int result = FAIL;
  5980. char message[80]={0};
  5981. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5982. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5983. LWS_Send(message);
  5984. result = TRUE;
  5985. return result;
  5986. }
  5987. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5988. {
  5989. mtrace();
  5990. int result = FAIL;
  5991. char message[80]={0};
  5992. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5993. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5994. LWS_Send(message);
  5995. result = TRUE;
  5996. return result;
  5997. }
  5998. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5999. {
  6000. mtrace();
  6001. int result = FAIL;
  6002. char message[80]={0};
  6003. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6004. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6005. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6006. LWS_Send(message);
  6007. result = TRUE;
  6008. return result;
  6009. }
  6010. int sendResetConfirmation(char *uuid,char *payload)
  6011. {
  6012. mtrace();
  6013. int result = FAIL;
  6014. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6015. char message[80]={0};
  6016. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  6017. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6018. LWS_Send(message);
  6019. result = TRUE;
  6020. return result;
  6021. }
  6022. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6023. {
  6024. mtrace();
  6025. int result = FAIL;
  6026. char message[500]={0};
  6027. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6028. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6029. LWS_Send(message);
  6030. result = TRUE;
  6031. return result;
  6032. }
  6033. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6034. {
  6035. mtrace();
  6036. int result = FAIL;
  6037. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6038. char message[80]={0};
  6039. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6040. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6041. LWS_Send(message);
  6042. result = TRUE;
  6043. return result;
  6044. }
  6045. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6046. {
  6047. mtrace();
  6048. int result = FAIL;
  6049. char message[80]={0};
  6050. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6051. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6052. LWS_Send(message);
  6053. result = TRUE;
  6054. return result;
  6055. }
  6056. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6057. {
  6058. mtrace();
  6059. int result = FAIL;
  6060. char message[80]={0};
  6061. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6062. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6063. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6064. LWS_Send(message);
  6065. result = TRUE;
  6066. return result;
  6067. }
  6068. int sendUpdateFirmwareConfirmation(char *uuid)
  6069. {
  6070. mtrace();
  6071. int result = FAIL;
  6072. char message[60]={0};
  6073. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6074. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6075. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6076. LWS_Send(message);
  6077. result = TRUE;
  6078. return result;
  6079. }
  6080. int sendCertificateSignedConfirmation(char *uuid)
  6081. {
  6082. mtrace();
  6083. int result = PASS;
  6084. char message[4096]={0};
  6085. json_object *CertificateSigned = json_object_new_object();
  6086. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6087. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  6088. sprintf(message,"[%d,\"%s\",%s]"
  6089. ,MESSAGE_TYPE_CALLRESULT
  6090. ,uuid
  6091. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6092. json_object_put(CertificateSigned);
  6093. LWS_Send(message);
  6094. return result;
  6095. }
  6096. int sendDeleteCertificateConfirmation(char *uuid)
  6097. {
  6098. mtrace();
  6099. int result = PASS;
  6100. char message[4096]={0};
  6101. json_object *DeleteCertificate = json_object_new_object();
  6102. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6103. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  6104. sprintf(message,"[%d,\"%s\",%s]"
  6105. ,MESSAGE_TYPE_CALLRESULT
  6106. ,uuid
  6107. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6108. json_object_put(DeleteCertificate);
  6109. LWS_Send(message);
  6110. return result;
  6111. }
  6112. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6113. {
  6114. mtrace();
  6115. int result = PASS;
  6116. char message[4096]={0};
  6117. json_object *ExtendedTriggerMessage = json_object_new_object();
  6118. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6119. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  6120. sprintf(message,"[%d,\"%s\",%s]"
  6121. ,MESSAGE_TYPE_CALLRESULT
  6122. ,uuid
  6123. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6124. json_object_put(ExtendedTriggerMessage);
  6125. LWS_Send(message);
  6126. return result;
  6127. }
  6128. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6129. {
  6130. mtrace();
  6131. int result = PASS;
  6132. char message[4096]={0};
  6133. json_object *GetInstalledCertificateIds = json_object_new_object();
  6134. json_object *certificateHashDataDatas = json_object_new_array();
  6135. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6136. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  6137. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6138. {
  6139. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6140. {
  6141. json_object *certificateHashData = json_object_new_object();
  6142. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6143. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6144. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6145. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6146. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6147. }
  6148. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6149. }
  6150. else
  6151. {
  6152. json_object_put(certificateHashDataDatas);
  6153. }
  6154. sprintf(message,"[%d,\"%s\",%s]"
  6155. ,MESSAGE_TYPE_CALLRESULT
  6156. ,uuid
  6157. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6158. json_object_put(GetInstalledCertificateIds);
  6159. LWS_Send(message);
  6160. return result;
  6161. }
  6162. int sendGetLogConfirmation(char *uuid)
  6163. {
  6164. mtrace();
  6165. int result = PASS;
  6166. char message[4096]={0};
  6167. json_object *GetLog = json_object_new_object();
  6168. DEBUG_INFO("sendGetLogConfirmation...\n");
  6169. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  6170. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  6171. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  6172. sprintf(message,"[%d,\"%s\",%s]"
  6173. ,MESSAGE_TYPE_CALLRESULT
  6174. ,uuid
  6175. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6176. json_object_put(GetLog);
  6177. LWS_Send(message);
  6178. return result;
  6179. }
  6180. int sendInstallCertificateConfirmation(char *uuid)
  6181. {
  6182. mtrace();
  6183. int result = PASS;
  6184. char message[4096]={0};
  6185. json_object *InstallCertificate = json_object_new_object();
  6186. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6187. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  6188. sprintf(message,"[%d,\"%s\",%s]"
  6189. ,MESSAGE_TYPE_CALLRESULT
  6190. ,uuid
  6191. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6192. json_object_put(InstallCertificate);
  6193. LWS_Send(message);
  6194. return result;
  6195. }
  6196. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6197. {
  6198. mtrace();
  6199. int result = PASS;
  6200. char message[4096]={0};
  6201. json_object *SignedUpdateFirmware = json_object_new_object();
  6202. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6203. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  6204. sprintf(message,"[%d,\"%s\",%s]"
  6205. ,MESSAGE_TYPE_CALLRESULT
  6206. ,uuid
  6207. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6208. json_object_put(SignedUpdateFirmware);
  6209. LWS_Send(message);
  6210. return result;
  6211. }
  6212. int sendUnknownConfirmation(char *uuid)
  6213. {
  6214. mtrace();
  6215. int result = PASS;
  6216. char message[256]={0};
  6217. DEBUG_INFO("sendUnknownConfirmation...\n");
  6218. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6219. LWS_Send(message);
  6220. return result;
  6221. }
  6222. //==========================================
  6223. // Handle server request routine Start
  6224. //==========================================
  6225. int handleCancelReservationRequest(char *uuid, char *payload)
  6226. {
  6227. mtrace();
  6228. int result = FAIL;
  6229. int gunNO = 0;
  6230. int reservationIdInt = -1;
  6231. char comfirmstr[20];
  6232. DEBUG_INFO("handleCancelReservationRequest...\n");
  6233. json_object *CancelReservation;
  6234. CancelReservation = json_tokener_parse(payload);
  6235. if(!is_error(CancelReservation))
  6236. {
  6237. // Required data
  6238. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6239. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6240. }
  6241. json_object_put(CancelReservation);
  6242. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6243. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6244. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6245. if(reservationIdInt != -1)
  6246. {
  6247. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6248. //check Transaction active
  6249. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6250. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6251. {
  6252. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6253. {
  6254. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6255. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6256. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6257. {
  6258. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6259. }
  6260. else
  6261. {
  6262. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6263. }
  6264. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6265. goto end;
  6266. }
  6267. }
  6268. for (int index = 0; index < CCS_QUANTITY; index++)
  6269. {
  6270. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6271. {
  6272. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6273. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6274. if(gunType[2] == GUN_TYPE_CCS)
  6275. {
  6276. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6277. }
  6278. else
  6279. {
  6280. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6281. }
  6282. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6283. goto end;
  6284. }
  6285. }
  6286. for (int index = 0; index < GB_QUANTITY; index++)
  6287. {
  6288. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6289. {
  6290. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6291. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6292. if(gunType[2] == GUN_TYPE_GBT)
  6293. {
  6294. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6295. }
  6296. else
  6297. {
  6298. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6299. }
  6300. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6301. goto end;
  6302. }
  6303. }
  6304. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6305. {
  6306. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6307. {
  6308. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6309. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6310. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6311. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6312. goto end;
  6313. }
  6314. }
  6315. for (int index = 0; index < AC_QUANTITY; index++)
  6316. {
  6317. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6318. {
  6319. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6320. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6321. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6322. {
  6323. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6324. }
  6325. else
  6326. {
  6327. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6328. }
  6329. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6330. goto end;
  6331. }
  6332. }
  6333. }
  6334. //The reservationId does NOT match the reservationId
  6335. sendCancelReservationConfirmation(uuid, comfirmstr);
  6336. end:
  6337. // Fill in ocpp packet uuid
  6338. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  6339. return result;
  6340. }
  6341. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6342. {
  6343. mtrace();
  6344. int result = FAIL;
  6345. int gunIndex = 0;
  6346. char typeStr[16]={0};
  6347. char comfirmstr[20];
  6348. int specificId = FALSE;
  6349. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6350. json_object *ChangeAvailability;
  6351. ChangeAvailability = json_tokener_parse(payload);
  6352. if(!is_error(ChangeAvailability))
  6353. {
  6354. // Required data
  6355. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6356. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6357. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6358. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6359. }
  6360. json_object_put(ChangeAvailability);
  6361. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6362. {
  6363. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6364. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6365. }
  6366. else if(gunIndex == 0)
  6367. {
  6368. for(int i=0; i < gunTotalNumber; i++)
  6369. {
  6370. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  6371. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  6372. }
  6373. }
  6374. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6375. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6376. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6377. {
  6378. specificId = TRUE;
  6379. }
  6380. if(specificId == FALSE)
  6381. goto end;
  6382. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6383. {
  6384. //----------------------gunIndex is 0 ------------------------------------------------//
  6385. if(gunIndex == 0)
  6386. {
  6387. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6388. {
  6389. for(int i=0; i < gunTotalNumber; i++)
  6390. {
  6391. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6392. {
  6393. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6394. {
  6395. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6396. {
  6397. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6398. goto end;
  6399. }
  6400. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6401. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6402. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6403. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6404. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6405. {
  6406. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6407. goto end;
  6408. }
  6409. }
  6410. }//END FOR CHAdeMO_QUANTITY
  6411. for (int index = 0; index < CCS_QUANTITY; index++)
  6412. {
  6413. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6414. {
  6415. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6416. {
  6417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6418. goto end;
  6419. }
  6420. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6421. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6422. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6423. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6424. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6425. {
  6426. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6427. goto end;
  6428. }
  6429. }
  6430. }//END FOR CCS_QUANTITY
  6431. for (int index = 0; index < GB_QUANTITY; index++)
  6432. {
  6433. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6434. {
  6435. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6436. {
  6437. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6438. goto end;
  6439. }
  6440. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6441. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6442. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6443. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6444. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6445. {
  6446. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6447. goto end;
  6448. }
  6449. }
  6450. }// END FOR GB_QUANTITY
  6451. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6452. {
  6453. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6454. {
  6455. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6456. {
  6457. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6458. goto end;
  6459. }
  6460. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6461. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6462. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6463. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6464. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6465. {
  6466. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6467. goto end;
  6468. }
  6469. }
  6470. }// END FOR GENERAL_GUN_QUANTITY
  6471. for (int index = 0; index < AC_QUANTITY; index++)
  6472. {
  6473. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6474. {
  6475. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6476. {
  6477. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6478. goto end;
  6479. }
  6480. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6481. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6482. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6483. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6484. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6485. {
  6486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6487. goto end;
  6488. }
  6489. }
  6490. }//END FOR AC_QUANTITY
  6491. }// END FOR gunTotalNumber
  6492. }
  6493. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6494. {
  6495. for(int i=0; i < gunTotalNumber; i++)
  6496. {
  6497. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6498. {
  6499. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6500. goto end;
  6501. }
  6502. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6503. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6504. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6505. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6506. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6507. {
  6508. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6509. goto end;
  6510. }
  6511. }
  6512. }
  6513. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6514. goto end;
  6515. }
  6516. //----------------------gunIndex is not 0 ------------------------------------------------//
  6517. //check Transaction active
  6518. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6519. {
  6520. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6521. {
  6522. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6523. {
  6524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6525. goto end;
  6526. }
  6527. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6528. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6529. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6530. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6531. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[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.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6539. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6540. goto end;
  6541. }
  6542. }
  6543. }//END FOR CHAdeMO_QUANTITY
  6544. for (int index = 0; index < CCS_QUANTITY; index++)
  6545. {
  6546. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6547. {
  6548. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6549. {
  6550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6551. goto end;
  6552. }
  6553. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6554. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6555. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6556. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6557. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[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.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6565. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6566. goto end;
  6567. }
  6568. }
  6569. }//END FOR CCS_QUANTITY
  6570. for (int index = 0; index < GB_QUANTITY; index++)
  6571. {
  6572. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6573. {
  6574. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6575. {
  6576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6577. goto end;
  6578. }
  6579. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6580. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6581. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6582. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6583. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].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.GbChargingData[index].SystemStatus);
  6591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6592. goto end;
  6593. }
  6594. }
  6595. }// END FOR GB_QUANTITY
  6596. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6597. {
  6598. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6599. {
  6600. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6601. {
  6602. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6603. goto end;
  6604. }
  6605. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6606. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6607. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6608. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6609. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.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.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6617. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6618. goto end;
  6619. }
  6620. }
  6621. }// END FOR GENERAL_GUN_QUANTITY
  6622. for (int index = 0; index < AC_QUANTITY; index++)
  6623. {
  6624. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6625. {
  6626. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6627. {
  6628. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6629. goto end;
  6630. }
  6631. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6632. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6633. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6634. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6635. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6636. {
  6637. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6638. goto end;
  6639. }
  6640. else
  6641. {
  6642. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6643. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6644. goto end;
  6645. }
  6646. }
  6647. }//END FOR AC_QUANTITY
  6648. }//END FOR AvailabilityTypeStr[Inoperative]
  6649. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6650. {
  6651. //----------------------gunIndex is 0 ------------------------------------------------//
  6652. if(gunIndex == 0)
  6653. {
  6654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6655. {
  6656. for(int i=0; i < gunTotalNumber; i++)
  6657. {
  6658. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6659. {
  6660. 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
  6661. {
  6662. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6663. goto end;
  6664. }
  6665. }//END FOR CHAdeMO_QUANTITY
  6666. for (int index = 0; index < CCS_QUANTITY; index++)
  6667. {
  6668. 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
  6669. {
  6670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6671. goto end;
  6672. }
  6673. }//END FOR CCS_QUANTITY
  6674. for (int index = 0; index < GB_QUANTITY; index++)
  6675. {
  6676. 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
  6677. {
  6678. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6679. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6680. goto end;
  6681. }
  6682. }// END FOR GB_QUANTITY
  6683. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6684. {
  6685. 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
  6686. {
  6687. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6688. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6689. goto end;
  6690. }
  6691. }// END FOR GENERAL_GUN_QUANTITY
  6692. for (int index = 0; index < AC_QUANTITY; index++)
  6693. {
  6694. 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
  6695. {
  6696. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6697. goto end;
  6698. }
  6699. }//END FOR CHAdeMO_QUANTITY
  6700. }// END FOR gunTotalNumber
  6701. }
  6702. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6703. {
  6704. for(int i=0; i < gunTotalNumber; i++)
  6705. {
  6706. for (int index = 0; index < AC_QUANTITY; index++)
  6707. {
  6708. 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
  6709. {
  6710. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6711. goto end;
  6712. }
  6713. }//END FOR CHAdeMO_QUANTITY
  6714. } // END FOR gunTotalNumber
  6715. }
  6716. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6717. goto end;
  6718. }
  6719. //----------------------gunIndex is not 0 ------------------------------------------------//
  6720. //check Transaction active
  6721. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6722. {
  6723. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6724. {
  6725. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6726. goto end;
  6727. }
  6728. }//END FOR CHAdeMO_QUANTITY
  6729. for (int index = 0; index < CCS_QUANTITY; index++)
  6730. {
  6731. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6732. {
  6733. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6734. goto end;
  6735. }
  6736. }//END FOR CCS_QUANTITY
  6737. for (int index = 0; index < GB_QUANTITY; index++)
  6738. {
  6739. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6740. {
  6741. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6742. goto end;
  6743. }
  6744. }// END FOR GB_QUANTITY
  6745. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6746. {
  6747. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6748. {
  6749. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6750. goto end;
  6751. }
  6752. }// END FOR GENERAL_GUN_QUANTITY
  6753. for (int index = 0; index < AC_QUANTITY; index++)
  6754. {
  6755. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6756. {
  6757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6758. goto end;
  6759. }
  6760. }//END FOR AC_QUANTITY
  6761. }//END FOR AvailabilityTypeStr[Operative]
  6762. end:
  6763. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6764. {
  6765. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6766. }
  6767. else
  6768. {
  6769. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6770. }
  6771. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6772. {
  6773. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6774. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6775. }
  6776. else if(gunIndex == 0)
  6777. {
  6778. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6779. {
  6780. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6781. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6782. }
  6783. }
  6784. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6785. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6786. return result;
  6787. }
  6788. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6789. {
  6790. mtrace();
  6791. int result = FAIL;
  6792. char keystr[40]={0};
  6793. char valuestr[256]={0};
  6794. char comfirmstr[20]={0};
  6795. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6796. json_object *ChangeConfiguration;
  6797. ChangeConfiguration = json_tokener_parse(payload);
  6798. if(!is_error(ChangeConfiguration))
  6799. {
  6800. // Required data
  6801. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6802. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6803. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6804. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6805. }
  6806. json_object_put(ChangeConfiguration);
  6807. if((uuid==NULL) || (payload ==NULL) )
  6808. {
  6809. DEBUG_ERROR("Payload is null\n");
  6810. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6811. }
  6812. else
  6813. {
  6814. int status = setKeyValue(keystr, valuestr);
  6815. switch(status)
  6816. {
  6817. case ConfigurationStatus_Accepted:
  6818. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6819. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  6820. StoreConfigurationTable();
  6821. break;
  6822. case RebootRequired:
  6823. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6824. StoreConfigurationTable();
  6825. break;
  6826. case NotSupported:
  6827. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6828. break;
  6829. case ConfigurationStatus_Rejected:
  6830. default:
  6831. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6832. break;
  6833. }
  6834. }
  6835. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6836. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  6837. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6838. {
  6839. ChageWebSocketPingInterval(atoi(valuestr));
  6840. }
  6841. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  6842. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6843. {
  6844. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  6845. SetOcppConnStatus(FALSE);
  6846. }
  6847. return result;
  6848. }
  6849. int handleClearCacheRequest(char *uuid, char *payload)
  6850. {
  6851. mtrace();
  6852. int result = FAIL;
  6853. char comfirmstr[20];
  6854. char rmFileCmd[100]={0};
  6855. struct stat stats;
  6856. DEBUG_INFO("handleClearCacheRequest...\n");
  6857. stat("/Storage/OCPP_PH", &stats);
  6858. // Check for directory existence
  6859. if (S_ISDIR(stats.st_mode) == 1)
  6860. {}
  6861. else
  6862. {
  6863. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6864. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  6865. system(rmFileCmd);
  6866. }
  6867. if(OCPP_cleanLocalCache())
  6868. {
  6869. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6870. }
  6871. else
  6872. {
  6873. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6874. }
  6875. sendClearCacheConfirmation(uuid, comfirmstr);
  6876. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6877. return result;
  6878. }
  6879. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6880. {
  6881. mtrace();
  6882. int result = FAIL;
  6883. int resultRename;
  6884. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6885. char chargingProfilePurposeStr[26]={0};
  6886. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6887. char tempchargingProfilePurposeStr[26]={0};
  6888. char str[100]={0};
  6889. char fname[200]={0};
  6890. char comfirmstr[20]={0};
  6891. char word[1600]={0};
  6892. int clearflag = FALSE;
  6893. int chargingProfileIdIsNULL = FALSE;
  6894. int connectorIsNULL = FALSE;
  6895. int chargingProfilePurposeIsNULL = FALSE;
  6896. int stackLevelIsNULL = FALSE;
  6897. //int GotoEnd = FALSE;
  6898. FILE *fptr1, *fptr2;
  6899. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  6900. int n_chargingProfile=0;
  6901. int isEmptyFile = FALSE;
  6902. char sLineWord[1600]={0};
  6903. char chargingProfiles[10][100]={0};
  6904. int ChargeProfileCount = 0;
  6905. int ch;
  6906. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6907. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6908. json_object *ClearChargingProfile;
  6909. ClearChargingProfile = json_tokener_parse(payload);
  6910. if(!is_error(ClearChargingProfile))
  6911. {
  6912. // Optional data
  6913. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6914. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6915. else
  6916. chargingProfileIdIsNULL = TRUE;
  6917. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6918. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6919. else
  6920. connectorIsNULL = TRUE;
  6921. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6922. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6923. else
  6924. chargingProfilePurposeIsNULL = TRUE;
  6925. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6926. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6927. else
  6928. stackLevelIsNULL = TRUE;
  6929. }
  6930. json_object_put(ClearChargingProfile);
  6931. if(connectorIsNULL == FALSE)
  6932. {
  6933. switch(connectorIdInt)
  6934. {
  6935. case 0:
  6936. if(chargingProfilePurposeIsNULL == TRUE)
  6937. {
  6938. int l = 0;
  6939. strcpy(fname, ChargePointMaxProfile_JSON);
  6940. if((access(fname,F_OK))!=-1)
  6941. {
  6942. strcpy(chargingProfiles[l], fname);
  6943. l = l + 1;
  6944. }
  6945. strcpy(fname, TxDefaultProfile_0_JSON);
  6946. if((access(fname,F_OK))!=-1)
  6947. {
  6948. strcpy(chargingProfiles[l], fname);
  6949. l = l + 1;
  6950. }
  6951. ChargeProfileCount = l;
  6952. }
  6953. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6954. {
  6955. strcpy(fname, ChargePointMaxProfile_JSON);
  6956. if((access(fname,F_OK))!=-1)
  6957. {
  6958. strcpy(chargingProfiles[0], fname);
  6959. ChargeProfileCount = 1;
  6960. }
  6961. }
  6962. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6963. {
  6964. strcpy(fname, TxDefaultProfile_0_JSON);
  6965. if((access(fname,F_OK))!=-1)
  6966. {
  6967. strcpy(chargingProfiles[0], fname);
  6968. ChargeProfileCount = 1;
  6969. }
  6970. }
  6971. break;
  6972. default:
  6973. if(chargingProfilePurposeIsNULL == TRUE)
  6974. {
  6975. int m = 0;
  6976. memset(fname, 0, ARRAY_SIZE(fname));
  6977. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  6978. if((access(fname,F_OK))!=-1)
  6979. {
  6980. strcpy(chargingProfiles[m], fname);
  6981. m = m + 1;
  6982. }
  6983. memset(fname, 0, ARRAY_SIZE(fname));
  6984. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  6985. if((access(fname,F_OK))!=-1)
  6986. {
  6987. strcpy(chargingProfiles[m], fname);
  6988. m = m + 1;
  6989. }
  6990. ChargeProfileCount = m;
  6991. }
  6992. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6993. {
  6994. //strcpy(fname, TxDefaultProfile_1_JSON);
  6995. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  6996. if((access(fname,F_OK))!=-1)
  6997. {
  6998. strcpy(chargingProfiles[0], fname);
  6999. ChargeProfileCount = 1;
  7000. }
  7001. }
  7002. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7003. {
  7004. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7005. if((access(fname,F_OK))!=-1)
  7006. {
  7007. strcpy(chargingProfiles[0], fname);
  7008. ChargeProfileCount = 1;
  7009. }
  7010. //strcpy(fname, TxProfile_1_JSON);
  7011. }
  7012. //strcpy(fname, ChargePointMaxProfile_JSON );
  7013. break;
  7014. }
  7015. }
  7016. else // Check all Charging Profiles
  7017. {
  7018. int i = 0;
  7019. char fnametemp[200]={0};
  7020. ChargeProfileCount = 0;
  7021. //Check ChargePointMaxProfile.json exit
  7022. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  7023. {
  7024. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  7025. i = i + 1;
  7026. }
  7027. //Check TxDefaultProfile_0.json exit
  7028. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  7029. {
  7030. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  7031. i = i + 1;
  7032. }
  7033. //Check TxDefaultProfile_%d.json
  7034. for(int j=1; j <= gunTotalNumber; j++)
  7035. {
  7036. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7037. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  7038. if((access(fnametemp,F_OK))!=-1)
  7039. {
  7040. strcpy(chargingProfiles[i], fnametemp);
  7041. i = i + 1;
  7042. }
  7043. }
  7044. //Check TxProfile_%d.json
  7045. for(int j=1; j <= gunTotalNumber; j++)
  7046. {
  7047. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7048. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  7049. if((access(fnametemp,F_OK))!=-1)
  7050. {
  7051. strcpy(chargingProfiles[i], fnametemp);
  7052. i = i + 1;
  7053. }
  7054. }
  7055. ChargeProfileCount = i;
  7056. }// End connectorIsNULL is TRUE
  7057. if(ChargeProfileCount == 0)
  7058. {
  7059. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7060. goto end;
  7061. }
  7062. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7063. {
  7064. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7065. goto end;
  7066. }
  7067. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7068. {
  7069. memset(str, 0, ARRAY_SIZE(str));
  7070. // clear temp file
  7071. sprintf(str,"rm -f %s",temp);
  7072. system(str);
  7073. for(int k=0; k < ChargeProfileCount; k++)
  7074. {
  7075. memset(str, 0, ARRAY_SIZE(str));
  7076. //clear file in C
  7077. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7078. system(str);
  7079. }
  7080. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7081. goto end;
  7082. }
  7083. else if(connectorIsNULL == TRUE)
  7084. {
  7085. for(int k=0; k < ChargeProfileCount; k++)
  7086. {
  7087. fptr1 = fopen(chargingProfiles[k], "r");
  7088. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  7089. //Check Charging Profile Count
  7090. while(fscanf(fptr1, "%s", word) != EOF)
  7091. {
  7092. //DEBUG_INFO("word=%s\n",word);
  7093. if(strstr(word, "chargingProfileId")!= NULL)
  7094. {
  7095. //DEBUG_INFO("test chargingProfileId \n");
  7096. n_chargingProfile = n_chargingProfile + 1;
  7097. //DEBUG_INFO("chargingProfileId Found\n");
  7098. }
  7099. }
  7100. rewind(fptr1);
  7101. //search Charging Profile Element
  7102. //int i= 0;
  7103. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7104. {
  7105. json_object *tmpProfilee;
  7106. tmpProfilee = json_tokener_parse(sLineWord);
  7107. if(!is_error(tmpProfilee))
  7108. {
  7109. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7110. {
  7111. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7112. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7113. }
  7114. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7115. {
  7116. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7117. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7118. }
  7119. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7120. {
  7121. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7122. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7123. }
  7124. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7125. {
  7126. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7127. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7128. }
  7129. }
  7130. json_object_put(tmpProfilee);
  7131. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7132. {
  7133. //------- not write to fptr2-------//
  7134. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7135. //clearflag = TRUE;
  7136. }
  7137. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7138. {
  7139. //------- not write to fptr2-------//
  7140. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7141. }
  7142. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7143. {
  7144. //------- not write to fptr2-------//
  7145. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7146. }
  7147. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7148. {
  7149. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7150. }
  7151. else
  7152. {
  7153. fprintf(fptr2, sLineWord);//writing data into file
  7154. }
  7155. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7156. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7157. if(clearflag == TRUE)
  7158. {
  7159. fclose(fptr1);
  7160. fclose(fptr2);
  7161. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7162. system(str);
  7163. // clear temp file
  7164. sprintf(str,"rm -f %s",temp);
  7165. system(str);
  7166. }
  7167. else
  7168. {
  7169. fclose(fptr1);
  7170. fclose(fptr2);
  7171. memset(str, 0, ARRAY_SIZE(str));
  7172. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7173. system(str);
  7174. resultRename = rename(temp, chargingProfiles[k]);
  7175. if(resultRename == 0)
  7176. {
  7177. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7178. }
  7179. else
  7180. {
  7181. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7182. }
  7183. if(comfirmstr[0]== 0)
  7184. {
  7185. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7186. }
  7187. //Check chargingProfile is empty file
  7188. /*------ Read the file ----------------*/
  7189. fptr1=fopen(chargingProfiles[k],"r");
  7190. ch=fgetc(fptr1);
  7191. rewind(fptr1);
  7192. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7193. if(ch!=EOF)
  7194. {
  7195. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7196. {
  7197. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7198. if(sLineWord[0]=='\0')
  7199. {
  7200. isEmptyFile = TRUE;
  7201. break;
  7202. }
  7203. else
  7204. {
  7205. isEmptyFile = FALSE;
  7206. break;
  7207. }
  7208. }
  7209. }
  7210. else
  7211. isEmptyFile = TRUE;
  7212. fclose(fptr1);
  7213. if(isEmptyFile == TRUE)
  7214. {
  7215. memset(str, 0, ARRAY_SIZE(str));
  7216. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7217. system(str);
  7218. }
  7219. }
  7220. }// End of while(int k=0; k < ChargePointCount; k++)
  7221. }
  7222. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7223. {
  7224. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7225. for(int k=0; k < ChargeProfileCount; k++)
  7226. {
  7227. fptr1 = fopen(chargingProfiles[k], "r");
  7228. fptr2 = fopen(temp, "w+");
  7229. //Check Charging Profile Count
  7230. while(fscanf(fptr1, "%s", word) != EOF)
  7231. {
  7232. //DEBUG_INFO("word=%s\n",word);
  7233. if(strstr(word, "chargingProfileId")!= NULL)
  7234. {
  7235. n_chargingProfile = n_chargingProfile + 1;
  7236. }
  7237. }
  7238. rewind(fptr1);
  7239. //search Charging Profile Element
  7240. //int i= 0;
  7241. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7242. {
  7243. json_object *tmpProfilee;
  7244. tmpProfilee = json_tokener_parse(sLineWord);
  7245. if(!is_error(tmpProfilee))
  7246. {
  7247. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7248. {
  7249. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7250. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7251. }
  7252. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7253. {
  7254. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7255. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7256. }
  7257. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7258. {
  7259. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7260. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7261. }
  7262. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7263. {
  7264. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7265. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7266. }
  7267. }
  7268. json_object_put(tmpProfilee);
  7269. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7270. {
  7271. //------- not write to fptr2-------//
  7272. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7273. //clearflag = TRUE;
  7274. }
  7275. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7276. {
  7277. //------- not write to fptr2-------//
  7278. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7279. }
  7280. else if(stackLevelIsNULL == TRUE)
  7281. {
  7282. //Clear Whole File
  7283. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7284. clearflag = TRUE;
  7285. break;
  7286. }
  7287. else
  7288. {
  7289. fprintf(fptr2, sLineWord);//writing data into file
  7290. }
  7291. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7292. }
  7293. if(clearflag == TRUE)
  7294. {
  7295. fclose(fptr1);
  7296. fclose(fptr2);
  7297. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7298. system(str);
  7299. // clear temp file
  7300. sprintf(str,"rm -f %s",temp);
  7301. system(str);
  7302. }
  7303. else
  7304. {
  7305. fclose(fptr1);
  7306. fclose(fptr2);
  7307. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7308. system(str);
  7309. resultRename = rename(temp, chargingProfiles[k]);
  7310. if(resultRename == 0)
  7311. {
  7312. DEBUG_INFO("File ChargingProfile renamed successfully");
  7313. }
  7314. else
  7315. {
  7316. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7317. }
  7318. if(comfirmstr[0]== 0)
  7319. {
  7320. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7321. }
  7322. //Check chargingProfile is empty file
  7323. /*------ Read the file ----------------*/
  7324. fptr1=fopen(chargingProfiles[k],"r");
  7325. ch=fgetc(fptr1);
  7326. rewind(fptr1);
  7327. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7328. if(ch!=EOF)
  7329. {
  7330. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7331. {
  7332. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7333. if(sLineWord[0]=='\0')
  7334. {
  7335. isEmptyFile = TRUE;
  7336. break;
  7337. }
  7338. else
  7339. {
  7340. isEmptyFile = FALSE;
  7341. break;
  7342. }
  7343. }
  7344. }
  7345. else
  7346. isEmptyFile = TRUE;
  7347. fclose(fptr1);
  7348. if(isEmptyFile == TRUE)
  7349. {
  7350. memset(str, 0, ARRAY_SIZE(str));
  7351. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7352. system(str);
  7353. }
  7354. /*------- End of reading ---------------*/
  7355. }
  7356. } // while(int k=0; k < ChargeProfileCount; k++)
  7357. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7358. end:
  7359. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7360. {
  7361. if(connectorIdInt == 0)
  7362. {
  7363. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7364. {
  7365. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  7366. }
  7367. }
  7368. else
  7369. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  7370. }
  7371. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7372. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7373. return result;
  7374. }
  7375. void createFirmwareVersionByDataTransfer(void)
  7376. {
  7377. json_object *FirmwareDataTransfer = json_object_new_object();
  7378. // AC & DC model
  7379. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7380. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7381. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7382. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7383. // DC model
  7384. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7385. {
  7386. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7387. {
  7388. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7389. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7390. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7391. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7392. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7393. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7394. }
  7395. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7396. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7397. {
  7398. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7399. }
  7400. }
  7401. else
  7402. {
  7403. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7404. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7405. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7406. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7407. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7408. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7409. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7410. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7411. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7412. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7413. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7414. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7415. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7416. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7417. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7418. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7419. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7420. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7421. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7422. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7423. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7424. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7425. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7426. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7427. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7428. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7429. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7430. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7431. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7432. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7433. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7434. }
  7435. // 4G model
  7436. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7437. {
  7438. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7439. }
  7440. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7441. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7442. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7443. json_object_put(FirmwareDataTransfer);
  7444. }
  7445. int handleDataTransferRequest(char *uuid, char *payload)
  7446. {
  7447. mtrace();
  7448. json_object *response = json_object_new_object();
  7449. int result = FAIL;
  7450. char tempvendorId[255]={0};
  7451. char tempmessageId[50]={0};
  7452. char tempdata[512]={0};
  7453. char message[2048]={0};
  7454. DEBUG_INFO("handleDataTransferRequest...\n");
  7455. if((uuid != NULL) && (payload != NULL))
  7456. {
  7457. json_object *DataTransfer;
  7458. DataTransfer = json_tokener_parse(payload);
  7459. if(!is_error(DataTransfer))
  7460. {
  7461. // Required data
  7462. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7463. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7464. // Optional data
  7465. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7466. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7467. if(json_object_object_get(DataTransfer, "data") != NULL)
  7468. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7469. result = PASS;
  7470. }
  7471. json_object_put(DataTransfer);
  7472. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7473. {
  7474. // Send all moudle firmware version on EVSE
  7475. createFirmwareVersionByDataTransfer();
  7476. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7477. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  7478. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7479. json_object_put(response);
  7480. }
  7481. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7482. {
  7483. system("/usr/bin/run_tmate_restart.sh &");
  7484. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7485. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7486. json_object_put(response);
  7487. }
  7488. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7489. {
  7490. json_object *data;
  7491. data = json_tokener_parse(tempdata);
  7492. if(!is_error(data))
  7493. {
  7494. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7495. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7496. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7497. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7498. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7499. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7500. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7501. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7502. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7503. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7504. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7505. }
  7506. else
  7507. {
  7508. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7509. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7510. }
  7511. json_object_put(data);
  7512. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7513. json_object_put(response);
  7514. }
  7515. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7516. {
  7517. json_object *data;
  7518. data = json_tokener_parse(tempdata);
  7519. if(!is_error(data))
  7520. {
  7521. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7522. if(json_object_object_get(data, "idToken") != NULL)
  7523. {
  7524. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7525. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7526. }
  7527. if(json_object_object_get(data, "price") != NULL)
  7528. {
  7529. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7530. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7531. }
  7532. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7533. }
  7534. else
  7535. {
  7536. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7537. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7538. }
  7539. json_object_put(data);
  7540. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7541. json_object_put(response);
  7542. }
  7543. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7544. {
  7545. json_object *data;
  7546. data = json_tokener_parse(tempdata);
  7547. if(!is_error(data))
  7548. {
  7549. if(json_object_object_get(data, "txId") != NULL)
  7550. {
  7551. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7552. for(int idx = 0;idx<gunTotalNumber;idx++)
  7553. {
  7554. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7555. {
  7556. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7557. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7558. if(json_object_object_get(data, "description") != NULL)
  7559. {
  7560. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7561. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7562. }
  7563. }
  7564. }
  7565. }
  7566. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7567. }
  7568. else
  7569. {
  7570. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7571. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7572. }
  7573. json_object_put(data);
  7574. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7575. json_object_put(response);
  7576. }
  7577. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7578. {
  7579. json_object *data;
  7580. data = json_tokener_parse(tempdata);
  7581. if(!is_error(data))
  7582. {
  7583. if(json_object_object_get(data, "txId") != NULL)
  7584. {
  7585. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7586. for(int idx = 0;idx<gunTotalNumber;idx++)
  7587. {
  7588. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7589. {
  7590. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7591. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7592. if(json_object_object_get(data, "description") != NULL)
  7593. {
  7594. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7595. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7596. }
  7597. }
  7598. }
  7599. }
  7600. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7601. }
  7602. else
  7603. {
  7604. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7605. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7606. }
  7607. json_object_put(data);
  7608. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7609. json_object_put(response);
  7610. }
  7611. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7612. {
  7613. json_object *data;
  7614. data = json_tokener_parse(tempdata);
  7615. if(!is_error(data))
  7616. {
  7617. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7618. if(json_object_object_get(data, "Content_Type") != NULL)
  7619. {
  7620. 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))
  7621. {
  7622. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7623. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7624. {
  7625. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7626. }
  7627. }
  7628. else
  7629. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7630. }
  7631. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  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_DsiplayLcdPage") != 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, "Page_Index") != NULL)
  7650. {
  7651. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7652. }
  7653. if(json_object_object_get(data, "Duration") != NULL)
  7654. {
  7655. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7656. }
  7657. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7658. }
  7659. else
  7660. {
  7661. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7662. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7663. }
  7664. json_object_put(data);
  7665. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7666. json_object_put(response);
  7667. }
  7668. else
  7669. {
  7670. // Can not find valid message id
  7671. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7672. }
  7673. }
  7674. else
  7675. {
  7676. // Payload is null
  7677. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7678. }
  7679. LWS_Send(message);
  7680. return result;
  7681. }
  7682. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7683. {
  7684. mtrace();
  7685. int result = FAIL;
  7686. int connectorIdInt, durationInt;
  7687. char chargingRateUnitStr[4]={0};
  7688. char comfirmstr[20];
  7689. int confirmPeriods = 0;
  7690. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7691. json_object *GetCompositeSchedule;
  7692. GetCompositeSchedule = json_tokener_parse(payload);
  7693. if(!is_error(GetCompositeSchedule))
  7694. {
  7695. // Required data
  7696. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7697. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7698. else
  7699. connectorIdInt = -1;
  7700. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7701. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7702. else
  7703. durationInt = 86400;
  7704. // Optional data
  7705. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7706. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7707. }
  7708. json_object_put(GetCompositeSchedule);
  7709. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7710. if((connectorIdInt == 0) ||
  7711. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7712. {
  7713. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7714. struct StructChargingProfile tmpProfile[1];
  7715. if(strstr(chargingRateUnitStr, "W") != NULL)
  7716. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7717. else
  7718. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7719. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7720. {
  7721. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7722. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7723. }
  7724. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7725. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7726. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7727. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7728. {
  7729. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7730. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7731. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7732. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7733. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7734. {
  7735. confirmPeriods = idx;
  7736. break;
  7737. }
  7738. }
  7739. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7740. {
  7741. confirmPeriods += 1;
  7742. }
  7743. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7744. }
  7745. else
  7746. {
  7747. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7748. }
  7749. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7750. return result;
  7751. }
  7752. int handleGetConfigurationRequest(char *uuid, char *payload)
  7753. {
  7754. mtrace();
  7755. int result = FAIL;
  7756. int MaxKeySupported = 0;
  7757. int n_keys = 0;
  7758. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7759. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7760. json_object *GetConfiguration;
  7761. GetConfiguration = json_tokener_parse(payload);
  7762. if(!is_error(GetConfiguration))
  7763. {
  7764. // Optional data
  7765. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7766. {
  7767. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7768. {
  7769. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7770. n_keys = idx + 1;
  7771. }
  7772. }
  7773. }
  7774. json_object_put(GetConfiguration);
  7775. UnknownKeynum = 0;
  7776. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7777. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7778. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7779. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7780. if(n_keys != 0)
  7781. {
  7782. for(int i=0;i<n_keys;i++)
  7783. {
  7784. getKeyValue(requestKey[i]);
  7785. }
  7786. }
  7787. else
  7788. {
  7789. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7790. getKeyValue("");
  7791. }
  7792. processUnkownKey();
  7793. sendGetConfigurationConfirmation(uuid);
  7794. return result;
  7795. }
  7796. static char fnamePlusPath[100]={0};
  7797. static char fnamePWithNoPath[60]={0};
  7798. void checkUploadLog(void)
  7799. {
  7800. FILE *fp;
  7801. /* Open the command for reading. */
  7802. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7803. if (fp == NULL) {
  7804. printf("Failed to run command\n" );
  7805. exit(1);
  7806. }
  7807. int ftppathlen = 0;
  7808. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7809. int i = 0;
  7810. /* Read the output a line at a time - output it. */
  7811. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7812. if(i==0)
  7813. {
  7814. ftppathlen = strlen(fnamePlusPath);
  7815. printf("%s\n", fnamePlusPath);
  7816. fnamePlusPath[ftppathlen]='\0';
  7817. break;
  7818. }
  7819. i= i+1;
  7820. }
  7821. /* close */
  7822. pclose(fp);
  7823. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7824. {
  7825. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7826. {
  7827. fnamePlusPath[k]='\0';
  7828. }
  7829. }
  7830. i=1;
  7831. //char fname[60]={0};
  7832. while(i < ftppathlen)
  7833. {
  7834. int len=ftppathlen-i;
  7835. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7836. {
  7837. printf("compare '/' all right\n");
  7838. break;
  7839. }
  7840. i=i+1;
  7841. }
  7842. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7843. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7844. fnamePWithNoPath[i+1] = '\0';
  7845. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7846. {
  7847. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7848. {
  7849. fnamePWithNoPath[j]='\0';
  7850. }
  7851. }
  7852. FILE* fp1 = fopen(fnamePlusPath, "r");
  7853. if (fp1)
  7854. {
  7855. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7856. // file exists
  7857. fclose(fp1);
  7858. }
  7859. else
  7860. {
  7861. // file doesn't exist
  7862. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7863. }
  7864. }
  7865. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7866. {
  7867. mtrace();
  7868. int result = FAIL;
  7869. time_t CurrentTime;
  7870. struct tm *tm;
  7871. pthread_t th_Status;
  7872. CurrentTime = time(NULL);
  7873. tm = localtime(&CurrentTime);
  7874. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  7875. sprintf((char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  7876. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  7877. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7878. return result;
  7879. }
  7880. void* GetDiagnosticsProcess(void* data)
  7881. {
  7882. pthread_detach(pthread_self());
  7883. mtrace();
  7884. int retriesInt=0, retryIntervalInt=0;
  7885. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7886. char protocol[10]={0}, user[64]={0},password[128]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  7887. int port=0;
  7888. int isSuccess = FALSE;
  7889. char ftpbuf[200]={0};
  7890. char cmdBuf[2048];
  7891. struct tm *tmNow;
  7892. time_t CurrentTime;
  7893. struct tm tmStart;
  7894. struct tm tmStop;
  7895. CurrentTime = time(NULL);
  7896. tmNow=localtime(&CurrentTime);
  7897. uint16_t targetYear, targetMonth;
  7898. json_object *GetDiagnostics;
  7899. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7900. GetDiagnostics = json_tokener_parse(data);
  7901. if(!is_error(GetDiagnostics))
  7902. {
  7903. // Required data
  7904. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7905. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7906. // Optional data
  7907. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7908. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7909. else
  7910. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7911. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7912. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7913. else
  7914. retryIntervalInt = 30;
  7915. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7916. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7917. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7918. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7919. }
  7920. json_object_put(GetDiagnostics);
  7921. // Pack log to compress file
  7922. 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) &&
  7923. (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))
  7924. {
  7925. // Pack system log
  7926. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7927. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7928. targetYear = tmStart.tm_year;
  7929. targetMonth = tmStart.tm_mon;
  7930. do
  7931. {
  7932. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7933. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7934. if(targetMonth+1>=13)
  7935. {
  7936. targetYear += 1;
  7937. targetMonth = 1;
  7938. }
  7939. else
  7940. {
  7941. targetMonth += 1;
  7942. }
  7943. }while((targetYear < (tmNow->tm_year+1900)) ||
  7944. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7945. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7946. system(cmdBuf);
  7947. // Pack charging & event log
  7948. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7949. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7950. targetYear = tmStart.tm_year;
  7951. targetMonth = tmStart.tm_mon;
  7952. do
  7953. {
  7954. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7955. if(targetMonth+1>=13)
  7956. {
  7957. targetYear += 1;
  7958. targetMonth = 1;
  7959. }
  7960. else
  7961. {
  7962. targetMonth += 1;
  7963. }
  7964. }while((targetYear < (tmNow->tm_year+1900)) ||
  7965. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7966. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7967. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7968. system(cmdBuf);
  7969. // Combine log file
  7970. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7971. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7972. }
  7973. else
  7974. {
  7975. system("exec /root/logPackTools 'log' 6");
  7976. }
  7977. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  7978. system(cmdBuf);
  7979. checkUploadLog();
  7980. //****************location*******************/
  7981. if(strcmp(locationstr,"")==0)
  7982. {
  7983. DEBUG_INFO("location is <Empty>!\n");
  7984. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7985. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7986. goto end;
  7987. }
  7988. memset(protocol, 0, ARRAY_SIZE(protocol));
  7989. memset(user, 0, ARRAY_SIZE(user) );
  7990. memset(password, 0, ARRAY_SIZE(password));
  7991. memset(host, 0, ARRAY_SIZE(host));
  7992. memset(path, 0, ARRAY_SIZE(path));
  7993. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7994. memset(host1, 0, ARRAY_SIZE(host1));
  7995. memset(path1, 0, ARRAY_SIZE(path1));
  7996. /*location: ftp://user:password@host:port/path*/
  7997. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7998. if((access(fnamePlusPath,F_OK))!=-1)
  7999. {
  8000. DEBUG_INFO("fnamePlusPath exist.\n");
  8001. }
  8002. else
  8003. {
  8004. DEBUG_INFO("fnamePlusPath not exist!\n");
  8005. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8006. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8007. goto end;
  8008. }
  8009. if(strchr(locationstr,'@')==NULL)
  8010. {
  8011. sscanf(locationstr,
  8012. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8013. protocol, host, &port, path);
  8014. strcpy(user,"anonymous");
  8015. strcpy(password,"");
  8016. }
  8017. else
  8018. {
  8019. //DEBUG_INFO("pch=%s\n", pch);
  8020. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8021. protocol, user, password, host, &port, path);
  8022. }
  8023. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8024. {
  8025. DEBUG_INFO("protocol is not ftp/http ! \n");
  8026. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8027. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8028. goto end;
  8029. }
  8030. if(strncmp(locationstr,"http", 4) == 0)
  8031. {
  8032. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8033. sprintf(ftppath,"/%s", path);
  8034. do
  8035. {
  8036. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8037. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8038. sleep(3);
  8039. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8040. if(!isSuccess)
  8041. {
  8042. DEBUG_INFO("Diagnostics fail.\n");
  8043. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8044. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8045. sleep(retryIntervalInt);
  8046. }
  8047. else
  8048. {
  8049. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8050. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8051. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8052. }
  8053. retriesInt--;
  8054. }while((isSuccess == 0)&&(retriesInt >= 0));
  8055. }
  8056. else
  8057. {
  8058. sscanf(host,"%[^/]%s",host1, path1);
  8059. if(strlen(path) > 0)
  8060. sprintf(ftppath,"/%s", path);
  8061. else
  8062. sprintf(ftppath,"/%s", path1);
  8063. int ftppathlen=strlen(ftppath);
  8064. int i=1;
  8065. char filenametemp[50];
  8066. while(i < ftppathlen)
  8067. {
  8068. int len=ftppathlen-i;
  8069. if(ftppath[len]== 47) // '/' ascll code: 47
  8070. {
  8071. DEBUG_INFO("find '/' all right\n");
  8072. break;
  8073. }
  8074. i=i+1;
  8075. }
  8076. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8077. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8078. filenametemp[i+1] = 0;
  8079. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  8080. if(port == 0)
  8081. port = 21;
  8082. do
  8083. {
  8084. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8085. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8086. sleep(3);
  8087. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8088. if(!isSuccess)
  8089. {
  8090. DEBUG_INFO("Diagnostics fail.\n");
  8091. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8092. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8093. sleep(retryIntervalInt);
  8094. }
  8095. else
  8096. {
  8097. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8098. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8099. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8100. }
  8101. retriesInt--;
  8102. }while((!isSuccess)&&(retriesInt >= 0));
  8103. }
  8104. end:
  8105. system("rm -f /mnt/*");
  8106. sleep(5);
  8107. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8108. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8109. pthread_exit(NULL);
  8110. }
  8111. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8112. {
  8113. mtrace();
  8114. int result = FAIL;
  8115. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8116. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8117. {
  8118. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8119. localversion = -1;
  8120. }
  8121. else
  8122. {
  8123. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8124. OCPP_getListVerion();
  8125. }
  8126. //from db.OCPP_getListVerion
  8127. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = localversion;
  8128. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  8129. sendGetLocalListVersionConfirmation(uuid,"");
  8130. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  8131. return result;
  8132. }
  8133. int handleRemoteStartRequest(char *uuid, char *payload)
  8134. {
  8135. mtrace();
  8136. int result = FAIL;
  8137. int connectorIdInt=0;
  8138. int tempIndex = 0;
  8139. int connectorIdIsNULL, chargingProfileIsNULL;
  8140. char comfirmstr[20]={0};
  8141. char cmdBuf[512];
  8142. json_object *RemoteStartTransaction;
  8143. FILE *fp;
  8144. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8145. if(server_pending == TRUE)
  8146. {
  8147. return 0;
  8148. }
  8149. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8150. RemoteStartTransaction = json_tokener_parse(payload);
  8151. if(!is_error(RemoteStartTransaction))
  8152. {
  8153. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8154. {
  8155. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8156. if(connectorIdInt <= gunTotalNumber)
  8157. {
  8158. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8159. // Required data
  8160. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8161. // Optional data
  8162. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8163. {
  8164. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8165. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8166. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8167. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8168. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8169. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8170. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8171. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8172. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8173. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8174. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8175. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8176. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8177. {
  8178. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  8179. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8180. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  8181. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8182. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  8183. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8184. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  8185. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8186. {
  8187. 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++)
  8188. {
  8189. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  8190. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  8191. 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)
  8192. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  8193. }
  8194. }
  8195. }
  8196. }
  8197. else
  8198. chargingProfileIsNULL = TRUE;
  8199. }
  8200. }
  8201. else
  8202. connectorIdIsNULL = TRUE;
  8203. }
  8204. else
  8205. connectorIdIsNULL = TRUE;
  8206. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8207. {
  8208. DEBUG_WARN("Connector id is NULL\n.");
  8209. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8210. goto end;
  8211. }
  8212. /*
  8213. enum _SYSTEM_STATUS
  8214. {
  8215. S_BOOTING = 0,
  8216. S_IDLE, = 1
  8217. S_AUTHORIZING, = 2
  8218. S_REASSIGN_CHECK, = 3
  8219. S_REASSIGN, = 4
  8220. S_PRECHARGE, = 5
  8221. S_PREPARING_FOR_EV, = 6
  8222. S_PREPARING_FOR_EVSE, = 7
  8223. S_CHARGING, = 8
  8224. S_TERMINATING, = 9
  8225. S_COMPLETE, = 10
  8226. S_ALARM, = 11
  8227. S_FAULT = 12
  8228. }
  8229. */
  8230. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8231. {
  8232. //check Transaction active
  8233. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8234. {
  8235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8236. {
  8237. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8238. }
  8239. else
  8240. {
  8241. tempIndex = connectorIdInt -1;
  8242. }
  8243. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8244. {
  8245. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8246. {
  8247. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8248. {
  8249. //Reserved
  8250. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8251. }
  8252. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8253. {
  8254. //Reserved
  8255. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8256. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8257. goto end;
  8258. }
  8259. else
  8260. {
  8261. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8262. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8263. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8264. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8265. {
  8266. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8267. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8268. goto end;
  8269. }
  8270. }//END FOR ELSE
  8271. }
  8272. }// END FOR CHAdeMO_QUANTITY
  8273. }
  8274. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8275. {
  8276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8277. {
  8278. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8279. }
  8280. else
  8281. {
  8282. tempIndex = connectorIdInt -1;
  8283. }
  8284. for (int index = 0; index < CCS_QUANTITY; index++)
  8285. {
  8286. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8287. {
  8288. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8289. {
  8290. //Reserved
  8291. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8292. }
  8293. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8294. {
  8295. //Reserved
  8296. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8297. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8298. goto end;
  8299. }
  8300. else
  8301. {
  8302. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8303. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8304. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8305. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8306. {
  8307. DEBUG_WARN("CCS connector not allow start\n.");
  8308. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8309. goto end;
  8310. }
  8311. }// END FOR ELSE
  8312. }
  8313. }// END FOR CCS_QUANTITY
  8314. }
  8315. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8316. {
  8317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8318. {
  8319. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8320. }
  8321. else
  8322. {
  8323. tempIndex = connectorIdInt -1;
  8324. }
  8325. for (int index = 0; index < GB_QUANTITY; index++)
  8326. {
  8327. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8328. {
  8329. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8330. {
  8331. //Reserved
  8332. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8333. }
  8334. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8335. {
  8336. //Reserved
  8337. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8338. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8339. goto end;
  8340. }
  8341. else
  8342. {
  8343. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8344. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8345. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8346. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8347. {
  8348. DEBUG_WARN("GB connector not allow start\n.");
  8349. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8350. goto end;
  8351. }
  8352. }// END FOR ELSE
  8353. }
  8354. } // END FOR GB_QUANTITY
  8355. }
  8356. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8357. {
  8358. tempIndex = connectorIdInt -1;
  8359. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8360. {
  8361. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8362. {
  8363. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8364. {
  8365. //Reserved
  8366. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8367. }
  8368. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8369. {
  8370. //Reserved
  8371. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8372. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8373. goto end;
  8374. }
  8375. else
  8376. {
  8377. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8378. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8379. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8380. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8381. {
  8382. DEBUG_WARN("GB connector not allow start\n.");
  8383. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8384. goto end;
  8385. }
  8386. }// END FOR ELSE
  8387. }
  8388. } // END FOR GB_QUANTITY
  8389. }
  8390. else
  8391. {
  8392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8393. {
  8394. tempIndex = 2;
  8395. }
  8396. else
  8397. {
  8398. tempIndex = connectorIdInt -1;
  8399. }
  8400. for (int index = 0; index < AC_QUANTITY; index++)
  8401. {
  8402. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8403. {
  8404. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8405. {
  8406. //Reserved
  8407. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8408. }
  8409. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8410. {
  8411. //Reserved
  8412. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8413. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8414. goto end;
  8415. }
  8416. else
  8417. {
  8418. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8419. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8420. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8421. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8422. {
  8423. DEBUG_WARN("AC connector not allow start\n.");
  8424. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8425. goto end;
  8426. }
  8427. }//END FOR ELSE
  8428. }
  8429. }// END FOR AC_QUANTITY
  8430. }
  8431. if(chargingProfileIsNULL == FALSE)
  8432. {
  8433. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8434. {
  8435. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8436. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8437. //memset idTag
  8438. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8439. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8440. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8441. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8442. // Save profile to file
  8443. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8444. system(cmdBuf);
  8445. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8446. fp = fopen(cmdBuf, "w");
  8447. 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));
  8448. fclose(fp);
  8449. }
  8450. else
  8451. {
  8452. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8453. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8454. }
  8455. }
  8456. else
  8457. {
  8458. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8459. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8460. //memset idTag
  8461. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8462. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8463. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8465. }
  8466. }
  8467. else
  8468. {
  8469. DEBUG_WARN("Connector id over\n.");
  8470. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8471. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8472. }
  8473. end:
  8474. json_object_put(RemoteStartTransaction);
  8475. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8476. {
  8477. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8478. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8479. }
  8480. //OCPP send RemoteStartConfirmation by first.
  8481. sendRemoteStartConfirmation(uuid, comfirmstr);
  8482. return result;
  8483. }
  8484. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8485. {
  8486. mtrace();
  8487. int result = FAIL;
  8488. int match = FALSE;
  8489. int GunNO = 0;
  8490. int tempIndex = 0;
  8491. int transactionIdInt=0;
  8492. int transactionIdIsNULL= TRUE;
  8493. char comfirmstr[20];
  8494. json_object *RemoteStopTransaction;
  8495. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8496. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8497. if(server_pending == TRUE)
  8498. {
  8499. return 0;
  8500. }
  8501. RemoteStopTransaction = json_tokener_parse(payload);
  8502. if(!is_error(RemoteStopTransaction))
  8503. {
  8504. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8505. {
  8506. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8507. transactionIdIsNULL = FALSE;
  8508. }
  8509. }
  8510. json_object_put(RemoteStopTransaction);
  8511. if(transactionIdIsNULL == FALSE)
  8512. {
  8513. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8514. {
  8515. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8516. {
  8517. //check Transaction active
  8518. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8519. {
  8520. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8521. {
  8522. tempIndex = ((gun_index==2) ? 1: 0);
  8523. }
  8524. else
  8525. {
  8526. tempIndex = gun_index;
  8527. }
  8528. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8529. {
  8530. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8531. {
  8532. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8533. {
  8534. match = TRUE;
  8535. GunNO = gun_index;
  8536. }
  8537. }
  8538. }// END FOR CHAdeMO_QUANTITY
  8539. }
  8540. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8541. {
  8542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8543. {
  8544. tempIndex = ((gun_index==2) ? 1: 0);
  8545. }
  8546. else
  8547. {
  8548. tempIndex = gun_index;
  8549. }
  8550. for (int index = 0; index < CCS_QUANTITY; index++)
  8551. {
  8552. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8553. {
  8554. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8555. {
  8556. match = TRUE;
  8557. GunNO = gun_index;
  8558. }
  8559. }
  8560. }// END FOR CCS_QUANTITY
  8561. }
  8562. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8563. {
  8564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8565. {
  8566. tempIndex = ((gun_index==2) ? 1: 0);
  8567. }
  8568. else
  8569. {
  8570. tempIndex = gun_index;
  8571. }
  8572. for (int index = 0; index < GB_QUANTITY; index++)
  8573. {
  8574. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8575. {
  8576. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8577. {
  8578. match = TRUE;
  8579. GunNO = gun_index;
  8580. }
  8581. }
  8582. }// END FOR GB_QUANTITY
  8583. }
  8584. else if(gunType[gun_index] == GUN_TYPE_DO)
  8585. {
  8586. tempIndex = gun_index;
  8587. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8588. {
  8589. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8590. {
  8591. 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
  8592. {
  8593. match = TRUE;
  8594. GunNO = gun_index;
  8595. }
  8596. }
  8597. }// END FOR GB_QUANTITY
  8598. }
  8599. else
  8600. {
  8601. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8602. {
  8603. tempIndex = 2;
  8604. }
  8605. else
  8606. {
  8607. tempIndex = gun_index;
  8608. }
  8609. for (int index = 0; index < AC_QUANTITY; index++)
  8610. {
  8611. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8612. {
  8613. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8614. {
  8615. match = TRUE;
  8616. GunNO = gun_index;
  8617. }
  8618. }
  8619. }// END FOR CHAdeMO_QUANTITY
  8620. } // END FOR AC ELSE
  8621. }// CHECK IF ResponseTransactionId == transactionIdInt
  8622. }//END FOR
  8623. if( match == TRUE)
  8624. {
  8625. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8626. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8627. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8628. }
  8629. else
  8630. {
  8631. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8632. }
  8633. }
  8634. else
  8635. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8636. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8637. return result;
  8638. }
  8639. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8640. {
  8641. mtrace();
  8642. int result = FAIL;
  8643. int connectorIdInt=0, reservationIdInt=0;
  8644. int tempIndex = 0;
  8645. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8646. char comfirmstr[20]={0};
  8647. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8648. int c = 0;
  8649. char *loc;
  8650. //char *ptr;
  8651. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8652. strcpy(sstrtemp, stringtrimspace(payload));
  8653. //***(1)connectorId ****/
  8654. c=0;
  8655. loc = strstr(sstrtemp, "connectorId");
  8656. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8657. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8658. {
  8659. sstr[c] = loc[strlen("connectorId")+2+c];
  8660. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8661. c++;
  8662. }
  8663. sstr[c] = '\0';
  8664. connectorIdInt = atoi(sstr);
  8665. //***(2)expiryDate ****/
  8666. loc = strstr(sstrtemp, "expiryDate");
  8667. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8668. c = 0;
  8669. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8670. {
  8671. sstr[c] = loc[3+strlen("expiryDate")+c];
  8672. c++;
  8673. }
  8674. sstr[c] = '\0';
  8675. strcpy(expiryDatestr, sstr);
  8676. //***(3)idTag ****/
  8677. loc = strstr(sstrtemp, "idTag");
  8678. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8679. c = 0;
  8680. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8681. {
  8682. sstr[c] = loc[3+strlen("idTag")+c];
  8683. c++;
  8684. }
  8685. sstr[c] = '\0';
  8686. strcpy(idTagstr, sstr);
  8687. //***(4)parentIdTag ****/
  8688. loc = strstr(sstrtemp, "parentIdTag");
  8689. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8690. c = 0;
  8691. if(loc == NULL)
  8692. {
  8693. strcpy(parentIdTagstr, "");
  8694. }
  8695. else
  8696. {
  8697. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8698. {
  8699. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8700. c++;
  8701. }
  8702. sstr[c] = '\0';
  8703. strcpy(parentIdTagstr, sstr);
  8704. }
  8705. //***(5)reservationId ****/
  8706. c=0;
  8707. loc = strstr(sstrtemp, "reservationId");
  8708. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8709. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8710. {
  8711. sstr[c] = loc[strlen("reservationId")+2+c];
  8712. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8713. c++;
  8714. }
  8715. sstr[c] = '\0';
  8716. reservationIdInt = atoi(sstr);
  8717. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8718. /*
  8719. enum SYSTEM_STATUS
  8720. {
  8721. SYS_MODE_BOOTING = 0,
  8722. SYS_MODE_IDLE = 1,
  8723. SYS_MODE_AUTHORIZING = 2,
  8724. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8725. SYS_MODE_REASSIGN = 4,
  8726. SYS_MODE_PREPARING = 5,
  8727. SYS_MODE_PREPARE_FOR_EV = 6,
  8728. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8729. SYS_MODE_CHARGING = 8,
  8730. SYS_MODE_TERMINATING = 9,
  8731. SYS_MODE_COMPLETE = 10,
  8732. SYS_MODE_ALARM = 11,
  8733. SYS_MODE_FAULT = 12,
  8734. SYS_MODE_RESERVATION = 13,
  8735. SYS_MODE_BOOKING = 14,
  8736. SYS_MODE_MAINTAIN = 15,
  8737. SYS_MODE_DEBUG = 16,
  8738. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8739. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8740. SYS_MODE_UPDATE = 19
  8741. };
  8742. */
  8743. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8744. {
  8745. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8746. goto end;
  8747. }
  8748. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8749. {
  8750. //check Transaction active
  8751. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8752. {
  8753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8754. {
  8755. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8756. }
  8757. else
  8758. {
  8759. tempIndex = connectorIdInt -1;
  8760. }
  8761. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8762. {
  8763. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8764. {
  8765. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8766. {
  8767. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8768. {
  8769. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8770. {
  8771. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8773. }
  8774. 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'))
  8775. {
  8776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8777. }
  8778. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8779. {
  8780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8781. }
  8782. else
  8783. {
  8784. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8785. }
  8786. }
  8787. 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
  8788. {
  8789. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8790. }
  8791. }
  8792. else
  8793. {
  8794. //replace reservation
  8795. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8796. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8797. }
  8798. }
  8799. } // END FOR CHAdeMO_QUANTITY
  8800. }
  8801. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8802. {
  8803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8804. {
  8805. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8806. }
  8807. else
  8808. {
  8809. tempIndex = connectorIdInt -1;
  8810. }
  8811. for (int index = 0; index < CCS_QUANTITY; index++)
  8812. {
  8813. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8814. {
  8815. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8816. {
  8817. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8818. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8819. {
  8820. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8821. {
  8822. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8823. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8824. }
  8825. 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'))
  8826. {
  8827. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8828. }
  8829. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8830. {
  8831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8832. }
  8833. else
  8834. {
  8835. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8836. }
  8837. }
  8838. 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
  8839. {
  8840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8841. }
  8842. }
  8843. else
  8844. {
  8845. //replace reservation
  8846. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8847. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8848. }
  8849. }
  8850. } // END FOR CCS_QUANTITY
  8851. }
  8852. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8853. {
  8854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8855. {
  8856. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8857. }
  8858. else
  8859. {
  8860. tempIndex = connectorIdInt -1;
  8861. }
  8862. for (int index = 0; index < GB_QUANTITY; index++)
  8863. {
  8864. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8865. {
  8866. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8867. {
  8868. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8869. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8870. {
  8871. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8872. {
  8873. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8874. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8875. }
  8876. 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'))
  8877. {
  8878. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8879. }
  8880. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8881. {
  8882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8883. }
  8884. else
  8885. {
  8886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8887. }
  8888. }
  8889. 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
  8890. {
  8891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8892. }
  8893. }
  8894. else
  8895. {
  8896. //replace reservation
  8897. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8898. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8899. }
  8900. }
  8901. }// END FOR GB_QUANTITY
  8902. }
  8903. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8904. {
  8905. tempIndex = connectorIdInt -1;
  8906. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8907. {
  8908. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8909. {
  8910. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8911. {
  8912. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8913. 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
  8914. {
  8915. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8916. {
  8917. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8918. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8919. }
  8920. 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'))
  8921. {
  8922. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8923. }
  8924. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8925. {
  8926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8927. }
  8928. else
  8929. {
  8930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8931. }
  8932. }
  8933. 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
  8934. {
  8935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8936. }
  8937. }
  8938. else
  8939. {
  8940. //replace reservation
  8941. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8943. }
  8944. }
  8945. }// END FOR GB_QUANTITY
  8946. }
  8947. else
  8948. {
  8949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8950. {
  8951. tempIndex = 2;
  8952. }
  8953. else
  8954. {
  8955. tempIndex = (connectorIdInt -1);
  8956. }
  8957. for (int index = 0; index < AC_QUANTITY; index++)
  8958. {
  8959. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8960. {
  8961. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8962. {
  8963. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8964. {
  8965. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8966. {
  8967. 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))
  8968. {
  8969. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8970. }
  8971. else
  8972. {
  8973. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8975. }
  8976. }
  8977. 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'))
  8978. {
  8979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8980. }
  8981. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8982. {
  8983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8984. }
  8985. else
  8986. {
  8987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8988. }
  8989. }
  8990. 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
  8991. {
  8992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8993. }
  8994. }
  8995. else
  8996. {
  8997. //replace reservation
  8998. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9000. }
  9001. }
  9002. } // END FOR AC_QUANTITY
  9003. }
  9004. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9005. }
  9006. else if(connectorIdInt == 0)
  9007. {
  9008. //check Transaction active
  9009. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9010. {
  9011. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9012. {
  9013. 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'))
  9014. {
  9015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9016. goto end;
  9017. }
  9018. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9019. {
  9020. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9021. goto end;
  9022. }
  9023. 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
  9024. {
  9025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9026. goto end;
  9027. }
  9028. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9029. {
  9030. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9031. goto end;
  9032. }
  9033. }
  9034. }// END FOR CHAdeMO_QUANTITY
  9035. for (int index = 0; index < CCS_QUANTITY; index++)
  9036. {
  9037. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9038. {
  9039. 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'))
  9040. {
  9041. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9042. goto end;
  9043. }
  9044. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9045. {
  9046. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9047. goto end;
  9048. }
  9049. 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
  9050. {
  9051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9052. goto end;
  9053. }
  9054. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9055. {
  9056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9057. goto end;
  9058. }
  9059. }
  9060. } // END FOR CCS_QUANTITY
  9061. for (int index = 0; index < GB_QUANTITY; index++)
  9062. {
  9063. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9064. {
  9065. 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'))
  9066. {
  9067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9068. goto end;
  9069. }
  9070. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9071. {
  9072. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9073. goto end;
  9074. }
  9075. 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
  9076. {
  9077. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9078. goto end;
  9079. }
  9080. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9081. {
  9082. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9083. goto end;
  9084. }
  9085. }
  9086. } // END FOR GB_QUANTITY
  9087. for (int index = 0; index < AC_QUANTITY; index++)
  9088. {
  9089. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9090. {
  9091. 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'))
  9092. {
  9093. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9094. goto end;
  9095. }
  9096. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9097. {
  9098. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9099. goto end;
  9100. }
  9101. 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
  9102. {
  9103. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9104. goto end;
  9105. }
  9106. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9107. {
  9108. 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))
  9109. {
  9110. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9111. goto end;
  9112. }
  9113. }
  9114. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9115. {
  9116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9117. goto end;
  9118. }
  9119. }
  9120. }// END FOR AC_QUANTITY
  9121. //The connectorId is 0
  9122. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  9123. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9124. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9125. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  9126. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9127. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  9128. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9129. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  9130. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  9131. result = TRUE;
  9132. return result;
  9133. }
  9134. else
  9135. {
  9136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9137. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9138. }
  9139. if(strcmp(comfirmstr,"Accepted") == 0)
  9140. {
  9141. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9142. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9143. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9144. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9145. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9146. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  9147. result = TRUE;
  9148. return result;
  9149. }
  9150. end:
  9151. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9152. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9153. return result;
  9154. }
  9155. int handleResetRequest(char *uuid, char *payload)
  9156. {
  9157. mtrace();
  9158. int result = FAIL;
  9159. char sstr[10]={0},sstrtemp[30]={ 0 };
  9160. char typestr[10]={0};
  9161. char comfirmstr[20]={0};
  9162. int c = 0;
  9163. char *loc;
  9164. DEBUG_INFO("handleResetRequest...\n");
  9165. strcpy(sstrtemp, stringtrimspace(payload));
  9166. loc = strstr(sstrtemp, "type");
  9167. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9168. c = 0;
  9169. while (loc[3+strlen("type")+c] != '\"')
  9170. {
  9171. sstr[c] = loc[3+strlen("type")+c];
  9172. c++;
  9173. }
  9174. sstr[c] = '\0';
  9175. strcpy(typestr,sstr);
  9176. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  9177. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9178. {
  9179. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  9180. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  9181. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9182. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9183. }
  9184. else
  9185. {
  9186. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9187. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9188. result = PASS;
  9189. }
  9190. sendResetConfirmation(uuid, comfirmstr);
  9191. return result;
  9192. }
  9193. int handleSendLocalListRequest(char *uuid, char *payload)
  9194. {
  9195. mtrace();
  9196. int result = FAIL;
  9197. int listVersionInt;
  9198. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9199. char listsearch[]="listVersion";
  9200. char updateTypesearch[]="updateType";
  9201. char localAuthorizationListsearch[]="localAuthorizationList";
  9202. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9203. char CardList[500][160]={0};
  9204. char updateTypestr[15]={0};
  9205. char idTagstr[20]={0};
  9206. char parentIdTag[20]={0};
  9207. char expiryDate[30]={0};
  9208. char idTagstatus[16]={0};
  9209. int c = 0;
  9210. int i = 0;
  9211. char *delim1 = "}";
  9212. char * pch;
  9213. char *loc;
  9214. //char *ptr;
  9215. char comfirmstr[20];
  9216. //int n_localAuthorizations = 0;
  9217. int checkState_Faulted = FALSE;
  9218. DEBUG_INFO("handleSendLocalListRequest...\n");
  9219. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9220. {
  9221. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9222. goto end;
  9223. }
  9224. //check Charge Point state
  9225. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9226. {
  9227. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9228. {
  9229. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9230. }
  9231. }
  9232. for (int index = 0; index < CCS_QUANTITY; index++)
  9233. {
  9234. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9235. {
  9236. checkState_Faulted = TRUE; //OCPP Status
  9237. }
  9238. }
  9239. for (int index = 0; index < GB_QUANTITY; index++)
  9240. {
  9241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9242. {
  9243. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9244. }
  9245. }
  9246. //check Charge Point state
  9247. for (int index = 0; index < AC_QUANTITY; index++)
  9248. {
  9249. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9250. {
  9251. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9252. }
  9253. }
  9254. if(checkState_Faulted == TRUE)
  9255. {
  9256. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9257. goto end;
  9258. }
  9259. //Filter payload space
  9260. strcpy(sstrtemp, stringtrimspace(payload));
  9261. //listVersion
  9262. c = 0;
  9263. loc = strstr(sstrtemp, listsearch);
  9264. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9265. {
  9266. sstr[c] = loc[strlen("listVersion")+2+c];
  9267. c++;
  9268. }
  9269. sstr[c] = '\0';
  9270. listVersionInt = atoi(sstr);
  9271. ShmOCPP16DataPH->SendLocalList.ListVersion = listVersionInt;
  9272. //updateType
  9273. loc = strstr(sstrtemp, updateTypesearch);
  9274. c = 0;
  9275. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9276. {
  9277. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9278. c++;
  9279. }
  9280. sstr[c] = '\0';
  9281. strcpy(updateTypestr, sstr);
  9282. sprintf((char *)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", updateTypestr);
  9283. //localAuthorizationList
  9284. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9285. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9286. if(loc != NULL) // localAuthorizationList is not NULL
  9287. {
  9288. //Check UpdateType
  9289. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9290. {
  9291. //Local list full update
  9292. printf("Local list full update.\n");
  9293. OCPP_getListVerion();
  9294. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9295. {
  9296. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9297. goto end;
  9298. }
  9299. OCPP_cleanLocalList();
  9300. }
  9301. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9302. {
  9303. //Local list different update
  9304. printf("Local list different update.\n");
  9305. OCPP_getListVerion();
  9306. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9307. {
  9308. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9309. goto end;
  9310. }
  9311. }
  9312. else
  9313. {
  9314. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9315. goto end;
  9316. }
  9317. c = 0;
  9318. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9319. {
  9320. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9321. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9322. c++;
  9323. }
  9324. sstr[c] = '\0';
  9325. //DEBUG_INFO("sstr=%s\n", sstr);
  9326. //parsing strings to words
  9327. i = 0;
  9328. pch = strtok(sstr,delim1);
  9329. while (pch != NULL)
  9330. {
  9331. strcpy(CardList[i], pch);
  9332. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9333. pch = strtok (NULL, delim1);
  9334. i = i + 1;
  9335. }
  9336. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9337. //local Authorizations List Numbers
  9338. //n_localAuthorizations = i;
  9339. ShmOCPP16DataPH->SendLocalList.ListVersion = listVersionInt;
  9340. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9341. c= 0;
  9342. while(c < i) // i is CardList Number
  9343. {
  9344. //Search "IdToken"
  9345. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9346. loc = strstr(CardList[c], "idTag");
  9347. int j = 0;
  9348. while (loc[3+strlen("idTag")+j] != '\"')
  9349. {
  9350. sstr[j] = loc[3+strlen("idTag")+j];
  9351. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9352. j++;
  9353. }
  9354. sstr[j] = '\0';
  9355. strcpy(idTagstr, sstr);
  9356. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9357. //Search "expiryDate"
  9358. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9359. loc = strstr(CardList[c], "expiryDate");
  9360. j = 0;
  9361. if(loc != NULL)
  9362. {
  9363. while (loc[3+strlen("expiryDate")+j] != '\"')
  9364. {
  9365. sstr[j] = loc[3+strlen("expiryDate")+j];
  9366. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9367. j++;
  9368. }
  9369. sstr[j] = '\0';
  9370. strcpy(expiryDate, sstr);
  9371. }
  9372. else
  9373. {
  9374. strcpy(expiryDate, "");
  9375. }
  9376. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9377. //Search "parentIdTag"
  9378. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9379. loc = strstr(CardList[c], "parentIdTag");
  9380. j = 0;
  9381. if(loc != NULL)
  9382. {
  9383. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9384. {
  9385. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9386. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9387. j++;
  9388. }
  9389. sstr[j] = '\0';
  9390. strcpy(parentIdTag, sstr);
  9391. }
  9392. else
  9393. {
  9394. strcpy(parentIdTag, "");
  9395. }
  9396. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9397. //Search "status"
  9398. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9399. loc = strstr(CardList[c], "status");
  9400. j = 0;
  9401. while (loc[3+strlen("status")+j] != '\"')
  9402. {
  9403. sstr[j] = loc[3+strlen("status")+j];
  9404. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9405. j++;
  9406. }
  9407. sstr[j] = '\0';
  9408. strcpy(idTagstatus, sstr);
  9409. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9410. OCPP_getIdTagFromLocalList(idTagstr);
  9411. //OCPP_getIdTagFromLocalList("test"); For Test
  9412. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9413. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9414. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9415. {
  9416. //Local list full update
  9417. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9418. // update list
  9419. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9420. //DEBUG_INFO("Local list full update. 1\n");
  9421. //OCPP_get_TableAuthlocalAllData();
  9422. //DEBUG_INFO("Local list full update. 2\n");
  9423. }
  9424. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9425. {
  9426. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9427. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9428. }
  9429. strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9430. strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9431. strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9432. strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9433. c++;
  9434. }
  9435. }
  9436. else
  9437. {
  9438. //Check UpdateType
  9439. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9440. {
  9441. //Local list full update
  9442. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9443. OCPP_cleanLocalList();
  9444. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9445. goto end;
  9446. }
  9447. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9448. {
  9449. //Local list different update
  9450. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9451. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9452. goto end;
  9453. }
  9454. }
  9455. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9456. end:
  9457. sendSendLocalListConfirmation(uuid, comfirmstr);
  9458. //ShmOCPP16DataPH->MsMsg.bits.SendLocalListConf = 1;
  9459. return result;
  9460. }
  9461. #define MAX 200
  9462. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9463. {
  9464. mtrace();
  9465. int result = FAIL;
  9466. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9467. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9468. char chargingProfilePurposeStr[30]={0};
  9469. char chargingProfileKindStr[16]={0};
  9470. char recurrencyKindStr[10]={0};
  9471. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9472. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9473. int chargingSchedulePeriodCount = 0;
  9474. char comfirmstr[20]={0};
  9475. int meet= FALSE;
  9476. FILE *fptr1;
  9477. char filename[MAX]={0};
  9478. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  9479. char rmFileCmd[50]={0};
  9480. char tempchargingProfilePurposeStr[30]={0};
  9481. char word[1600]={0};
  9482. int n_chargingProfile = 0;
  9483. json_object *SetChargingProfile;
  9484. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9485. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9486. SetChargingProfile = json_tokener_parse(payload);
  9487. if(!is_error(SetChargingProfile))
  9488. {
  9489. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9490. {
  9491. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9492. if(connectorIdInt == 0)
  9493. {
  9494. memset(&ShmOCPP16DataPH->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9495. ShmOCPP16DataPH->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9496. }
  9497. else
  9498. {
  9499. memset(&ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9500. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9501. }
  9502. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9503. }
  9504. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9505. {
  9506. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9507. {
  9508. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9509. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9510. {
  9511. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9512. }
  9513. else
  9514. {
  9515. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9516. }
  9517. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9518. }
  9519. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9520. {
  9521. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9522. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9523. {
  9524. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9525. }
  9526. else
  9527. {
  9528. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9529. }
  9530. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9531. }
  9532. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9533. {
  9534. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9535. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9536. {
  9537. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9538. }
  9539. else
  9540. {
  9541. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9542. }
  9543. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9544. }
  9545. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9546. {
  9547. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9548. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9549. {
  9550. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9551. }
  9552. else
  9553. {
  9554. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9555. }
  9556. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9557. }
  9558. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9559. {
  9560. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9561. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9562. {
  9563. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9564. }
  9565. else
  9566. {
  9567. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9568. }
  9569. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9570. }
  9571. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9572. {
  9573. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9574. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9575. {
  9576. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9577. }
  9578. else
  9579. {
  9580. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9581. }
  9582. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9583. }
  9584. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9585. {
  9586. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9587. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9588. {
  9589. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9590. }
  9591. else
  9592. {
  9593. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9594. }
  9595. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9596. }
  9597. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9598. {
  9599. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9600. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9601. {
  9602. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9603. }
  9604. else
  9605. {
  9606. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9607. }
  9608. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9609. }
  9610. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9611. {
  9612. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9613. {
  9614. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9615. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9616. {
  9617. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9618. }
  9619. else
  9620. {
  9621. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9622. }
  9623. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9624. }
  9625. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9626. {
  9627. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9628. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9629. {
  9630. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9631. }
  9632. else
  9633. {
  9634. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9635. }
  9636. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9637. }
  9638. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9639. {
  9640. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9641. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9642. {
  9643. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9644. }
  9645. else
  9646. {
  9647. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9648. }
  9649. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9650. }
  9651. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9652. {
  9653. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9654. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9655. {
  9656. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9657. }
  9658. else
  9659. {
  9660. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9661. }
  9662. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9663. }
  9664. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9665. {
  9666. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9667. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9668. if(chargingSchedulePeriodCount <= 10)
  9669. {
  9670. 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++)
  9671. {
  9672. 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)
  9673. {
  9674. 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"));
  9675. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9676. {
  9677. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9678. }
  9679. else
  9680. {
  9681. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9682. }
  9683. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9684. }
  9685. 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)
  9686. {
  9687. 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"));
  9688. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9689. {
  9690. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9691. }
  9692. else
  9693. {
  9694. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9695. }
  9696. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9697. }
  9698. 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)
  9699. {
  9700. 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"));
  9701. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9702. {
  9703. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9704. }
  9705. else
  9706. {
  9707. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9708. }
  9709. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9710. }
  9711. }
  9712. }
  9713. }
  9714. }
  9715. }
  9716. }
  9717. json_object_put(SetChargingProfile);
  9718. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9719. {
  9720. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9721. goto end;
  9722. }
  9723. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9724. {
  9725. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9726. if(connectorIdInt != 0)
  9727. {
  9728. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9729. goto end;
  9730. }
  9731. strcpy(filename, ChargePointMaxProfile_JSON );
  9732. fptr1 = fopen(filename, "r");
  9733. if (!fptr1)
  9734. {
  9735. //file not exist
  9736. DEBUG_INFO("Unable to open the input file!!\n");
  9737. fptr1 = fopen(filename, "w+");
  9738. }
  9739. else
  9740. {
  9741. //Check Charging Profile Count
  9742. while(fscanf(fptr1, "%s", word) != EOF)
  9743. {
  9744. //DEBUG_INFO("word=%s\n",word);
  9745. if(strstr(word, "chargingProfileId")!= NULL)
  9746. {
  9747. //DEBUG_INFO("test chargingProfileId \n");
  9748. n_chargingProfile = n_chargingProfile + 1;
  9749. //DEBUG_INFO("chargingProfileId Found\n");
  9750. }
  9751. }
  9752. }
  9753. fclose(fptr1);
  9754. }
  9755. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9756. {
  9757. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9758. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9759. {
  9760. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9761. goto end;
  9762. }
  9763. memset(filename, 0, ARRAY_SIZE(filename));
  9764. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  9765. fptr1 = fopen(filename, "r");
  9766. if (!fptr1)
  9767. {
  9768. //file not exist
  9769. //DEBUG_INFO("Unable to open the input file!!\n");
  9770. fptr1 = fopen(filename, "w+");
  9771. }
  9772. else
  9773. {
  9774. //Check Charging Profile Count
  9775. while(fscanf(fptr1, "%s", word) != EOF)
  9776. {
  9777. //DEBUG_INFO("word=%s\n",word);
  9778. if(strstr(word, "chargingProfileId")!= NULL)
  9779. {
  9780. //DEBUG_INFO("test chargingProfileId \n");
  9781. n_chargingProfile = n_chargingProfile + 1;
  9782. //DEBUG_INFO("chargingProfileId Found\n");
  9783. }
  9784. }
  9785. }
  9786. fclose(fptr1);
  9787. }
  9788. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9789. {
  9790. //printf("set chargingProfile 1-4\n");
  9791. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9792. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9793. if(connectorIdInt == 0)
  9794. {
  9795. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9796. goto end;
  9797. }
  9798. int tempIndex = 0;
  9799. //check Transaction active
  9800. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9801. {
  9802. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9803. {
  9804. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9805. }
  9806. else
  9807. {
  9808. tempIndex = connectorIdInt -1;
  9809. }
  9810. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9811. {
  9812. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9813. {
  9814. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9815. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9816. {
  9817. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9818. {
  9819. meet = TRUE;
  9820. break;
  9821. }
  9822. }
  9823. }
  9824. }
  9825. }
  9826. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9827. {
  9828. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9829. {
  9830. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9831. }
  9832. else
  9833. {
  9834. tempIndex = connectorIdInt -1;
  9835. }
  9836. for (int index = 0; index < CCS_QUANTITY; index++)
  9837. {
  9838. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9839. {
  9840. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9841. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9842. {
  9843. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9844. {
  9845. meet = TRUE;
  9846. break;
  9847. }
  9848. }
  9849. }
  9850. }
  9851. }
  9852. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9853. {
  9854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9855. {
  9856. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9857. }
  9858. else
  9859. {
  9860. tempIndex = connectorIdInt -1;
  9861. }
  9862. for (int index = 0; index < GB_QUANTITY; index++)
  9863. {
  9864. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9865. {
  9866. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9867. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9868. {
  9869. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9870. {
  9871. meet = TRUE;
  9872. break;
  9873. }
  9874. }
  9875. }
  9876. }
  9877. }
  9878. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9879. {
  9880. tempIndex = connectorIdInt -1;
  9881. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9882. {
  9883. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9884. {
  9885. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9886. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9887. {
  9888. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9889. {
  9890. meet = TRUE;
  9891. break;
  9892. }
  9893. }
  9894. }
  9895. }
  9896. }
  9897. else
  9898. {
  9899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9900. {
  9901. tempIndex = 2;
  9902. }
  9903. else
  9904. {
  9905. tempIndex = (connectorIdInt -1);
  9906. }
  9907. for (int index = 0; index < AC_QUANTITY; index++)
  9908. {
  9909. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9910. {
  9911. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9912. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9913. {
  9914. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9915. {
  9916. meet = TRUE;
  9917. break;
  9918. }
  9919. }
  9920. }
  9921. }
  9922. }
  9923. //check Transaction active
  9924. if(meet == FALSE)
  9925. {
  9926. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9927. goto end;
  9928. }
  9929. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9930. {
  9931. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9932. goto end;
  9933. }
  9934. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9935. fptr1 = fopen(filename, "r");
  9936. if (!fptr1)
  9937. {
  9938. //file not exist
  9939. DEBUG_INFO("Unable to open the input file!!\n");
  9940. fptr1 = fopen(filename, "w+");
  9941. }
  9942. else
  9943. {
  9944. //Check Charging Profile Count
  9945. while(fscanf(fptr1, "%s", word) != EOF)
  9946. {
  9947. //DEBUG_INFO("word=%s\n",word);
  9948. if(strstr(word, "chargingProfileId")!= NULL)
  9949. {
  9950. //DEBUG_INFO("test chargingProfileId \n");
  9951. n_chargingProfile = n_chargingProfile + 1;
  9952. //DEBUG_INFO("chargingProfileId Found\n");
  9953. }
  9954. }
  9955. }
  9956. fclose(fptr1);
  9957. }
  9958. // Check ChargeProfileMaxStackLevel
  9959. if(n_chargingProfile >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9960. {
  9961. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9962. goto end;
  9963. }
  9964. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9965. {
  9966. int i = 0;
  9967. char fnametemp[200]={0};
  9968. n_chargingProfile = 0;
  9969. //Check ChargePointMaxProfile.json exit
  9970. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  9971. {
  9972. fptr1 = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  9973. //Check Charging Profile Count
  9974. while(fscanf(fptr1, "%s", word) != EOF)
  9975. {
  9976. //DEBUG_INFO("word=%s\n",word);
  9977. if(strstr(word, "chargingProfileId")!= NULL)
  9978. {
  9979. //DEBUG_INFO("test chargingProfileId \n");
  9980. n_chargingProfile = n_chargingProfile + 1;
  9981. i = i + 1;
  9982. //DEBUG_INFO("chargingProfileId Found\n");
  9983. }
  9984. memset(word, 0, ARRAY_SIZE(word));
  9985. }
  9986. fclose(fptr1);
  9987. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9988. }
  9989. //Check TxDefaultProfile_0.json exit
  9990. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  9991. {
  9992. i = 0;
  9993. fptr1 = fopen("/Storage/OCPP_PH/TxDefaultProfile_0.json", "r");
  9994. //Check Charging Profile Count
  9995. while(fscanf(fptr1, "%s", word) != EOF)
  9996. {
  9997. //DEBUG_INFO("word=%s\n",word);
  9998. if(strstr(word, "chargingProfileId")!= NULL)
  9999. {
  10000. //DEBUG_INFO("test chargingProfileId \n");
  10001. n_chargingProfile = n_chargingProfile + 1;
  10002. i = i + 1;
  10003. //DEBUG_INFO("chargingProfileId Found\n");
  10004. }
  10005. memset(word, 0, ARRAY_SIZE(word));
  10006. }
  10007. fclose(fptr1);
  10008. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10009. }
  10010. //Check TxDefaultProfile_%d.json
  10011. for(int j=1; j <= gunTotalNumber; j++)
  10012. {
  10013. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10014. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  10015. if((access(fnametemp,F_OK))!=-1)
  10016. {
  10017. i = 0;
  10018. fptr1 = fopen(fnametemp, "r");
  10019. //Check Charging Profile Count
  10020. while(fscanf(fptr1, "%s", word) != EOF)
  10021. {
  10022. //DEBUG_INFO("word=%s\n",word);
  10023. if(strstr(word, "chargingProfileId")!= NULL)
  10024. {
  10025. //DEBUG_INFO("test chargingProfileId \n");
  10026. n_chargingProfile = n_chargingProfile + 1;
  10027. i = i + 1;
  10028. //DEBUG_INFO("chargingProfileId Found\n");
  10029. }
  10030. memset(word, 0, ARRAY_SIZE(word));
  10031. }
  10032. fclose(fptr1);
  10033. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10034. }
  10035. }
  10036. //Check TxProfile_%d.json
  10037. for(int j=1; j <= gunTotalNumber; j++)
  10038. {
  10039. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10040. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  10041. if((access(fnametemp,F_OK))!=-1)
  10042. {
  10043. i = 0;
  10044. fptr1 = fopen(fnametemp, "r");
  10045. //Check Charging Profile Count
  10046. while(fscanf(fptr1, "%s", word) != EOF)
  10047. {
  10048. //DEBUG_INFO("word=%s\n",word);
  10049. if(strstr(word, "chargingProfileId")!= NULL)
  10050. {
  10051. //DEBUG_INFO("test chargingProfileId \n");
  10052. n_chargingProfile = n_chargingProfile + 1;
  10053. i = i + 1;
  10054. //DEBUG_INFO("chargingProfileId Found\n");
  10055. }
  10056. memset(word, 0, ARRAY_SIZE(word));
  10057. }
  10058. fclose(fptr1);
  10059. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10060. }
  10061. }
  10062. if( n_chargingProfile > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10063. {
  10064. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10065. goto end;
  10066. }
  10067. }
  10068. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10069. //**********************************Write to File********************************************************/
  10070. FILE *infile;
  10071. FILE *outfile;
  10072. infile = fopen (filename, "r");
  10073. outfile = fopen (tempfile, "w");
  10074. int d =0;
  10075. d = fgetc(infile);
  10076. rewind(infile);
  10077. if(d == EOF)
  10078. {
  10079. // Profile is empty
  10080. fprintf(outfile,"%s\n",payload);
  10081. fclose(infile);
  10082. fclose(outfile);
  10083. sprintf(rmFileCmd,"rm -f %s",filename);
  10084. system(rmFileCmd);
  10085. rename(tempfile, filename);
  10086. }
  10087. else
  10088. {
  10089. // Profile is not empty
  10090. char buf[2048]={0};
  10091. int ChargingProfileAdded = FALSE;
  10092. while (fgets(buf, sizeof(buf), infile) != NULL)
  10093. {
  10094. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10095. json_object *tmpChargingProfile;
  10096. tmpChargingProfile = json_tokener_parse(buf);
  10097. if(!is_error(SetChargingProfile))
  10098. {
  10099. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10100. {
  10101. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10102. }
  10103. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10104. {
  10105. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10106. {
  10107. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10108. }
  10109. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10110. {
  10111. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10112. }
  10113. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10114. {
  10115. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10116. }
  10117. }
  10118. }
  10119. json_object_put(tmpChargingProfile);
  10120. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10121. {
  10122. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10123. {
  10124. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10125. if(ChargingProfileAdded == FALSE)
  10126. {
  10127. fprintf(outfile,"%s\n",payload);
  10128. ChargingProfileAdded = TRUE;
  10129. }
  10130. }
  10131. else
  10132. {
  10133. if(tempstackLevelInt < stackLevelInt)
  10134. {
  10135. if(ChargingProfileAdded == FALSE)
  10136. {
  10137. fprintf(outfile,"%s\n",buf);
  10138. fprintf(outfile,"%s\n",payload);
  10139. ChargingProfileAdded = TRUE;
  10140. }
  10141. else
  10142. {
  10143. fprintf(outfile,"%s\n",buf);
  10144. }
  10145. }
  10146. else
  10147. {
  10148. if(ChargingProfileAdded == FALSE)
  10149. {
  10150. fprintf(outfile,"%s\n",buf);
  10151. fprintf(outfile,"%s\n",payload);
  10152. ChargingProfileAdded = TRUE;
  10153. }
  10154. else
  10155. {
  10156. fprintf(outfile,"%s\n",buf);
  10157. }
  10158. }
  10159. }
  10160. }
  10161. else
  10162. {
  10163. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10164. {
  10165. if(ChargingProfileAdded == FALSE)
  10166. {
  10167. fprintf(outfile,"%s\n",buf);
  10168. fprintf(outfile,"%s\n",payload);
  10169. ChargingProfileAdded = TRUE;
  10170. }
  10171. else
  10172. {
  10173. fprintf(outfile,"%s\n",buf);
  10174. }
  10175. }
  10176. else if(tempstackLevelInt < stackLevelInt)
  10177. {
  10178. if(ChargingProfileAdded == FALSE)
  10179. {
  10180. fprintf(outfile,"%s\n",buf);
  10181. fprintf(outfile,"%s\n",payload);
  10182. ChargingProfileAdded = TRUE;
  10183. }
  10184. else
  10185. {
  10186. fprintf(outfile,"%s\n",buf);
  10187. }
  10188. }
  10189. else
  10190. {
  10191. if(ChargingProfileAdded == FALSE)
  10192. {
  10193. fprintf(outfile,"%s\n",buf);
  10194. fprintf(outfile,"%s\n",payload);
  10195. ChargingProfileAdded = TRUE;
  10196. }
  10197. else
  10198. {
  10199. fprintf(outfile,"%s\n",buf);
  10200. }
  10201. }
  10202. }
  10203. } // end of while loop
  10204. fclose(infile);
  10205. fclose(outfile);
  10206. sprintf(rmFileCmd,"rm -f %s",filename);
  10207. system(rmFileCmd);
  10208. rename(tempfile, filename);
  10209. }
  10210. sleep(1);
  10211. result = TRUE;
  10212. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10213. end:
  10214. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10215. {
  10216. if(connectorIdInt == 0)
  10217. {
  10218. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10219. {
  10220. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  10221. }
  10222. }
  10223. else
  10224. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  10225. }
  10226. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10227. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10228. return result;
  10229. }
  10230. int handleTriggerMessageRequest(char *uuid, char *payload)
  10231. {
  10232. mtrace();
  10233. int result = FAIL;
  10234. int connectorIdIsNULL = FALSE;
  10235. int connectorIdInt =0;
  10236. char sstr[40]={0},sstrtemp[100]={ 0 };
  10237. char requestedMessagestr[40]={0};
  10238. char comfirmstr[20]={0};
  10239. int c = 0;
  10240. char *loc;
  10241. DEBUG_INFO("handleTriggerMessageRequest\n");
  10242. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10243. strcpy(sstrtemp, stringtrimspace(payload));
  10244. c = 0;
  10245. loc = strstr(sstrtemp, "requestedMessage");
  10246. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10247. {
  10248. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10249. c++;
  10250. }
  10251. sstr[c] = '\0';
  10252. strcpy(requestedMessagestr, sstr);
  10253. c = 0;
  10254. loc = strstr(sstrtemp, "connectorId");
  10255. if(loc == NULL)
  10256. {
  10257. connectorIdIsNULL = TRUE;
  10258. }
  10259. else
  10260. {
  10261. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10262. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10263. {
  10264. sstr[c] = loc[strlen("connectorId")+2+c];
  10265. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10266. c++;
  10267. }
  10268. sstr[c] = '\0';
  10269. connectorIdInt = atoi(sstr);
  10270. }
  10271. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10272. {
  10273. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10274. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10275. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10276. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10277. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10278. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10279. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10280. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10281. {
  10282. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10283. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10284. return TRUE;
  10285. }
  10286. else
  10287. {
  10288. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10289. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10290. }
  10291. }
  10292. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10293. {
  10294. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10295. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10296. return TRUE;
  10297. }
  10298. //==========================
  10299. // Trigger message
  10300. //==========================
  10301. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10302. {
  10303. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10304. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10305. {
  10306. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10307. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10308. }
  10309. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10310. }
  10311. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10312. {
  10313. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  10314. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10315. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10316. }
  10317. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10318. {
  10319. //sendBootNotificationRequest();
  10320. server_sign = FALSE;
  10321. }
  10322. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10323. {
  10324. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10325. }
  10326. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10327. {
  10328. if(connectorIdIsNULL == FALSE)
  10329. {
  10330. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10331. {
  10332. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10333. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10334. }
  10335. }
  10336. else
  10337. {
  10338. for(int idx=0;idx< gunTotalNumber;idx++)
  10339. {
  10340. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10341. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10342. }
  10343. }
  10344. }
  10345. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10346. {
  10347. if(connectorIdIsNULL == FALSE)
  10348. {
  10349. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10350. {
  10351. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10352. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10353. }
  10354. }
  10355. else
  10356. {
  10357. for(int idx=0;idx< gunTotalNumber;idx++)
  10358. {
  10359. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  10360. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10361. }
  10362. }
  10363. }
  10364. return result;
  10365. }
  10366. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10367. {
  10368. mtrace();
  10369. int result = FAIL;
  10370. int connectorIdInt =0;
  10371. char comfirmstr[20]={0};
  10372. int tempIndex = 0;
  10373. json_object *UnlockConnector;
  10374. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10375. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10376. UnlockConnector = json_tokener_parse(payload);
  10377. if(!is_error(UnlockConnector))
  10378. {
  10379. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10380. {
  10381. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10382. }
  10383. }
  10384. json_object_put(UnlockConnector);
  10385. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10386. if(gunTotalNumber == 0)
  10387. {
  10388. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10389. goto end;
  10390. }
  10391. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10392. {
  10393. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10394. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10395. goto end;
  10396. }
  10397. else
  10398. {
  10399. //check Transaction active
  10400. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10401. {
  10402. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10403. {
  10404. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10405. }
  10406. else
  10407. {
  10408. tempIndex = connectorIdInt -1;
  10409. }
  10410. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10411. {
  10412. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10413. {
  10414. //stop Transaction
  10415. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10416. }
  10417. }
  10418. }
  10419. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10420. {
  10421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10422. {
  10423. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10424. }
  10425. else
  10426. {
  10427. tempIndex = connectorIdInt -1;
  10428. }
  10429. for (int index = 0; index < CCS_QUANTITY; index++)
  10430. {
  10431. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10432. {
  10433. //stop Transaction
  10434. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10435. }
  10436. }
  10437. }
  10438. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10439. {
  10440. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10441. {
  10442. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10443. }
  10444. else
  10445. {
  10446. tempIndex = connectorIdInt -1;
  10447. }
  10448. for (int index = 0; index < GB_QUANTITY; index++)
  10449. {
  10450. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10451. {
  10452. //stop Transaction
  10453. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10454. }
  10455. }
  10456. }
  10457. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10458. {
  10459. tempIndex = connectorIdInt -1;
  10460. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10461. {
  10462. 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)))
  10463. {
  10464. //stop Transaction
  10465. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10466. }
  10467. }
  10468. }
  10469. else
  10470. {
  10471. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10472. {
  10473. tempIndex = 2;
  10474. }
  10475. else
  10476. {
  10477. tempIndex = connectorIdInt-1;
  10478. }
  10479. for (int index = 0; index < AC_QUANTITY; index++)
  10480. {
  10481. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10482. {
  10483. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10484. }
  10485. }
  10486. }
  10487. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10488. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  10489. result = TRUE;
  10490. return result;
  10491. }
  10492. end:
  10493. //json_object_put(obj); --- remove temporally
  10494. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10495. return result;
  10496. }
  10497. static char UpdateFirmwarepayloadData[300]={0};
  10498. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10499. {
  10500. mtrace();
  10501. int result = FAIL;
  10502. pthread_t t;
  10503. sendUpdateFirmwareConfirmation(uuid);
  10504. memset(UpdateFirmwarepayloadData, 0, 300);
  10505. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10506. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10507. ////pthread_join(t, NULL); //
  10508. //pthread_detach(t);
  10509. //sendUpdateFirmwareConfirmation(uuid);
  10510. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  10511. return result;
  10512. }
  10513. void *UpdateFirmwareProcess(void *data)
  10514. {
  10515. pthread_detach(pthread_self());
  10516. mtrace();
  10517. int retriesInt =0, retryIntervalInt=0;
  10518. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10519. int port=0;
  10520. char locationstr[512]={0}, retrieveDatestr[36]={0};
  10521. int isSuccess = 0;
  10522. char ftpbuf[512];
  10523. char temp[100];
  10524. char * pch;
  10525. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10526. json_object *UpdateFirmware;
  10527. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10528. if(!is_error(UpdateFirmware))
  10529. {
  10530. // Required data
  10531. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10532. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10533. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10534. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10535. // Optional data
  10536. if(json_object_object_get(UpdateFirmware, "retries"))
  10537. {
  10538. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10539. }
  10540. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10541. {
  10542. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10543. }
  10544. }
  10545. json_object_put(UpdateFirmware);
  10546. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10547. memset(path, 0, ARRAY_SIZE(path));
  10548. // Wait retrieveData
  10549. if(strlen(retrieveDatestr) > 10)
  10550. {
  10551. do
  10552. {
  10553. sleep(1);
  10554. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10555. }
  10556. // Ready to download
  10557. system("rm -f /mnt/*");
  10558. if(strncmp(locationstr,"http", 4) == 0)
  10559. {
  10560. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10561. sprintf(ftppath,"/%s", path);
  10562. DEBUG_INFO("locationstr: %s\n", locationstr);
  10563. DEBUG_INFO("protocol: %s\n",protocol);
  10564. DEBUG_INFO("host: %s\n",host);
  10565. DEBUG_INFO("path: %s\n",path);
  10566. DEBUG_INFO("ftppath: %s\n",ftppath);
  10567. int ftppathlen=strlen(ftppath);
  10568. int i=1;
  10569. char filenametemp[50];
  10570. while(i < ftppathlen)
  10571. {
  10572. int len=ftppathlen-i;
  10573. if(ftppath[len]== 47) // '/' ascll code: 47
  10574. {
  10575. DEBUG_INFO("compare '/' all right\n");
  10576. break;
  10577. }
  10578. i=i+1;
  10579. }
  10580. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10581. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10582. filenametemp[i+1] = 0;
  10583. do
  10584. {
  10585. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10586. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10587. sleep(1);
  10588. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10589. if(!isSuccess)
  10590. {
  10591. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10592. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10593. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10594. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10595. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10596. }
  10597. else
  10598. {
  10599. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10600. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10601. }
  10602. retriesInt--;
  10603. }while((isSuccess == 0)&&(retriesInt >= 0));
  10604. }
  10605. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10606. {
  10607. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10608. memset(temp, 0, ARRAY_SIZE(temp));
  10609. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10610. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10611. int ftppathlen=strlen(ftpbuf);
  10612. int i=1;
  10613. char filenametemp[50];
  10614. while(i < ftppathlen)
  10615. {
  10616. int len=ftppathlen-i;
  10617. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10618. {
  10619. DEBUG_INFO(" compare '/' all right\n");
  10620. break;
  10621. }
  10622. i=i+1;
  10623. }
  10624. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10625. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10626. filenametemp[i+1] = 0;
  10627. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10628. pch=strchr(temp,'@');
  10629. if(pch==NULL)
  10630. {
  10631. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10632. protocol, host, &port, path);
  10633. strcpy(user,"anonymous");
  10634. strcpy(password,"");
  10635. }
  10636. else
  10637. {
  10638. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10639. protocol, user, password, host, &port, path);
  10640. }
  10641. sscanf(host,"%[^/]%s",host1, path1);
  10642. sprintf(ftppath,"%s", path1);
  10643. //DEBUG_INFO("protocol =%s\n",protocol);
  10644. //DEBUG_INFO("user =%s\n",user);
  10645. //DEBUG_INFO("password =%s\n",password);
  10646. //DEBUG_INFO("host1 =%s\n",host1);
  10647. //DEBUG_INFO("port =%d\n",port);
  10648. //DEBUG_INFO("path1 =%s\n",path1);
  10649. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10650. //ftpFile(host, user, password, port, ftppath, fname);
  10651. //download firmware pthred
  10652. if(port == 0)
  10653. {
  10654. port = 21;
  10655. }
  10656. do
  10657. {
  10658. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10659. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10660. sleep(1);
  10661. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10662. if(!isSuccess)
  10663. {
  10664. //BulldogUtil.sleepMs(interval*1000);
  10665. DEBUG_INFO("Update firmware request and download file fail.\n");
  10666. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10667. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10668. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10669. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10670. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10671. }
  10672. else
  10673. {
  10674. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10675. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10676. }
  10677. retriesInt--;
  10678. }while((!isSuccess)&&(retriesInt >= 0));
  10679. }
  10680. else
  10681. {
  10682. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10683. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10684. sleep(1);
  10685. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10686. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10687. }
  10688. // OCPPPH only, must announce CSU upgrade firmware
  10689. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  10690. pthread_exit(NULL);
  10691. }
  10692. int handleCertificateSignedRequest(char *uuid, char *payload)
  10693. {
  10694. mtrace();
  10695. int result = PASS;
  10696. json_object *CertificateSigned;
  10697. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10698. CertificateSigned = json_tokener_parse(payload);
  10699. if(!is_error(CertificateSigned))
  10700. {
  10701. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10702. }
  10703. json_object_put(CertificateSigned);
  10704. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  10705. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  10706. fclose(fp);
  10707. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10708. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  10709. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  10710. sendCertificateSignedConfirmation(uuid);
  10711. return result;
  10712. }
  10713. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10714. {
  10715. mtrace();
  10716. int result = PASS;
  10717. json_object *DeleteCertificate;
  10718. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10719. DeleteCertificate = json_tokener_parse(payload);
  10720. if(!is_error(DeleteCertificate))
  10721. {
  10722. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10723. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10724. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10725. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10726. }
  10727. json_object_put(DeleteCertificate);
  10728. /*
  10729. * TODO: Delete certificateSigned process
  10730. */
  10731. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  10732. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  10733. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  10734. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  10735. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  10736. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  10737. sendDeleteCertificateConfirmation(uuid);
  10738. return result;
  10739. }
  10740. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10741. {
  10742. mtrace();
  10743. int result = PASS;
  10744. json_object *ExtendedTriggerMessage;
  10745. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10746. ExtendedTriggerMessage = json_tokener_parse(payload);
  10747. if(!is_error(ExtendedTriggerMessage))
  10748. {
  10749. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10750. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10751. {
  10752. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10753. }
  10754. else
  10755. {
  10756. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  10757. }
  10758. }
  10759. json_object_put(ExtendedTriggerMessage);
  10760. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  10761. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  10762. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10763. {
  10764. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10765. }
  10766. else
  10767. {
  10768. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10769. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10770. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10771. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10772. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10773. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10774. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10775. {
  10776. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10777. }
  10778. else
  10779. {
  10780. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10781. }
  10782. }
  10783. sendExtendedTriggerMessageConfirmation(uuid);
  10784. //==========================
  10785. // Trigger message
  10786. //==========================
  10787. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10788. {
  10789. //sendBootNotificationRequest();
  10790. server_sign = FALSE;
  10791. }
  10792. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10793. {
  10794. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  10795. }
  10796. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10797. {
  10798. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10799. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10800. {
  10801. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10802. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10803. }
  10804. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10805. }
  10806. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10807. {
  10808. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10809. }
  10810. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10811. {
  10812. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10813. {
  10814. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10815. }
  10816. else
  10817. {
  10818. for(int idx=0;idx< gunTotalNumber;idx++)
  10819. {
  10820. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10821. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10822. }
  10823. }
  10824. }
  10825. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10826. {
  10827. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  10828. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  10829. {
  10830. system("openssl req -newkey rsa:2048 -out /Storage/OCPP_PH/certCP.csr -nodes -keyout /Storage/OCPP_PH/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  10831. }
  10832. }
  10833. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10834. {
  10835. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10836. {
  10837. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10838. }
  10839. else
  10840. {
  10841. for(int idx=0;idx< gunTotalNumber;idx++)
  10842. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10843. }
  10844. }
  10845. return result;
  10846. }
  10847. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10848. {
  10849. mtrace();
  10850. int result = PASS;
  10851. json_object *GetInstalledCertificateIds;
  10852. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10853. GetInstalledCertificateIds = json_tokener_parse(payload);
  10854. if(!is_error(GetInstalledCertificateIds))
  10855. {
  10856. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10857. }
  10858. json_object_put(GetInstalledCertificateIds);
  10859. /*
  10860. * TODO: Return installed certificate process
  10861. */
  10862. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10863. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  10864. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10865. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  10866. sendGetInstalledCertificateIdsConfirmation(uuid);
  10867. return result;
  10868. }
  10869. int handleGetLogRequest(char *uuid, char *payload)
  10870. {
  10871. mtrace();
  10872. int result = PASS;
  10873. json_object *GetLog;
  10874. DEBUG_INFO("handleGetLogRequest...\n");
  10875. GetLog = json_tokener_parse(payload);
  10876. if(!is_error(GetLog))
  10877. {
  10878. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10879. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10880. if(json_object_object_get(GetLog, "retries") != NULL)
  10881. {
  10882. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10883. }
  10884. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10885. {
  10886. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10887. }
  10888. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10889. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10890. {
  10891. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10892. }
  10893. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10894. {
  10895. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10896. }
  10897. }
  10898. json_object_put(GetLog);
  10899. /*
  10900. * TODO: Upload log process
  10901. */
  10902. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  10903. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  10904. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  10905. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  10906. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  10907. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  10908. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  10909. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  10910. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  10911. sendGetLogConfirmation(uuid);
  10912. return result;
  10913. }
  10914. int handleInstallCertificateRequest(char *uuid, char *payload)
  10915. {
  10916. mtrace();
  10917. int result = PASS;
  10918. json_object *InstallCertificate;
  10919. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10920. InstallCertificate = json_tokener_parse(payload);
  10921. if(!is_error(InstallCertificate))
  10922. {
  10923. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10924. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10925. /*
  10926. * TODO: Install certificate process
  10927. */
  10928. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  10929. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  10930. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  10931. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  10932. sendInstallCertificateConfirmation(uuid);
  10933. }
  10934. json_object_put(InstallCertificate);
  10935. return result;
  10936. }
  10937. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10938. {
  10939. mtrace();
  10940. int result = PASS;
  10941. json_object *SignedUpdateFirmware;
  10942. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10943. SignedUpdateFirmware = json_tokener_parse(payload);
  10944. if(!is_error(SignedUpdateFirmware))
  10945. {
  10946. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10947. {
  10948. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10949. }
  10950. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10951. {
  10952. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10953. }
  10954. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10955. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10956. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10957. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10958. {
  10959. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10960. }
  10961. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10962. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10963. }
  10964. json_object_put(SignedUpdateFirmware);
  10965. /*
  10966. * TODO: Upgrade firmware process
  10967. */
  10968. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10969. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  10970. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  10971. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  10972. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  10973. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  10974. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  10975. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  10976. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  10977. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  10978. sendInstallCertificateConfirmation(uuid);
  10979. return result;
  10980. }
  10981. int handleUnknownRequest(char *uuid, char *payload)
  10982. {
  10983. mtrace();
  10984. int result = PASS;
  10985. DEBUG_INFO("handleUnknownRequest...\n");
  10986. sendUnknownConfirmation(uuid);
  10987. result = PASS;
  10988. return result;
  10989. }
  10990. //==========================================
  10991. // Handle server response routine
  10992. //==========================================
  10993. void handleAuthorizeResponse(char *payload, int gun_index)
  10994. {
  10995. mtrace();
  10996. char expiryDatestr[30]={0};
  10997. char parentIdTagstr[20]={0};
  10998. char statusstr[20]={0};
  10999. int expiryDateISNULL=FALSE;
  11000. int parentIdTagISNULL=FALSE;
  11001. DEBUG_INFO("handleAuthorizeResponse...\n");
  11002. json_object *Authorize;
  11003. Authorize = json_tokener_parse(payload);
  11004. if(!is_error(Authorize))
  11005. {
  11006. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11007. {
  11008. // Required data
  11009. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11010. // Optional data
  11011. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11012. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11013. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11014. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11015. }
  11016. }
  11017. json_object_put(Authorize);
  11018. if(expiryDateISNULL == FALSE)
  11019. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11020. if(parentIdTagISNULL == FALSE)
  11021. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11022. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11023. //Update idTag information to authorization cache if supproted
  11024. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11025. {
  11026. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11027. }
  11028. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11029. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11030. authorizeRetryTimes = 0;
  11031. }
  11032. void handleBootNotificationResponse(char *payload, int gun_index)
  11033. {
  11034. mtrace();
  11035. char statusStr[12]={0};
  11036. char currentTimeStr[30]={0};
  11037. int intervalInt = 0;
  11038. DEBUG_INFO("handleBootNotificationResponse...\n");
  11039. json_object *BootNotification;
  11040. BootNotification = json_tokener_parse(payload);
  11041. if(!is_error(BootNotification))
  11042. {
  11043. // Required data
  11044. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11045. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11046. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11047. }
  11048. json_object_put(BootNotification);
  11049. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11050. BootNotificationInterval = intervalInt;
  11051. HeartBeatWaitTime = intervalInt;
  11052. //write back to ShmOCPP16DataPH->BootNotification
  11053. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11054. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11055. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11056. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11057. {
  11058. server_sign = TRUE;
  11059. server_pending =FALSE;
  11060. }
  11061. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11062. {
  11063. server_pending = TRUE;
  11064. }
  11065. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11066. srand(time(NULL));
  11067. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11068. SetOcppConnStatus(TRUE);
  11069. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11070. }
  11071. void handleDataTransferResponse(char *payload, int gun_index)
  11072. {
  11073. char sstr[160]={0};//sstr[200]={ 0 };
  11074. int c = 0;
  11075. char *loc;
  11076. DEBUG_INFO("handleDataTransferResponse ...\n");
  11077. loc = strstr(payload, "status");
  11078. printf("loc=%s\n",loc);
  11079. c = 0;
  11080. while (loc[3+strlen("status")+c] != '\"')
  11081. {
  11082. sstr[c] = loc[3+strlen("status")+c];
  11083. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11084. c++;
  11085. }
  11086. sstr[c] = '\0';
  11087. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11088. }
  11089. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11090. {
  11091. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11092. //struct json_object *obj;
  11093. // obj = json_tokener_parse(payload);
  11094. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11095. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11096. //No fields are defined.
  11097. }
  11098. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11099. {
  11100. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11101. //struct json_object *obj;
  11102. // obj = json_tokener_parse(payload);
  11103. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11104. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11105. //No fields are defined.
  11106. }
  11107. void handleHeartbeatResponse(char *payload, int gun_index)
  11108. {
  11109. mtrace();
  11110. DEBUG_INFO("handleHeartbeatResponse...\n");
  11111. json_object *Heartbeat;
  11112. Heartbeat = json_tokener_parse(payload);
  11113. if(!is_error(Heartbeat))
  11114. {
  11115. // Required data
  11116. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11117. }
  11118. json_object_put(Heartbeat);
  11119. if(FirstHeartBeat == 0)
  11120. {
  11121. FirstHeartBeat = 1;
  11122. DEBUG_INFO("FirstHeartBeat \n");
  11123. }
  11124. HeartBeatWithNOResponse = 0;
  11125. clientTime.Heartbeat=time((time_t*)NULL);
  11126. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11127. }
  11128. void handleMeterValuesResponse(char *payload, int gun_index)
  11129. {
  11130. mtrace();
  11131. DEBUG_INFO("handleMeterValuesResponse...\n");
  11132. }
  11133. void handleStartTransactionResponse(char *payload, int gun_index)
  11134. {
  11135. mtrace();
  11136. //int transactionIdInt = 0;
  11137. FILE *outfile;
  11138. char data[100]={0};
  11139. DEBUG_INFO("handleStartTransactionResponse...\n");
  11140. json_object *StartTransaction;
  11141. StartTransaction = json_tokener_parse(payload);
  11142. if(!is_error(StartTransaction))
  11143. {
  11144. // Required data
  11145. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11146. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11147. // Optional data
  11148. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11149. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11150. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11151. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11152. }
  11153. json_object_put(StartTransaction);
  11154. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11155. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11156. //-----------Start : write to the Queue TransactionId file -----------------//
  11157. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11158. {}
  11159. else
  11160. {
  11161. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  11162. if(log == NULL)
  11163. {
  11164. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11165. return ;
  11166. }
  11167. else
  11168. {
  11169. fclose(log);
  11170. }
  11171. }
  11172. // open file for writing
  11173. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11174. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  11175. {
  11176. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  11177. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11178. fputs(data, outfile);
  11179. fclose (outfile);
  11180. }
  11181. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11182. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11183. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11184. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  11185. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11186. }
  11187. void handleStatusNotificationResponse(char *payload, int gun_index)
  11188. {
  11189. mtrace();
  11190. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11191. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11192. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11193. }
  11194. void handleStopTransactionnResponse(char *payload, int gun_index)
  11195. {
  11196. mtrace();
  11197. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11198. json_object *StopTransaction;
  11199. StopTransaction = json_tokener_parse(payload);
  11200. if(!is_error(StopTransaction))
  11201. {
  11202. // Optional data
  11203. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11204. {
  11205. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11206. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11207. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11208. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11209. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11210. }
  11211. }
  11212. json_object_put(StopTransaction);
  11213. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11214. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11215. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11216. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11217. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11218. }
  11219. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11220. {
  11221. mtrace();
  11222. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11223. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  11224. }
  11225. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11226. {
  11227. mtrace();
  11228. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11229. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  11230. }
  11231. void handleSignCertificateResponse(char *payload, int gun_index)
  11232. {
  11233. mtrace();
  11234. DEBUG_INFO("handleSignCertificateResponse...\n");
  11235. json_object *SignCertificate;
  11236. SignCertificate = json_tokener_parse(payload);
  11237. if(!is_error(SignCertificate))
  11238. {
  11239. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11240. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  11241. }
  11242. json_object_put(SignCertificate);
  11243. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  11244. }
  11245. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11246. {
  11247. mtrace();
  11248. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11249. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11250. }
  11251. //==========================================
  11252. // Handle Error routine
  11253. //==========================================
  11254. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11255. {
  11256. mtrace();
  11257. #ifdef SystemLogMessage
  11258. DEBUG_INFO("errorCode: %s\n", errorCode);
  11259. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11260. DEBUG_INFO("errorDetails: %s\n", payload);
  11261. #endif
  11262. }
  11263. //===============================================
  11264. // Common routine
  11265. //===============================================
  11266. int initialConfigurationTable(void)
  11267. {
  11268. //clock_t start_t, end_t, total_t;
  11269. FILE *fp;
  11270. FILE *outfile;
  11271. char str[512]={0};
  11272. char sstr[256]={0};
  11273. int c = 0;
  11274. char *loc;
  11275. int confVersion = 3;
  11276. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11277. //start_t = clock();
  11278. //printf("Starting of the program, start_t = %ld\n", start_t);
  11279. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11280. // Check configuration file size is correct
  11281. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  11282. {
  11283. struct stat st;
  11284. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  11285. if(st.st_size < 3100)
  11286. {
  11287. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  11288. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11289. }
  11290. }
  11291. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  11292. {
  11293. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11294. if(outfile == NULL)
  11295. {
  11296. DEBUG_INFO("Error opening file\n");
  11297. return FALSE;
  11298. }
  11299. /*Core Profile*/
  11300. //AllowOfflineTxForUnknownId
  11301. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11305. //AuthorizationCacheEnabled
  11306. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11308. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11310. //AuthorizeRemoteTxRequests
  11311. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11313. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11315. //BlinkRepeat
  11316. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11317. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11320. //ClockAlignedDataInterval
  11321. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11322. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11325. //ConnectionTimeOut
  11326. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11327. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11330. //GetConfigurationMaxKeys
  11331. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11333. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11335. // HeartbeatInterval
  11336. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11340. // LightIntensity
  11341. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11345. // LocalAuthorizeOffline
  11346. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11350. // LocalPreAuthorize
  11351. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11355. // MaxEnergyOnInvalidId
  11356. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11358. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11360. // MeterValuesAlignedData
  11361. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11363. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11364. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11365. else
  11366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11368. // MeterValuesAlignedDataMaxLength
  11369. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11373. else
  11374. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11376. // MeterValuesSampledData
  11377. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11381. else
  11382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11384. // MeterValuesSampledDataMaxLength
  11385. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11386. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11387. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11389. else
  11390. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11392. // MeterValueSampleInterval
  11393. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11395. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11397. // MinimumStatusDuration
  11398. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11400. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11401. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11403. // NumberOfConnectors
  11404. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11407. {
  11408. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11409. }
  11410. else
  11411. {
  11412. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11413. }
  11414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11415. // ResetRetries
  11416. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11418. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11420. // ConnectorPhaseRotation
  11421. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11425. // ConnectorPhaseRotationMaxLength
  11426. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11428. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11430. // StopTransactionOnEVSideDisconnect
  11431. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11433. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11435. // StopTransactionOnInvalidId
  11436. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11437. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11440. // StopTxnAlignedData
  11441. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11443. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11445. // StopTxnAlignedDataMaxLength
  11446. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11447. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11448. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11450. // StopTxnSampledData
  11451. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11452. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11454. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11455. else
  11456. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11458. // StopTxnSampledDataMaxLength
  11459. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11460. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11462. {
  11463. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11464. }
  11465. else
  11466. {
  11467. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11468. }
  11469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11470. // SupportedFeatureProfiles
  11471. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11472. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11473. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11475. // SupportedFeatureProfilesMaxLength
  11476. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11477. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11478. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11480. // TransactionMessageAttempts
  11481. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11482. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11483. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11484. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11486. // TransactionMessageRetryInterval
  11487. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11488. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11489. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11490. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11492. // UnlockConnectorOnEVSideDisconnect
  11493. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11494. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11495. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11497. // WebSocketPingInterval
  11498. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11499. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11500. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11502. // QueueOffLineStartTransactionMessage
  11503. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11504. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11505. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11507. // AuthorizationKey
  11508. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11509. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11510. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  11511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11512. // SecurityProfile
  11513. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11514. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  11516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11517. // DefaultPrice
  11518. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11519. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11520. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11522. // CustomDisplayCostAndPrice
  11523. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11524. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11525. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11527. // CustomIdleFeeAfterStop
  11528. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11529. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11530. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11532. // Configuration Version
  11533. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11534. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11535. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11537. //* Local Auth List Management Profile*/
  11538. #if 0
  11539. //For OCTT Test Case
  11540. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11541. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11542. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11543. #endif
  11544. #if 1
  11545. //LocalAuthListEnabled
  11546. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11547. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11548. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11550. #endif
  11551. //LocalAuthListMaxLength
  11552. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11553. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11554. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11556. //SendLocalListMaxLength
  11557. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11558. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11559. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11561. //ReserveConnectorZeroSupported
  11562. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11563. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11564. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11566. //* Smart Charging Profile */
  11567. //ChargeProfileMaxStackLevel
  11568. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11569. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11570. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11572. // ChargingScheduleAllowedChargingRateUnit
  11573. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11574. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11575. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  11576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11577. // ChargingScheduleMaxPeriods
  11578. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11579. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11580. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11582. // ConnectorSwitch3to1PhaseSupported
  11583. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11584. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11585. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  11586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11587. // MaxChargingProfilesInstalled
  11588. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11589. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11590. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11592. fclose(outfile);
  11593. }
  11594. else
  11595. {
  11596. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  11597. char keystr[60]={0};
  11598. char readonlystr[10]={0};
  11599. char valuestr[256]={0};
  11600. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  11601. if(fp == NULL) {
  11602. DEBUG_INFO("Error opening file");
  11603. return FALSE;
  11604. }
  11605. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11606. {
  11607. //DEBUG_INFO("Get Configuration \n");
  11608. if(strlen(str) > 0)
  11609. {
  11610. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11611. //*************************key*********************************/
  11612. if(strstr(str, "key") != NULL)
  11613. {
  11614. loc = strstr(str, "key");
  11615. c = 0;
  11616. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11617. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11618. {
  11619. sstr[c] = loc[strlen("key")+3+c];
  11620. c++;
  11621. }
  11622. sstr[c] = '\0';
  11623. strcpy(keystr,sstr);
  11624. }
  11625. //*************************readonly*********************************/
  11626. if(strstr(str, "readonly") != NULL)
  11627. {
  11628. loc = strstr(str, "readonly");
  11629. c = 0;
  11630. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11631. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11632. {
  11633. sstr[c] = loc[strlen("readonly")+2+c];
  11634. c++;
  11635. }
  11636. sstr[c] = '\0';
  11637. strcpy(readonlystr,sstr);
  11638. }
  11639. //*************************value*********************************/
  11640. if(strstr(str, "value") != NULL)
  11641. {
  11642. loc = strstr(str, "value");
  11643. c = 0;
  11644. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11645. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11646. {
  11647. sstr[c] = loc[strlen("value")+3+c];
  11648. c++;
  11649. }
  11650. sstr[c] = '\0';
  11651. strcpy(valuestr,sstr);
  11652. }
  11653. // DEBUG_INFO("keystr=%s\n",keystr);
  11654. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11655. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11656. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11657. {
  11658. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11659. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11660. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11661. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11662. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11663. }
  11664. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11665. {
  11666. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11667. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11668. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11669. }
  11670. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11671. {
  11672. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11673. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11674. }
  11675. if(strcmp(keystr, "BlinkRepeat") == 0)
  11676. {
  11677. //Charger.BlinkRepeat = Integer.parseInt(value);
  11678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11679. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11680. }
  11681. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11682. {
  11683. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11684. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11685. }
  11686. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11687. {
  11688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11689. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11690. }
  11691. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11692. {
  11693. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11694. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11695. }
  11696. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11697. {
  11698. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11699. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11700. HeartBeatWaitTime = atoi(valuestr);
  11701. }
  11702. if(strcmp(keystr, "LightIntensity") == 0)
  11703. {
  11704. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11705. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11706. }
  11707. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11708. {
  11709. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11710. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11711. }
  11712. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11713. {
  11714. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11715. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11716. }
  11717. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11718. {
  11719. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11720. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11721. }
  11722. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11723. {
  11724. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11725. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11726. }
  11727. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11728. {
  11729. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11730. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11731. }
  11732. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11733. {
  11734. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11735. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11736. }
  11737. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11738. {
  11739. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11740. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11741. }
  11742. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11743. {
  11744. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11745. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11746. }
  11747. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11748. {
  11749. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11750. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11751. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11752. }
  11753. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11754. {
  11755. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11756. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11757. }
  11758. if(strcmp(keystr, "ResetRetries") == 0)
  11759. {
  11760. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11761. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11762. }
  11763. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11764. {
  11765. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11766. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11767. }
  11768. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11769. {
  11770. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11771. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11772. }
  11773. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11774. {
  11775. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11776. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11777. }
  11778. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11779. {
  11780. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11781. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11782. }
  11783. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11784. {
  11785. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11786. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11787. }
  11788. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11789. {
  11790. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11791. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11792. }
  11793. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11794. {
  11795. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11796. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11797. }
  11798. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11799. {
  11800. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11801. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11802. }
  11803. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11804. {
  11805. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11806. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11807. }
  11808. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11809. {
  11810. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11811. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11812. }
  11813. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11814. {
  11815. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11816. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11817. TransactionMessageAttemptsValue = atoi(valuestr);
  11818. }
  11819. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11820. {
  11821. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11822. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11823. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11824. }
  11825. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11826. {
  11827. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11828. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11829. }
  11830. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11831. {
  11832. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11833. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11834. }
  11835. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11836. {
  11837. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11838. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11839. }
  11840. if(strcmp(keystr, "AuthorizationKey") == 0)
  11841. {
  11842. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11843. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11844. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11845. }
  11846. if(strcmp(keystr, "SecurityProfile") == 0)
  11847. {
  11848. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11849. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11850. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  11851. }
  11852. if(strcmp(keystr, "DefaultPrice") == 0)
  11853. {
  11854. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11855. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11856. }
  11857. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11858. {
  11859. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11860. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11861. }
  11862. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11863. {
  11864. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11865. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11866. }
  11867. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11868. {
  11869. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11870. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11871. }
  11872. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11873. {
  11874. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11875. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11876. }
  11877. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11878. {
  11879. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11880. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11881. }
  11882. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11883. {
  11884. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11885. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11886. }
  11887. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11888. {
  11889. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11890. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11891. }
  11892. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11893. {
  11894. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11895. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11896. }
  11897. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11898. {
  11899. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11900. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11901. }
  11902. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11903. {
  11904. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11905. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11906. }
  11907. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11908. {
  11909. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11910. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11911. }
  11912. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11913. {
  11914. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11915. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11916. }
  11917. }
  11918. }
  11919. fclose(fp);
  11920. }
  11921. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11922. {
  11923. return PASS;
  11924. }
  11925. else
  11926. {
  11927. return FAIL;
  11928. }
  11929. }
  11930. void StoreConfigurationTable(void)
  11931. {
  11932. FILE *outfile;
  11933. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11934. if(outfile == NULL)
  11935. {
  11936. DEBUG_INFO("Error opening file");
  11937. return ;
  11938. }
  11939. /*Core Profile*/
  11940. //AllowOfflineTxForUnknownId
  11941. /*
  11942. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11943. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11944. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11946. */
  11947. //DEBUG_INFO("data=%s\n",data);
  11948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11949. //AuthorizationCacheEnabled
  11950. /*
  11951. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11954. */
  11955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11956. //AuthorizeRemoteTxRequests
  11957. /*
  11958. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11961. */
  11962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11963. //BlinkRepeat
  11964. /*
  11965. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11968. */
  11969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11970. //ClockAlignedDataInterval
  11971. /*
  11972. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11975. */
  11976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11977. //ConnectionTimeOut
  11978. /*
  11979. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11982. */
  11983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11984. //GetConfigurationMaxKeys
  11985. /*
  11986. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11989. */
  11990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11991. // HeartbeatInterval
  11992. /*
  11993. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11996. */
  11997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11998. // LightIntensity
  11999. /*
  12000. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12003. */
  12004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12005. // LocalAuthorizeOffline
  12006. /*
  12007. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12009. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12010. */
  12011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12012. // LocalPreAuthorize
  12013. /*
  12014. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12017. */
  12018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12019. // MaxEnergyOnInvalidId
  12020. /*
  12021. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12024. */
  12025. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12027. // MeterValuesAlignedData
  12028. /*
  12029. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12031. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12032. */
  12033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12034. // MeterValuesAlignedDataMaxLength
  12035. /*
  12036. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12039. */
  12040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12041. // MeterValuesSampledData
  12042. /*
  12043. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12045. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12046. */
  12047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12048. // MeterValuesSampledDataMaxLength
  12049. /*
  12050. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12053. */
  12054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12055. // MeterValueSampleInterval
  12056. /*
  12057. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12059. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12060. */
  12061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12062. // MinimumStatusDuration
  12063. /*
  12064. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12067. */
  12068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12069. // NumberOfConnectors
  12070. /*
  12071. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12074. {
  12075. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12076. }
  12077. else
  12078. {
  12079. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12080. }
  12081. */
  12082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12083. // ResetRetries
  12084. /*
  12085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12088. */
  12089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12090. // ConnectorPhaseRotation
  12091. /*
  12092. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12095. */
  12096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12097. // ConnectorPhaseRotationMaxLength
  12098. /*
  12099. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12102. */
  12103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12104. // StopTransactionOnEVSideDisconnect
  12105. /*
  12106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12109. */
  12110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12111. // StopTransactionOnInvalidId
  12112. /*
  12113. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12116. */
  12117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12118. // StopTxnAlignedData
  12119. /*
  12120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12123. */
  12124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12125. // StopTxnAlignedDataMaxLength
  12126. /*
  12127. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12128. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12130. */
  12131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12132. // StopTxnSampledData
  12133. /*
  12134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12137. */
  12138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12139. // StopTxnSampledDataMaxLength
  12140. /*
  12141. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12142. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12144. */
  12145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12146. // SupportedFeatureProfiles
  12147. /*
  12148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12151. */
  12152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12153. // SupportedFeatureProfilesMaxLength
  12154. /*
  12155. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12158. */
  12159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12160. // TransactionMessageAttempts
  12161. /*
  12162. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12165. */
  12166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12167. // TransactionMessageRetryInterval
  12168. /*
  12169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12172. */
  12173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12174. // UnlockConnectorOnEVSideDisconnect
  12175. /*
  12176. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12179. */
  12180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12181. // WebSocketPingInterval
  12182. /*
  12183. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12186. */
  12187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12188. // QueueOffLineStartTransactionMessage
  12189. /*
  12190. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12193. */
  12194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12195. // AuthorizationKey
  12196. /*
  12197. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12200. */
  12201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12202. // SecurityProfile
  12203. /*
  12204. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12207. */
  12208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12209. // DefaultPrice
  12210. /*
  12211. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12214. */
  12215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12216. // CustomDisplayCostAndPrice
  12217. /*
  12218. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12221. */
  12222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12223. // CustomIdleFeeAfterStop
  12224. /*
  12225. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12228. */
  12229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12230. // ConfigurationVersion
  12231. /*
  12232. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12233. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12235. */
  12236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12237. //* Local Auth List Management Profile*/
  12238. //LocalAuthListEnabled
  12239. /*
  12240. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12242. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12243. */
  12244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12245. //LocalAuthListMaxLength
  12246. /*
  12247. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12249. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12250. */
  12251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12252. //SendLocalListMaxLength
  12253. /*
  12254. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12257. */
  12258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12259. //ReserveConnectorZeroSupported
  12260. /*
  12261. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12262. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12263. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12264. */
  12265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12266. //* Smart Charging Profile */
  12267. //ChargeProfileMaxStackLevel
  12268. /*
  12269. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12271. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12272. */
  12273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12274. // ChargingScheduleAllowedChargingRateUnit
  12275. /*
  12276. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12277. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12278. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12279. */
  12280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12281. // ChargingScheduleMaxPeriods
  12282. /*
  12283. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12284. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12285. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12286. */
  12287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12288. // ConnectorSwitch3to1PhaseSupported
  12289. /*
  12290. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12292. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12293. */
  12294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12295. // MaxChargingProfilesInstalled
  12296. /*
  12297. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12298. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12299. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12300. */
  12301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12302. fclose(outfile);
  12303. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12304. }
  12305. void getKeyValue(char *keyReq)
  12306. {
  12307. int isEmpty = FALSE;
  12308. int isKnowKey = FALSE;
  12309. DEBUG_INFO("keyReq = %s\n", keyReq);
  12310. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12311. isEmpty = TRUE;
  12312. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12313. {
  12314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12316. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12317. {
  12318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12319. }
  12320. else
  12321. {
  12322. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12323. }
  12324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12325. isKnowKey = TRUE;
  12326. }
  12327. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12328. {
  12329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12331. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12332. {
  12333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12334. }
  12335. else
  12336. {
  12337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12338. }
  12339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12340. isKnowKey = TRUE;
  12341. }
  12342. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12343. {
  12344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12346. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12347. {
  12348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12349. }
  12350. else
  12351. {
  12352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12353. }
  12354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12355. isKnowKey = TRUE;
  12356. }
  12357. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12358. {
  12359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12361. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12362. {
  12363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12364. }
  12365. else
  12366. {
  12367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12368. }
  12369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12370. isKnowKey = TRUE;
  12371. }
  12372. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12373. {
  12374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12376. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12377. {
  12378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12379. }
  12380. else
  12381. {
  12382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12383. }
  12384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12385. isKnowKey = TRUE;
  12386. }
  12387. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12388. {
  12389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12391. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12392. {
  12393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12394. }
  12395. else
  12396. {
  12397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12398. }
  12399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12400. isKnowKey = TRUE;
  12401. }
  12402. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12403. {
  12404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12406. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12407. {
  12408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12409. }
  12410. else
  12411. {
  12412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12413. }
  12414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12415. isKnowKey = TRUE;
  12416. }
  12417. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12418. {
  12419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12421. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12422. {
  12423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12424. }
  12425. else
  12426. {
  12427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12428. }
  12429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12430. isKnowKey = TRUE;
  12431. }
  12432. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12433. {
  12434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12436. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12437. {
  12438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12439. }
  12440. else
  12441. {
  12442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12443. }
  12444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12445. isKnowKey = TRUE;
  12446. }
  12447. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12448. {
  12449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12451. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12452. {
  12453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12454. }
  12455. else
  12456. {
  12457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12458. }
  12459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12460. isKnowKey = TRUE;
  12461. }
  12462. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12463. {
  12464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12466. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12467. {
  12468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12469. }
  12470. else
  12471. {
  12472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12473. }
  12474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12475. isKnowKey = TRUE;
  12476. }
  12477. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12478. {
  12479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12481. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12482. {
  12483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12484. }
  12485. else
  12486. {
  12487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12488. }
  12489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12490. isKnowKey = TRUE;
  12491. }
  12492. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12493. {
  12494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12496. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12497. {
  12498. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12499. }
  12500. else
  12501. {
  12502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12503. }
  12504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12505. isKnowKey = TRUE;
  12506. }
  12507. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12508. {
  12509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12511. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12512. {
  12513. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12514. }
  12515. else
  12516. {
  12517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12518. }
  12519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12520. isKnowKey = TRUE;
  12521. }
  12522. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12523. {
  12524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12526. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12527. {
  12528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12529. }
  12530. else
  12531. {
  12532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12533. }
  12534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12535. isKnowKey = TRUE;
  12536. }
  12537. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12538. {
  12539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12541. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12542. {
  12543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12544. }
  12545. else
  12546. {
  12547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12548. }
  12549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12550. isKnowKey = TRUE;
  12551. }
  12552. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12553. {
  12554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12556. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12557. {
  12558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12559. }
  12560. else
  12561. {
  12562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12563. }
  12564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12565. isKnowKey = TRUE;
  12566. }
  12567. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12568. {
  12569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12571. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12572. {
  12573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12574. }
  12575. else
  12576. {
  12577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12578. }
  12579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  12580. isKnowKey = TRUE;
  12581. }
  12582. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12583. {
  12584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12586. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12587. {
  12588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12589. }
  12590. else
  12591. {
  12592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12593. }
  12594. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12596. isKnowKey = TRUE;
  12597. }
  12598. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12599. {
  12600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12602. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12603. {
  12604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12605. }
  12606. else
  12607. {
  12608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12609. }
  12610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12611. isKnowKey = TRUE;
  12612. }
  12613. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12614. {
  12615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12617. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12618. {
  12619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12620. }
  12621. else
  12622. {
  12623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12624. }
  12625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12626. isKnowKey = TRUE;
  12627. }
  12628. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12629. {
  12630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12632. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12633. {
  12634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12635. }
  12636. else
  12637. {
  12638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12639. }
  12640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12641. isKnowKey = TRUE;
  12642. }
  12643. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12644. {
  12645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12647. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12648. {
  12649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12650. }
  12651. else
  12652. {
  12653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12654. }
  12655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12656. isKnowKey = TRUE;
  12657. }
  12658. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12659. {
  12660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12662. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12663. {
  12664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12665. }
  12666. else
  12667. {
  12668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12669. }
  12670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12671. isKnowKey = TRUE;
  12672. }
  12673. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12674. {
  12675. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12677. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12678. {
  12679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12680. }
  12681. else
  12682. {
  12683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12684. }
  12685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12686. isKnowKey = TRUE;
  12687. }
  12688. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12689. {
  12690. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12692. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12693. {
  12694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12695. }
  12696. else
  12697. {
  12698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12699. }
  12700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12701. isKnowKey = TRUE;
  12702. }
  12703. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12704. {
  12705. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12707. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12708. {
  12709. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12710. }
  12711. else
  12712. {
  12713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12714. }
  12715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12716. isKnowKey = TRUE;
  12717. }
  12718. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12719. {
  12720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12722. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12723. {
  12724. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12725. }
  12726. else
  12727. {
  12728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12729. }
  12730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12731. isKnowKey = TRUE;
  12732. }
  12733. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12734. {
  12735. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12737. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12738. {
  12739. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12740. }
  12741. else
  12742. {
  12743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12744. }
  12745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12746. isKnowKey = TRUE;
  12747. }
  12748. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12749. {
  12750. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12752. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12753. {
  12754. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12755. }
  12756. else
  12757. {
  12758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12759. }
  12760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12761. isKnowKey = TRUE;
  12762. }
  12763. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12764. {
  12765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12767. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12768. {
  12769. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12770. }
  12771. else
  12772. {
  12773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12774. }
  12775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12776. isKnowKey = TRUE;
  12777. }
  12778. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12779. {
  12780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12781. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12782. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12783. {
  12784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12785. }
  12786. else
  12787. {
  12788. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12789. }
  12790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12791. isKnowKey = TRUE;
  12792. }
  12793. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12794. {
  12795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12796. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12797. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12798. {
  12799. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12800. }
  12801. else
  12802. {
  12803. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12804. }
  12805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12806. isKnowKey = TRUE;
  12807. }
  12808. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12809. {
  12810. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12811. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12812. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12813. {
  12814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12815. }
  12816. else
  12817. {
  12818. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12819. }
  12820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12821. isKnowKey = TRUE;
  12822. }
  12823. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12824. {
  12825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12827. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12828. {
  12829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12830. }
  12831. else
  12832. {
  12833. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12834. }
  12835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12836. isKnowKey = TRUE;
  12837. }
  12838. /*
  12839. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12840. {
  12841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12843. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12844. {
  12845. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12846. }
  12847. else
  12848. {
  12849. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12850. }
  12851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12852. isKnowKey = TRUE;
  12853. }*/
  12854. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12855. {
  12856. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12858. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12859. {
  12860. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12861. }
  12862. else
  12863. {
  12864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12865. }
  12866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12867. isKnowKey = TRUE;
  12868. }
  12869. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12870. {
  12871. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12873. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12874. {
  12875. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12876. }
  12877. else
  12878. {
  12879. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12880. }
  12881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12882. isKnowKey = TRUE;
  12883. }
  12884. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12885. {
  12886. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12888. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12889. {
  12890. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12891. }
  12892. else
  12893. {
  12894. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12895. }
  12896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12897. isKnowKey = TRUE;
  12898. }
  12899. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12900. {
  12901. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12903. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12904. {
  12905. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12906. }
  12907. else
  12908. {
  12909. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12910. }
  12911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12912. isKnowKey = TRUE;
  12913. }
  12914. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12915. {
  12916. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12918. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12919. {
  12920. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12921. }
  12922. else
  12923. {
  12924. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12925. }
  12926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12927. isKnowKey = TRUE;
  12928. }
  12929. #if 1
  12930. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12931. {
  12932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12934. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12935. {
  12936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12937. }
  12938. else
  12939. {
  12940. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12941. }
  12942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12943. isKnowKey = TRUE;
  12944. }
  12945. #endif
  12946. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12947. {
  12948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12950. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12951. {
  12952. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12953. }
  12954. else
  12955. {
  12956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12957. }
  12958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12959. isKnowKey = TRUE;
  12960. }
  12961. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12962. {
  12963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12965. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12966. {
  12967. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12968. }
  12969. else
  12970. {
  12971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12972. }
  12973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12974. isKnowKey = TRUE;
  12975. }
  12976. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12977. {
  12978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12980. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12981. {
  12982. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12983. }
  12984. else
  12985. {
  12986. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12987. }
  12988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12989. isKnowKey = TRUE;
  12990. }
  12991. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12992. {
  12993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12995. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12996. {
  12997. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12998. }
  12999. else
  13000. {
  13001. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13002. }
  13003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13004. isKnowKey = TRUE;
  13005. }
  13006. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13007. {
  13008. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13010. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13011. {
  13012. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13013. }
  13014. else
  13015. {
  13016. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13017. }
  13018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13019. isKnowKey = TRUE;
  13020. }
  13021. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13022. {
  13023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13025. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13026. {
  13027. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13028. }
  13029. else
  13030. {
  13031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13032. }
  13033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13034. isKnowKey = TRUE;
  13035. }
  13036. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13037. {
  13038. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13040. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13041. {
  13042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13043. }
  13044. else
  13045. {
  13046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13047. }
  13048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13049. isKnowKey = TRUE;
  13050. }
  13051. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13052. {
  13053. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13055. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13056. {
  13057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13058. }
  13059. else
  13060. {
  13061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13062. }
  13063. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13064. isKnowKey = TRUE;
  13065. }
  13066. //=========================================================
  13067. if(!isEmpty && !isKnowKey)
  13068. {
  13069. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13070. strcpy(unknownkey[UnknownKeynum], keyReq);
  13071. UnknownKeynum = UnknownKeynum + 1;
  13072. }
  13073. }
  13074. void processUnkownKey(void)
  13075. {
  13076. DEBUG_INFO("processUnkownKey...\n");
  13077. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13078. for(int index=0; index < UnknownKeynum; index++)
  13079. {
  13080. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13081. {
  13082. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13083. }
  13084. }
  13085. }
  13086. int setKeyValue(char *key, char *value)
  13087. {
  13088. int isSuccess = NotSupported;
  13089. int check_ascii=0;
  13090. char str[256]={0};
  13091. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13092. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13093. {
  13094. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13095. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13096. {
  13097. strcpy(str, (const char*)value);
  13098. for(int i = 0; str[i]; i++){
  13099. str[i] = tolower(str[i]);
  13100. }
  13101. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13102. isSuccess = ConfigurationStatus_Accepted;
  13103. }
  13104. else
  13105. {
  13106. isSuccess = ConfigurationStatus_Rejected;
  13107. }
  13108. }
  13109. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13110. {
  13111. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13112. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13113. {
  13114. strcpy(str, (const char*)value);
  13115. for(int i = 0; str[i]; i++){
  13116. str[i] = tolower(str[i]);
  13117. }
  13118. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13119. isSuccess = ConfigurationStatus_Accepted;
  13120. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13121. }
  13122. else
  13123. {
  13124. isSuccess = ConfigurationStatus_Rejected;
  13125. }
  13126. }
  13127. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13128. {
  13129. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13130. {
  13131. strcpy(str, (const char*)value);
  13132. for(int i = 0; str[i]; i++)
  13133. {
  13134. str[i] = tolower(str[i]);
  13135. }
  13136. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13137. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13138. isSuccess = ConfigurationStatus_Accepted;
  13139. }
  13140. else
  13141. {
  13142. isSuccess = ConfigurationStatus_Rejected;
  13143. }
  13144. }
  13145. if(strcmp(key, "BlinkRepeat") == 0)
  13146. {
  13147. //Charger.BlinkRepeat = Integer.parseInt(value);
  13148. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13149. {
  13150. check_ascii = value[0];
  13151. if( (check_ascii < 48) || (check_ascii > 57) )
  13152. {
  13153. isSuccess = ConfigurationStatus_Rejected;
  13154. }
  13155. else
  13156. {
  13157. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13158. isSuccess = ConfigurationStatus_Accepted;
  13159. }
  13160. }
  13161. else
  13162. {
  13163. isSuccess = ConfigurationStatus_Rejected;
  13164. }
  13165. }
  13166. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13167. {
  13168. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13169. {
  13170. check_ascii = value[0];
  13171. if( (check_ascii < 48) || (check_ascii > 57) )
  13172. {
  13173. isSuccess = ConfigurationStatus_Rejected;
  13174. }
  13175. else
  13176. {
  13177. if((atoi(value) == 0) || (atoi(value) >= 10))
  13178. {
  13179. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13180. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13181. isSuccess = ConfigurationStatus_Accepted;
  13182. }
  13183. else
  13184. isSuccess = ConfigurationStatus_Rejected;
  13185. }
  13186. }
  13187. else
  13188. {
  13189. isSuccess = ConfigurationStatus_Rejected;
  13190. }
  13191. }
  13192. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13193. {
  13194. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13195. {
  13196. check_ascii = value[0];
  13197. if( (check_ascii < 48) || (check_ascii > 57) )
  13198. {
  13199. isSuccess = ConfigurationStatus_Rejected;
  13200. }
  13201. else
  13202. {
  13203. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13204. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13205. isSuccess = ConfigurationStatus_Accepted;
  13206. }
  13207. }
  13208. else
  13209. {
  13210. isSuccess = ConfigurationStatus_Rejected;
  13211. }
  13212. }
  13213. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13214. {
  13215. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13216. {
  13217. check_ascii = value[0];
  13218. if( (check_ascii < 48) || (check_ascii > 57) )
  13219. {
  13220. isSuccess = ConfigurationStatus_Rejected;
  13221. }
  13222. else
  13223. {
  13224. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13225. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13226. isSuccess = ConfigurationStatus_Accepted;
  13227. }
  13228. }
  13229. else
  13230. {
  13231. isSuccess = ConfigurationStatus_Rejected;
  13232. }
  13233. }
  13234. if(strcmp(key, "HeartbeatInterval") == 0)
  13235. {
  13236. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13237. {
  13238. check_ascii = value[0];
  13239. if( (check_ascii < 48) || (check_ascii > 57) )
  13240. {
  13241. isSuccess = ConfigurationStatus_Rejected;
  13242. }
  13243. else
  13244. {
  13245. if((atoi(value) == 0) || (atoi(value) >= 10))
  13246. {
  13247. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13248. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13249. HeartBeatWaitTime = atoi(value);
  13250. isSuccess = ConfigurationStatus_Accepted;
  13251. }
  13252. else
  13253. {
  13254. isSuccess = ConfigurationStatus_Rejected;
  13255. }
  13256. }
  13257. }
  13258. else
  13259. {
  13260. isSuccess = ConfigurationStatus_Rejected;
  13261. }
  13262. }
  13263. if(strcmp(key, "LightIntensity") == 0)
  13264. {
  13265. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13266. {
  13267. check_ascii = value[0];
  13268. if( (check_ascii < 48) || (check_ascii > 57) )
  13269. {
  13270. isSuccess = ConfigurationStatus_Rejected;
  13271. }
  13272. else
  13273. {
  13274. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13275. isSuccess = ConfigurationStatus_Accepted;
  13276. }
  13277. }
  13278. else
  13279. {
  13280. isSuccess = ConfigurationStatus_Rejected;
  13281. }
  13282. }
  13283. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13284. {
  13285. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13286. {
  13287. strcpy(str, (const char*)value);
  13288. for(int i = 0; str[i]; i++)
  13289. {
  13290. str[i] = tolower(str[i]);
  13291. }
  13292. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13293. isSuccess = ConfigurationStatus_Accepted;
  13294. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13295. }
  13296. else
  13297. {
  13298. isSuccess = ConfigurationStatus_Rejected;
  13299. }
  13300. }
  13301. if(strcmp(key, "LocalPreAuthorize") == 0)
  13302. {
  13303. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13304. {
  13305. strcpy(str, (const char*)value);
  13306. for(int i = 0; str[i]; i++)
  13307. {
  13308. str[i] = tolower(str[i]);
  13309. }
  13310. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13311. isSuccess = ConfigurationStatus_Accepted;
  13312. }
  13313. else
  13314. {
  13315. isSuccess = ConfigurationStatus_Rejected;
  13316. }
  13317. }
  13318. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13319. {
  13320. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13321. {
  13322. check_ascii = value[0];
  13323. if( (check_ascii < 48) || (check_ascii > 57) )
  13324. {
  13325. isSuccess = ConfigurationStatus_Rejected;
  13326. }
  13327. else
  13328. {
  13329. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13330. isSuccess = ConfigurationStatus_Accepted;
  13331. }
  13332. }
  13333. else
  13334. {
  13335. isSuccess = ConfigurationStatus_Rejected;
  13336. }
  13337. }
  13338. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13339. {
  13340. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13341. {
  13342. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13343. isSuccess = ConfigurationStatus_Accepted;
  13344. }
  13345. else
  13346. {
  13347. isSuccess = ConfigurationStatus_Rejected;
  13348. }
  13349. }
  13350. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13351. {
  13352. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13353. {
  13354. check_ascii = value[0];
  13355. if( (check_ascii < 48) || (check_ascii > 57) )
  13356. {
  13357. isSuccess = ConfigurationStatus_Rejected;
  13358. }
  13359. else
  13360. {
  13361. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13362. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13363. isSuccess = ConfigurationStatus_Accepted;
  13364. }
  13365. }
  13366. else
  13367. {
  13368. isSuccess = ConfigurationStatus_Rejected;
  13369. }
  13370. }
  13371. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13372. {
  13373. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13374. {
  13375. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13376. isSuccess = ConfigurationStatus_Accepted;
  13377. }
  13378. else
  13379. {
  13380. isSuccess = ConfigurationStatus_Rejected;
  13381. }
  13382. }
  13383. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13384. {
  13385. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13386. {
  13387. check_ascii = value[0];
  13388. if( (check_ascii < 48) || (check_ascii > 57) )
  13389. {
  13390. isSuccess = ConfigurationStatus_Rejected;
  13391. }
  13392. else
  13393. {
  13394. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13395. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13396. isSuccess = ConfigurationStatus_Accepted;
  13397. }
  13398. }
  13399. else
  13400. {
  13401. isSuccess = ConfigurationStatus_Rejected;
  13402. }
  13403. }
  13404. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13405. {
  13406. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].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. if((atoi(value) == 0) || (atoi(value) >= 10))
  13416. {
  13417. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13418. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13419. isSuccess = ConfigurationStatus_Accepted;
  13420. }
  13421. else
  13422. {
  13423. isSuccess = ConfigurationStatus_Rejected;
  13424. }
  13425. }
  13426. }
  13427. else
  13428. {
  13429. isSuccess = ConfigurationStatus_Rejected;
  13430. }
  13431. }
  13432. if(strcmp(key, "MinimumStatusDuration") == 0)
  13433. {
  13434. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13435. {
  13436. check_ascii = value[0];
  13437. if( (check_ascii < 48) || (check_ascii > 57) )
  13438. {
  13439. isSuccess = ConfigurationStatus_Rejected;
  13440. }
  13441. else
  13442. {
  13443. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13444. {
  13445. isSuccess = ConfigurationStatus_Rejected;
  13446. }
  13447. else
  13448. {
  13449. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13450. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13451. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13452. isSuccess = ConfigurationStatus_Accepted;
  13453. }
  13454. }
  13455. }
  13456. else
  13457. {
  13458. isSuccess = ConfigurationStatus_Rejected;
  13459. }
  13460. }
  13461. if(strcmp(key, "NumberOfConnectors") == 0)
  13462. {
  13463. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13464. {
  13465. check_ascii = value[0];
  13466. if( (check_ascii < 48) || (check_ascii > 57) )
  13467. {
  13468. isSuccess = ConfigurationStatus_Rejected;
  13469. }
  13470. else
  13471. {
  13472. //Charger.ResetRetries = Integer.parseInt(value);
  13473. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13474. isSuccess = ConfigurationStatus_Accepted;
  13475. }
  13476. }
  13477. else
  13478. {
  13479. isSuccess = ConfigurationStatus_Rejected;
  13480. }
  13481. }
  13482. if(strcmp(key, "ResetRetries") == 0)
  13483. {
  13484. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13485. {
  13486. check_ascii = value[0];
  13487. if( (check_ascii < 48) || (check_ascii > 57) )
  13488. {
  13489. isSuccess = ConfigurationStatus_Rejected;
  13490. }
  13491. else
  13492. {
  13493. //Charger.ResetRetries = Integer.parseInt(value);
  13494. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13495. isSuccess = ConfigurationStatus_Accepted;
  13496. }
  13497. }
  13498. else
  13499. {
  13500. isSuccess = ConfigurationStatus_Rejected;
  13501. }
  13502. }
  13503. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13504. {
  13505. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13506. {
  13507. strcpy(str, (const char*)value);
  13508. for(int i = 0; str[i]; i++)
  13509. {
  13510. str[i] = tolower(str[i]);
  13511. }
  13512. if(strcmp(str, "notapplicable")== 0)
  13513. {
  13514. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13515. isSuccess = ConfigurationStatus_Accepted;
  13516. }
  13517. else if(strcmp(str, "unknown")== 0)
  13518. {
  13519. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13520. isSuccess = ConfigurationStatus_Accepted;
  13521. }
  13522. else if(strcmp(str, "rst")== 0)
  13523. {
  13524. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13525. isSuccess = ConfigurationStatus_Accepted;
  13526. }
  13527. else if(strcmp(str, "rts")== 0)
  13528. {
  13529. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13530. isSuccess = ConfigurationStatus_Accepted;
  13531. }
  13532. else if(strcmp(str, "srt")== 0)
  13533. {
  13534. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13535. isSuccess = ConfigurationStatus_Accepted;
  13536. }
  13537. else if(strcmp(str, "str")== 0)
  13538. {
  13539. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13540. isSuccess = ConfigurationStatus_Accepted;
  13541. }
  13542. else if(strcmp(str, "trs")== 0)
  13543. {
  13544. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13545. isSuccess = ConfigurationStatus_Accepted;
  13546. }
  13547. else if(strcmp(str, "tsr")== 0)
  13548. {
  13549. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13550. isSuccess = ConfigurationStatus_Accepted;
  13551. }
  13552. else
  13553. {
  13554. isSuccess = ConfigurationStatus_Rejected;
  13555. }
  13556. }
  13557. else
  13558. {
  13559. isSuccess = ConfigurationStatus_Rejected;
  13560. }
  13561. }
  13562. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13563. {
  13564. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13565. {
  13566. check_ascii = value[0];
  13567. if( (check_ascii < 48) || (check_ascii > 57) )
  13568. {
  13569. isSuccess = ConfigurationStatus_Rejected;
  13570. }
  13571. else
  13572. {
  13573. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13574. isSuccess = ConfigurationStatus_Accepted;
  13575. }
  13576. }
  13577. else
  13578. {
  13579. isSuccess = ConfigurationStatus_Rejected;
  13580. }
  13581. }
  13582. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13583. {
  13584. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13585. {
  13586. strcpy(str, (const char*)value);
  13587. for(int i = 0; str[i]; i++)
  13588. {
  13589. str[i] = tolower(str[i]);
  13590. }
  13591. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13592. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13593. isSuccess = ConfigurationStatus_Accepted;
  13594. }
  13595. else
  13596. {
  13597. isSuccess = ConfigurationStatus_Rejected;
  13598. }
  13599. }
  13600. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13601. {
  13602. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13603. {
  13604. strcpy(str, (const char*)value);
  13605. for(int i = 0; str[i]; i++)
  13606. {
  13607. str[i] = tolower(str[i]);
  13608. }
  13609. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13610. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13611. isSuccess = ConfigurationStatus_Accepted;
  13612. }
  13613. else
  13614. {
  13615. isSuccess = ConfigurationStatus_Rejected;
  13616. }
  13617. }
  13618. if(strcmp(key, "StopTxnAlignedData") == 0)
  13619. {
  13620. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13621. {
  13622. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13623. isSuccess = ConfigurationStatus_Accepted;
  13624. }
  13625. else
  13626. {
  13627. isSuccess = ConfigurationStatus_Rejected;
  13628. }
  13629. }
  13630. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13631. {
  13632. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13633. {
  13634. check_ascii = value[0];
  13635. if( (check_ascii < 48) || (check_ascii > 57) )
  13636. {
  13637. isSuccess = ConfigurationStatus_Rejected;
  13638. }
  13639. else
  13640. {
  13641. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13642. isSuccess = ConfigurationStatus_Accepted;
  13643. }
  13644. }
  13645. else
  13646. {
  13647. isSuccess = ConfigurationStatus_Rejected;
  13648. }
  13649. }
  13650. if(strcmp(key, "StopTxnSampledData") == 0)
  13651. {
  13652. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13653. {
  13654. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13655. isSuccess = ConfigurationStatus_Accepted;
  13656. }
  13657. else
  13658. {
  13659. isSuccess = ConfigurationStatus_Rejected;
  13660. }
  13661. }
  13662. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13663. {
  13664. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13665. {
  13666. check_ascii = value[0];
  13667. if( (check_ascii < 48) || (check_ascii > 57) )
  13668. {
  13669. isSuccess = ConfigurationStatus_Rejected;
  13670. }
  13671. else
  13672. {
  13673. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13674. isSuccess = ConfigurationStatus_Accepted;
  13675. }
  13676. }
  13677. else
  13678. {
  13679. isSuccess = ConfigurationStatus_Rejected;
  13680. }
  13681. }
  13682. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13683. {
  13684. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13685. {
  13686. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13687. isSuccess = ConfigurationStatus_Accepted;
  13688. }
  13689. else
  13690. {
  13691. isSuccess = ConfigurationStatus_Rejected;
  13692. }
  13693. }
  13694. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13695. {
  13696. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13697. {
  13698. check_ascii = value[0];
  13699. if( (check_ascii < 48) || (check_ascii > 57) )
  13700. {
  13701. isSuccess = ConfigurationStatus_Rejected;
  13702. }
  13703. else
  13704. {
  13705. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13706. isSuccess = ConfigurationStatus_Accepted;
  13707. }
  13708. }
  13709. else
  13710. {
  13711. isSuccess = ConfigurationStatus_Rejected;
  13712. }
  13713. }
  13714. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13715. {
  13716. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13717. {
  13718. check_ascii = value[0];
  13719. if( (check_ascii < 48) || (check_ascii > 57) )
  13720. {
  13721. isSuccess = ConfigurationStatus_Rejected;
  13722. }
  13723. else
  13724. {
  13725. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13726. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13727. TransactionMessageAttemptsValue = atoi(value);
  13728. isSuccess = ConfigurationStatus_Accepted;
  13729. }
  13730. }
  13731. else
  13732. {
  13733. isSuccess = ConfigurationStatus_Rejected;
  13734. }
  13735. }
  13736. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13737. {
  13738. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13739. {
  13740. check_ascii = value[0];
  13741. if( (check_ascii < 48) || (check_ascii > 57) )
  13742. {
  13743. isSuccess = ConfigurationStatus_Rejected;
  13744. }
  13745. else
  13746. {
  13747. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13748. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13749. TransactionMessageRetryIntervalValue = atoi(value);
  13750. isSuccess = ConfigurationStatus_Accepted;
  13751. }
  13752. }
  13753. else
  13754. {
  13755. isSuccess = ConfigurationStatus_Rejected;
  13756. }
  13757. }
  13758. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13759. {
  13760. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13761. {
  13762. strcpy(str, (const char*)value);
  13763. for(int i = 0; str[i]; i++)
  13764. {
  13765. str[i] = tolower(str[i]);
  13766. }
  13767. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13768. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13769. isSuccess = ConfigurationStatus_Accepted;
  13770. }
  13771. else
  13772. {
  13773. isSuccess = ConfigurationStatus_Rejected;
  13774. }
  13775. }
  13776. if(strcmp(key, "WebSocketPingInterval") == 0)
  13777. {
  13778. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13779. {
  13780. check_ascii = value[0];
  13781. if( (check_ascii < 48) || (check_ascii > 57) )
  13782. {
  13783. isSuccess = ConfigurationStatus_Rejected;
  13784. }
  13785. else
  13786. {
  13787. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13788. isSuccess = ConfigurationStatus_Accepted;
  13789. }
  13790. }
  13791. else
  13792. {
  13793. isSuccess = ConfigurationStatus_Rejected;
  13794. }
  13795. }
  13796. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13797. {
  13798. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13799. {
  13800. strcpy(str, (const char*)value);
  13801. for(int i = 0; str[i]; i++)
  13802. {
  13803. str[i] = tolower(str[i]);
  13804. }
  13805. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13806. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13807. isSuccess = ConfigurationStatus_Accepted;
  13808. }
  13809. else
  13810. {
  13811. isSuccess = ConfigurationStatus_Rejected;
  13812. }
  13813. }
  13814. if(strcmp(key, "AuthorizationKey") == 0)
  13815. {
  13816. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13817. {
  13818. strcpy(str, (const char*)value);
  13819. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13820. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13821. isSuccess = ConfigurationStatus_Accepted;
  13822. }
  13823. else
  13824. {
  13825. isSuccess = ConfigurationStatus_Rejected;
  13826. }
  13827. }
  13828. if(strcmp(key, "SecurityProfile") == 0)
  13829. {
  13830. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13831. {
  13832. check_ascii = value[0];
  13833. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13834. {
  13835. isSuccess = ConfigurationStatus_Rejected;
  13836. }
  13837. else if(check_ascii == 0x33)
  13838. {
  13839. isSuccess = NotSupported;
  13840. }
  13841. else
  13842. {
  13843. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13844. {
  13845. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13846. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  13847. isSuccess = ConfigurationStatus_Accepted;
  13848. }
  13849. else
  13850. isSuccess = ConfigurationStatus_Rejected;
  13851. }
  13852. }
  13853. else
  13854. {
  13855. isSuccess = ConfigurationStatus_Rejected;
  13856. }
  13857. }
  13858. if(strcmp(key, "DefaultPrice") == 0)
  13859. {
  13860. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13861. {
  13862. strcpy(str, (const char*)value);
  13863. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13864. isSuccess = ConfigurationStatus_Accepted;
  13865. }
  13866. else
  13867. {
  13868. isSuccess = ConfigurationStatus_Rejected;
  13869. }
  13870. }
  13871. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13872. {
  13873. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13874. {
  13875. strcpy(str, (const char*)value);
  13876. for(int i = 0; str[i]; i++)
  13877. {
  13878. str[i] = tolower(str[i]);
  13879. }
  13880. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13881. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13882. isSuccess = ConfigurationStatus_Accepted;
  13883. }
  13884. else
  13885. {
  13886. isSuccess = ConfigurationStatus_Rejected;
  13887. }
  13888. }
  13889. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13890. {
  13891. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13892. {
  13893. strcpy(str, (const char*)value);
  13894. for(int i = 0; str[i]; i++)
  13895. {
  13896. str[i] = tolower(str[i]);
  13897. }
  13898. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13899. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13900. isSuccess = ConfigurationStatus_Accepted;
  13901. }
  13902. else
  13903. {
  13904. isSuccess = ConfigurationStatus_Rejected;
  13905. }
  13906. }
  13907. #if 0
  13908. //For OCPP Test Case
  13909. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13910. {
  13911. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13912. {
  13913. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13914. isSuccess = ConfigurationStatus_Accepted;
  13915. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13916. }
  13917. else
  13918. {
  13919. isSuccess = ConfigurationStatus_Rejected;
  13920. }
  13921. }
  13922. #endif
  13923. #if 1
  13924. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13925. {
  13926. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13927. {
  13928. strcpy(str, (const char*)value);
  13929. for(int i = 0; str[i]; i++)
  13930. {
  13931. str[i] = tolower(str[i]);
  13932. }
  13933. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13934. isSuccess = ConfigurationStatus_Accepted;
  13935. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13936. }
  13937. else
  13938. {
  13939. isSuccess = ConfigurationStatus_Rejected;
  13940. }
  13941. }
  13942. #endif
  13943. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13944. {
  13945. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13946. {
  13947. check_ascii = value[0];
  13948. if( (check_ascii < 48) || (check_ascii > 57) )
  13949. {
  13950. isSuccess = ConfigurationStatus_Rejected;
  13951. }
  13952. else
  13953. {
  13954. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13955. isSuccess = ConfigurationStatus_Accepted;
  13956. }
  13957. }
  13958. else
  13959. {
  13960. isSuccess = ConfigurationStatus_Rejected;
  13961. }
  13962. }
  13963. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13964. {
  13965. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13966. {
  13967. check_ascii = value[0];
  13968. if( (check_ascii < 48) || (check_ascii > 57) )
  13969. {
  13970. isSuccess = ConfigurationStatus_Rejected;
  13971. }
  13972. else
  13973. {
  13974. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13975. isSuccess = ConfigurationStatus_Accepted;
  13976. }
  13977. }
  13978. else
  13979. {
  13980. isSuccess = ConfigurationStatus_Rejected;
  13981. }
  13982. }
  13983. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13984. {
  13985. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13986. {
  13987. strcpy(str, (const char*)value);
  13988. for(int i = 0; str[i]; i++)
  13989. {
  13990. str[i] = tolower(str[i]);
  13991. }
  13992. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13993. isSuccess = ConfigurationStatus_Accepted;
  13994. }
  13995. else
  13996. {
  13997. isSuccess = ConfigurationStatus_Rejected;
  13998. }
  13999. }
  14000. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14001. {
  14002. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14003. {
  14004. check_ascii = value[0];
  14005. if( (check_ascii < 48) || (check_ascii > 57) )
  14006. {
  14007. isSuccess = ConfigurationStatus_Rejected;
  14008. }
  14009. else
  14010. {
  14011. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14012. isSuccess = ConfigurationStatus_Accepted;
  14013. }
  14014. }
  14015. else
  14016. {
  14017. isSuccess = ConfigurationStatus_Rejected;
  14018. }
  14019. }
  14020. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14021. {
  14022. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14023. {
  14024. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14025. isSuccess = ConfigurationStatus_Accepted;
  14026. }
  14027. else
  14028. {
  14029. isSuccess = ConfigurationStatus_Rejected;
  14030. }
  14031. }
  14032. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14033. {
  14034. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14035. {
  14036. check_ascii = value[0];
  14037. if( (check_ascii < 48) || (check_ascii > 57) )
  14038. {
  14039. isSuccess = ConfigurationStatus_Rejected;
  14040. }
  14041. else
  14042. {
  14043. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14044. isSuccess = ConfigurationStatus_Accepted;
  14045. }
  14046. }
  14047. else
  14048. {
  14049. isSuccess = ConfigurationStatus_Rejected;
  14050. }
  14051. }
  14052. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14053. {
  14054. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14055. {
  14056. strcpy(str, (const char*)value);
  14057. for(int i = 0; str[i]; i++)
  14058. {
  14059. str[i] = tolower(str[i]);
  14060. }
  14061. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14062. isSuccess = ConfigurationStatus_Accepted;
  14063. }
  14064. else
  14065. {
  14066. isSuccess = ConfigurationStatus_Rejected;
  14067. }
  14068. }
  14069. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14070. {
  14071. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14072. {
  14073. check_ascii = value[0];
  14074. if( (check_ascii < 48) || (check_ascii > 57) )
  14075. {
  14076. isSuccess = ConfigurationStatus_Rejected;
  14077. }
  14078. else
  14079. {
  14080. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14081. isSuccess = ConfigurationStatus_Accepted;
  14082. }
  14083. }
  14084. else
  14085. {
  14086. isSuccess = ConfigurationStatus_Rejected;
  14087. }
  14088. }
  14089. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14090. return isSuccess;
  14091. }
  14092. int TransactionMessageAttemptsGet(void)
  14093. {
  14094. return TransactionMessageAttemptsValue;
  14095. }
  14096. int FirstHeartBeatResponse(void)
  14097. {
  14098. return FirstHeartBeat;
  14099. }
  14100. int TransactionMessageRetryIntervalGet(void)
  14101. {
  14102. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14103. }
  14104. int ReadHttpStatus(int sock)
  14105. {
  14106. //char c;
  14107. char buff[1024]="",*ptr=buff+1;
  14108. int bytes_received, status;
  14109. DEBUG_INFO("Begin Response ..\n");
  14110. while((bytes_received = recv(sock, ptr, 1, 0))){
  14111. if(bytes_received==-1){
  14112. perror("ReadHttpStatus");
  14113. exit(1);
  14114. }
  14115. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14116. ptr++;
  14117. }
  14118. *ptr=0;
  14119. ptr=buff+1;
  14120. sscanf(ptr,"%*s %d ", &status);
  14121. DEBUG_INFO("%s\n",ptr);
  14122. DEBUG_INFO("status=%d\n",status);
  14123. DEBUG_INFO("End Response ..\n");
  14124. return (bytes_received>0)?status:0;
  14125. }
  14126. //the only filed that it parsed is 'Content-Length'
  14127. int ParseHeader(int sock)
  14128. {
  14129. //char c;
  14130. char buff[1024]="",*ptr=buff+4;
  14131. int bytes_received;
  14132. DEBUG_INFO("Begin HEADER ..\n");
  14133. while((bytes_received = recv(sock, ptr, 1, 0))){
  14134. if(bytes_received==-1){
  14135. perror("Parse Header");
  14136. exit(1);
  14137. }
  14138. if(
  14139. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14140. (ptr[-1]=='\r') && (*ptr=='\n' )
  14141. ) break;
  14142. ptr++;
  14143. }
  14144. *ptr=0;
  14145. ptr=buff+4;
  14146. //printf("%s",ptr);
  14147. if(bytes_received){
  14148. ptr=strstr(ptr,"Content-Length:");
  14149. if(ptr){
  14150. sscanf(ptr,"%*s %d",&bytes_received);
  14151. }else
  14152. bytes_received=-1; //unknown size
  14153. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14154. }
  14155. DEBUG_INFO("End HEADER ..\n");
  14156. return bytes_received ;
  14157. }
  14158. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14159. {
  14160. int result = TRUE;
  14161. char rmFileCmd[100]={0};
  14162. char FilePath[100]={0};
  14163. char ftpbuf[200];
  14164. int systemresult;
  14165. //DEBUG_INFO("filename=%s\n",filename);
  14166. //DEBUG_INFO("url=%s\n",url);
  14167. sprintf(FilePath,"/mnt/%s",filename);
  14168. system("ping 8.8.8.8 &");
  14169. if((access(FilePath,F_OK))!=-1)
  14170. {
  14171. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14172. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14173. system(rmFileCmd);
  14174. }
  14175. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14176. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14177. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14178. systemresult = system(ftpbuf);
  14179. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14180. if(systemresult != 0)
  14181. {
  14182. DEBUG_INFO("http DownLoad error!\n");
  14183. result = FALSE;
  14184. }
  14185. system("pkill ping");
  14186. return result;
  14187. }
  14188. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14189. {
  14190. int result = TRUE;
  14191. char rmFileCmd[100]={0};
  14192. char FilePath[100]={0};
  14193. char ftpbuf[200];
  14194. int systemresult;
  14195. //char temp[100];
  14196. sprintf(FilePath,"/mnt/%s",filename);
  14197. system("ping 8.8.8.8 &");
  14198. if((access(FilePath,F_OK))!=-1)
  14199. {
  14200. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14201. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14202. system(rmFileCmd);
  14203. }
  14204. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14205. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14206. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14207. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14208. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14209. systemresult = system(ftpbuf);
  14210. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14211. if(systemresult != 0)
  14212. {
  14213. printf("wget error!\n");
  14214. result = FALSE;
  14215. }
  14216. system("pkill ping");
  14217. return result;
  14218. }
  14219. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14220. {
  14221. char rmFileCmd[100]={0};
  14222. char FilePath[100]={0};
  14223. char buf[512];
  14224. int systemresult = 0;
  14225. //DEBUG_INFO("filename=%s\n",filename);
  14226. //DEBUG_INFO("url=%s\n",url);
  14227. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14228. if((access(FilePath,F_OK))!=-1)
  14229. {
  14230. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14231. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14232. system(rmFileCmd);
  14233. }
  14234. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14235. if(fp == NULL)
  14236. {
  14237. DEBUG_INFO("log is NULL\n");
  14238. return FALSE;
  14239. }
  14240. else
  14241. {
  14242. fprintf(fp, "%s\n", url);
  14243. fprintf(fp, "%s\n", filename);
  14244. fclose(fp);
  14245. }
  14246. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14247. if(phpFP == NULL)
  14248. {
  14249. DEBUG_INFO("PHP upload fail.\n");
  14250. return FALSE;
  14251. }
  14252. else
  14253. {
  14254. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14255. {
  14256. if(strstr(buf, "result") != NULL)
  14257. {
  14258. sscanf(buf, "result: %d", &systemresult);
  14259. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14260. }
  14261. }
  14262. pclose(phpFP);
  14263. }
  14264. if(systemresult != 1)
  14265. {
  14266. DEBUG_INFO("HTTP upload error!\n");
  14267. return FALSE;
  14268. }
  14269. return TRUE;
  14270. }
  14271. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14272. {
  14273. struct hostent* server;
  14274. char *IPbuffer;
  14275. char ftpbuf[200];
  14276. int systemresult;
  14277. // To retrieve host information
  14278. server = gethostbyname(location);
  14279. // To convert an Internet network
  14280. // address into ASCII string
  14281. IPbuffer = inet_ntoa(*((struct in_addr*)
  14282. server->h_addr_list[0]));
  14283. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14284. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14285. /* format : ftpput -u username -p passwd IP target source*/
  14286. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14287. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14288. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14289. systemresult = system(ftpbuf);
  14290. DEBUG_INFO("systemresult=%d\n",systemresult);
  14291. if(systemresult != 0)
  14292. {
  14293. DEBUG_INFO("ftpput error!\n");
  14294. return FALSE;
  14295. }
  14296. return TRUE;
  14297. }
  14298. int GetOcppServerURL()
  14299. {
  14300. int result = FALSE;
  14301. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14302. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14303. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14304. struct yuarel url;
  14305. char urlStr[512];
  14306. // OCPPPH only
  14307. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  14308. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14309. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  14310. {
  14311. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  14312. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14313. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14314. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  14315. if(yuarel_parse(&url, urlStr) != -1)
  14316. {
  14317. sprintf(OcppProtocol, "%s", url.scheme);
  14318. sprintf(OcppHost, "%s", url.host);
  14319. if(url.path == NULL)
  14320. OcppTempPath[0] = '\0';
  14321. else
  14322. sprintf(OcppTempPath, "%s", url.path);
  14323. if(url.port == 0)
  14324. {
  14325. if(strcmp(OcppProtocol, "wss") == 0)
  14326. OcppPort = 443;
  14327. else
  14328. OcppPort = 80;
  14329. }
  14330. else
  14331. OcppPort = url.port;
  14332. result = TRUE;
  14333. }
  14334. }
  14335. else
  14336. {
  14337. strcpy(OcppHost,"");
  14338. }
  14339. return result;
  14340. }
  14341. int GetOcppPath()
  14342. {
  14343. int result = FALSE;
  14344. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  14345. {
  14346. if(OcppTempPath == NULL)
  14347. {
  14348. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  14349. }
  14350. else
  14351. {
  14352. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  14353. }
  14354. result = TRUE;
  14355. goto End;
  14356. }
  14357. else
  14358. {
  14359. strcpy(OcppPath,"");
  14360. }
  14361. End:
  14362. return result;
  14363. }
  14364. int GetOcppPort()
  14365. {
  14366. return OcppPort;
  14367. }
  14368. int GetOcppConnStatus(void)
  14369. {
  14370. return ShmOCPP16DataPH->OcppConnStatus;
  14371. }
  14372. void SetOcppConnStatus(uint8_t status)
  14373. {
  14374. ShmOCPP16DataPH->OcppConnStatus = status;
  14375. }
  14376. int GetHeartBeatWithNOResponse(void)
  14377. {
  14378. return HeartBeatWithNOResponse;
  14379. }
  14380. void SetHeartBeatWithNOResponse(void)
  14381. {
  14382. HeartBeatWithNOResponse = 0;
  14383. }
  14384. void GetStartTransactionIdTag(int gun_index)
  14385. {
  14386. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14387. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14388. }
  14389. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14390. {
  14391. char ch;
  14392. FILE *fptr1;
  14393. int temptransactionId;
  14394. char str[100]={0};
  14395. temptransactionId = 0;
  14396. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14397. {
  14398. DEBUG_INFO("IdTag is empty.\n");
  14399. return temptransactionId;
  14400. }
  14401. /*------ Read the file ----------------*/
  14402. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  14403. if (!fptr1)
  14404. {
  14405. DEBUG_INFO("QueueTransactionId file open error.\n");
  14406. //printf(" File not found or unable to open the input file!!\n");
  14407. return temptransactionId;
  14408. }
  14409. ch=fgetc(fptr1);
  14410. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  14411. rewind(fptr1);
  14412. if(ch!=EOF)
  14413. {
  14414. // printf("%c",ch);
  14415. while (fgets(str, 100, fptr1) != NULL)
  14416. {
  14417. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14418. if(str[0]=='\0')
  14419. {
  14420. break;
  14421. }
  14422. char *revbuf[8] = {0}; // Variable store string split
  14423. int num = 0;// Quantity after string split
  14424. DEBUG_INFO("Transaction queue data= %s\n", str);
  14425. splitstring(str,",",revbuf,&num); // String split
  14426. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14427. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14428. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14429. DEBUG_INFO("------------------------------\n");
  14430. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14431. {
  14432. if(isStopTransaction)
  14433. {
  14434. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14435. {
  14436. temptransactionId = atoi(revbuf[2]);
  14437. //break;
  14438. }
  14439. }
  14440. else
  14441. {
  14442. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14443. {
  14444. temptransactionId = atoi(revbuf[2]);
  14445. //break;
  14446. }
  14447. }
  14448. }
  14449. }
  14450. }
  14451. else
  14452. DEBUG_INFO("EOF\n");
  14453. fclose(fptr1);
  14454. /*------- End of reading ---------------*/
  14455. return temptransactionId;
  14456. }
  14457. void SetTransactionIdZero(int transactionId)
  14458. {
  14459. char ch;
  14460. FILE *fptr1, *fptr2;
  14461. int temptransactionId = 0;
  14462. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  14463. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  14464. if (!fptr1)
  14465. {
  14466. //printf(" File not found or unable to open the input file!!\n");
  14467. return ;
  14468. }
  14469. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14470. if (!fptr2)
  14471. {
  14472. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14473. fclose(fptr1);
  14474. return ;
  14475. }
  14476. ch=fgetc(fptr1);
  14477. rewind(fptr1);
  14478. if(ch!=EOF)
  14479. {
  14480. // copy all contents to the temporary file except the specific line
  14481. while (fgets(str, 100, fptr1) != NULL)
  14482. {
  14483. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14484. if(str[0]=='\0')
  14485. {
  14486. break;
  14487. }
  14488. char *revbuf[8] = {0};
  14489. int num = 0;
  14490. strcpy(strtemp, str);
  14491. splitstring(str,",",revbuf,&num);
  14492. if(revbuf[2][0] != '\0')
  14493. {
  14494. temptransactionId = atoi(revbuf[2]);
  14495. if(transactionId != temptransactionId)
  14496. {
  14497. fprintf(fptr2, "%s\n", strtemp);
  14498. }
  14499. }
  14500. }
  14501. }
  14502. fclose(fptr1);
  14503. fclose(fptr2);
  14504. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  14505. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  14506. /*------ Read the file ----------------*/
  14507. }
  14508. int InternetDisconnect(void)
  14509. {
  14510. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14511. }
  14512. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14513. void storeTempStopTransaction(int gun_index)
  14514. {
  14515. char guid[37]={0};
  14516. int tempIndex = 0;
  14517. char TempStopTransaction[256];
  14518. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  14519. DEBUG_INFO("storeTempStopTransaction...\n");
  14520. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14521. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  14522. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14523. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14524. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14525. {
  14526. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14527. {
  14528. tempIndex = ((gun_index==2) ? 1: 0);
  14529. }
  14530. else
  14531. {
  14532. tempIndex = gun_index;
  14533. }
  14534. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14535. {
  14536. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14537. {
  14538. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14539. }
  14540. }// END OF CHAdeMO_QUANTITY
  14541. }
  14542. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14543. {
  14544. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14545. {
  14546. tempIndex = ((gun_index==2) ? 1: 0);
  14547. }
  14548. else
  14549. {
  14550. tempIndex = gun_index;
  14551. }
  14552. for (int index = 0; index < CCS_QUANTITY; index++)
  14553. {
  14554. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14555. {
  14556. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14557. }
  14558. }// END OF CCS_QUANTITY
  14559. }
  14560. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14561. {
  14562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14563. {
  14564. tempIndex = ((gun_index==2) ? 1: 0);
  14565. }
  14566. else
  14567. {
  14568. tempIndex = gun_index;
  14569. }
  14570. for (int index = 0; index < GB_QUANTITY; index++)
  14571. {
  14572. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14573. {
  14574. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14575. }
  14576. }// END OF GB_QUANTITY
  14577. }
  14578. else if(gunType[gun_index] == GUN_TYPE_DO)
  14579. {
  14580. tempIndex = gun_index;
  14581. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14582. {
  14583. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14584. {
  14585. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14586. }
  14587. }
  14588. }
  14589. else
  14590. {
  14591. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14592. {
  14593. tempIndex = 2;
  14594. }
  14595. else
  14596. {
  14597. tempIndex = gun_index;
  14598. }
  14599. for (int index = 0; index < AC_QUANTITY; index++)
  14600. {
  14601. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14602. {
  14603. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14604. }
  14605. }// END OF AC_QUANTITY
  14606. }
  14607. //Stop Transaction Time
  14608. struct timeval tmnow;
  14609. struct tm *tm;
  14610. char buf[28];//, usec_buf[6];
  14611. gettimeofday(&tmnow, NULL);
  14612. time_t t;
  14613. t = time(NULL);
  14614. /*UTC time and date*/
  14615. tm = gmtime(&t);
  14616. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14617. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  14618. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  14619. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14620. random_uuid(guid);
  14621. /***********************************transactionData******************************************************/
  14622. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14624. //=================================
  14625. //1. Transaction_Begin
  14626. //=================================
  14627. //============================== Energy.Active.Import.Interval ===========================================
  14628. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14629. {
  14630. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14631. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14632. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14633. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  14634. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14635. 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))
  14636. {
  14637. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14638. }
  14639. else
  14640. {
  14641. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14642. }
  14643. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14644. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14645. }
  14646. //=================================
  14647. //2. Transaction_End
  14648. //=================================
  14649. //2.1====================================== Current.Import L1 ==============================================
  14650. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14651. {
  14652. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14653. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14654. {
  14655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14656. {
  14657. tempIndex = ((gun_index==2) ? 1: 0);
  14658. }
  14659. else
  14660. {
  14661. tempIndex = gun_index;
  14662. }
  14663. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14664. {
  14665. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14666. {
  14667. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14668. }
  14669. }// End of for CHAdeMO_QUANTITY
  14670. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14671. }
  14672. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14673. {
  14674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14675. {
  14676. tempIndex = ((gun_index==2) ? 1: 0);
  14677. }
  14678. else
  14679. {
  14680. tempIndex = gun_index;
  14681. }
  14682. for (int index = 0; index < CCS_QUANTITY; index++)
  14683. {
  14684. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14685. {
  14686. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14687. }
  14688. }// End of for CCS_QUANTITY
  14689. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14690. }
  14691. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14692. {
  14693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14694. {
  14695. tempIndex = ((gun_index==2) ? 1: 0);
  14696. }
  14697. else
  14698. {
  14699. tempIndex = gun_index;
  14700. }
  14701. for (int index = 0; index < GB_QUANTITY; index++)
  14702. {
  14703. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14704. {
  14705. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14706. }
  14707. }// End of for GB_QUANTITY
  14708. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14709. }
  14710. else if(gunType[gun_index] == GUN_TYPE_DO)
  14711. {
  14712. tempIndex = gun_index;
  14713. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14714. {
  14715. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14716. {
  14717. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14718. }
  14719. }
  14720. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14721. }
  14722. else
  14723. {
  14724. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14725. {
  14726. tempIndex = 2;
  14727. }
  14728. else
  14729. {
  14730. tempIndex = gun_index;
  14731. }
  14732. for (int index = 0; index < AC_QUANTITY; index++)
  14733. {
  14734. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14735. {
  14736. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14737. }
  14738. }// End of for AC_QUANTITY
  14739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14740. }
  14741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14742. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14744. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14746. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14747. }
  14748. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14749. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14750. {
  14751. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14752. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14753. {
  14754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14755. {
  14756. tempIndex = ((gun_index==2) ? 1: 0);
  14757. }
  14758. else
  14759. {
  14760. tempIndex = gun_index;
  14761. }
  14762. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14763. {
  14764. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14765. {
  14766. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14767. }
  14768. }// END OF CHAdeMO_QUANTITY
  14769. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14770. }
  14771. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14772. {
  14773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14774. {
  14775. tempIndex = ((gun_index==2) ? 1: 0);
  14776. }
  14777. else
  14778. {
  14779. tempIndex = gun_index;
  14780. }
  14781. for (int index = 0; index < CCS_QUANTITY; index++)
  14782. {
  14783. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14784. {
  14785. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14786. }
  14787. }// END OF CCS_QUANTITY
  14788. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14789. }
  14790. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14791. {
  14792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14793. {
  14794. tempIndex = ((gun_index==2) ? 1: 0);
  14795. }
  14796. else
  14797. {
  14798. tempIndex = gun_index;
  14799. }
  14800. for (int index = 0; index < GB_QUANTITY; index++)
  14801. {
  14802. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14803. {
  14804. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14805. }
  14806. }// END OF GB_QUANTITY
  14807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14808. }
  14809. else if(gunType[gun_index] == GUN_TYPE_DO)
  14810. {
  14811. tempIndex = gun_index;
  14812. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14813. {
  14814. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14815. {
  14816. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14817. }
  14818. }
  14819. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14820. }
  14821. else
  14822. {
  14823. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14824. {
  14825. tempIndex = 2;
  14826. }
  14827. else
  14828. {
  14829. tempIndex = gun_index;
  14830. }
  14831. for (int index = 0; index < AC_QUANTITY; index++)
  14832. {
  14833. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14834. {
  14835. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14836. }
  14837. }// END OF AC_QUANTITY
  14838. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14839. }
  14840. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14841. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14842. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14843. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14844. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14845. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14846. }
  14847. //2.3====================================== Power.Active.Import =========================================
  14848. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14849. {
  14850. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14851. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14852. {
  14853. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14854. {
  14855. tempIndex = ((gun_index==2) ? 1: 0);
  14856. }
  14857. else
  14858. {
  14859. tempIndex = gun_index;
  14860. }
  14861. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14862. {
  14863. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14864. {
  14865. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14866. }
  14867. } // End for CHAdeMO_QUANTITY
  14868. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14869. }
  14870. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14871. {
  14872. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14873. {
  14874. tempIndex = ((gun_index==2) ? 1: 0);
  14875. }
  14876. else
  14877. {
  14878. tempIndex = gun_index;
  14879. }
  14880. for (int index = 0; index < CCS_QUANTITY; index++)
  14881. {
  14882. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14883. {
  14884. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14885. }
  14886. } // END for CCS_QUANTITY
  14887. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14888. }
  14889. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14890. {
  14891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14892. {
  14893. tempIndex = ((gun_index==2) ? 1: 0);
  14894. }
  14895. else
  14896. {
  14897. tempIndex = gun_index;
  14898. }
  14899. for (int index = 0; index < GB_QUANTITY; index++)
  14900. {
  14901. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14902. {
  14903. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14904. }
  14905. }// END for GB_QUANTITY
  14906. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14907. }
  14908. else if(gunType[gun_index] == GUN_TYPE_DO)
  14909. {
  14910. tempIndex = gun_index;
  14911. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14912. {
  14913. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14914. {
  14915. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14916. }
  14917. }
  14918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14919. }
  14920. else
  14921. {
  14922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14923. {
  14924. tempIndex = 2;
  14925. }
  14926. else
  14927. {
  14928. tempIndex = gun_index;
  14929. }
  14930. for (int index = 0; index < AC_QUANTITY; index++)
  14931. {
  14932. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14933. {
  14934. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14935. }
  14936. } // END for AC_QUANTITY
  14937. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14938. }
  14939. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14941. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14942. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14944. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14945. }
  14946. //2.4====================================== Voltage L1 ====================================================
  14947. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14948. {
  14949. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14950. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14951. {
  14952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14953. {
  14954. tempIndex = ((gun_index==2) ? 1: 0);
  14955. }
  14956. else
  14957. {
  14958. tempIndex = gun_index;
  14959. }
  14960. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14961. {
  14962. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14963. {
  14964. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14965. }
  14966. } // END OF FOR CHAdeMO_QUANTITY
  14967. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14968. }
  14969. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14970. {
  14971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14972. {
  14973. tempIndex = ((gun_index==2) ? 1: 0);
  14974. }
  14975. else
  14976. {
  14977. tempIndex = gun_index;
  14978. }
  14979. for (int index = 0; index < CCS_QUANTITY; index++)
  14980. {
  14981. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14982. {
  14983. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14984. }
  14985. } // END OF FOR CCS_QUANTITY
  14986. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14987. }
  14988. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14989. {
  14990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14991. {
  14992. tempIndex = ((gun_index==2) ? 1: 0);
  14993. }
  14994. else
  14995. {
  14996. tempIndex = gun_index;
  14997. }
  14998. for (int index = 0; index < GB_QUANTITY; index++)
  14999. {
  15000. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15001. {
  15002. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15003. }
  15004. } // END OF FOR GB_QUANTITY
  15005. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15006. }
  15007. else if(gunType[gun_index] == GUN_TYPE_DO)
  15008. {
  15009. tempIndex = gun_index;
  15010. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15011. {
  15012. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15013. {
  15014. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15015. }
  15016. }
  15017. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15018. }
  15019. else
  15020. {
  15021. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15022. {
  15023. tempIndex = 2;
  15024. }
  15025. else
  15026. {
  15027. tempIndex = gun_index;
  15028. }
  15029. for (int index = 0; index < AC_QUANTITY; index++)
  15030. {
  15031. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15032. {
  15033. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15034. }
  15035. } // END OF FOR AC_QUANTITY
  15036. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15037. }
  15038. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15039. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15040. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15041. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15042. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15043. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15044. }
  15045. //2.5============================================== End SoC =========================================================
  15046. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15047. {
  15048. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15049. 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))
  15050. {
  15051. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15052. {
  15053. tempIndex = ((gun_index==2) ? 1: 0);
  15054. }
  15055. else
  15056. {
  15057. tempIndex = gun_index;
  15058. }
  15059. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15060. {
  15061. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15062. {
  15063. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15064. {
  15065. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15066. }
  15067. }
  15068. }
  15069. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15070. {
  15071. for (int index = 0; index < CCS_QUANTITY; index++)
  15072. {
  15073. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15074. {
  15075. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15076. }
  15077. }
  15078. }
  15079. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15080. {
  15081. for (int index = 0; index < GB_QUANTITY; index++)
  15082. {
  15083. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15084. {
  15085. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15086. }
  15087. }
  15088. }
  15089. else if(gunType[gun_index] == GUN_TYPE_DO)
  15090. {
  15091. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15092. {
  15093. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15094. {
  15095. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15096. }
  15097. }
  15098. }
  15099. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15100. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15101. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15102. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15103. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15104. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15105. } // END FOR DC CASE
  15106. }
  15107. //2.6====================================== Current.Import L2 ==============================================
  15108. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15109. {
  15110. // AC 3 phase L2 current
  15111. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15112. {
  15113. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15114. {
  15115. tempIndex = 2;
  15116. }
  15117. else
  15118. {
  15119. tempIndex = gun_index;
  15120. }
  15121. for (int index = 0; index < AC_QUANTITY; index++)
  15122. {
  15123. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15124. {
  15125. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15126. }
  15127. }// End of for AC_QUANTITY
  15128. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15129. }
  15130. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15131. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15132. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15133. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15134. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15135. }
  15136. //2.7====================================== Current.Import L3 ==============================================
  15137. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15138. {
  15139. // AC 3 phase L3 current
  15140. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15141. {
  15142. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15143. {
  15144. tempIndex = 2;
  15145. }
  15146. else
  15147. {
  15148. tempIndex = gun_index;
  15149. }
  15150. for (int index = 0; index < AC_QUANTITY; index++)
  15151. {
  15152. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15153. {
  15154. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15155. }
  15156. }// End of for AC_QUANTITY
  15157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15158. }
  15159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15160. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15161. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15162. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15163. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15164. }
  15165. //2.9====================================== Voltage L2 ====================================================
  15166. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15167. {
  15168. // AC 3 phase L2 volatge
  15169. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15170. {
  15171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15172. {
  15173. tempIndex = 2;
  15174. }
  15175. else
  15176. {
  15177. tempIndex = gun_index;
  15178. }
  15179. for (int index = 0; index < AC_QUANTITY; index++)
  15180. {
  15181. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15182. {
  15183. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15184. }
  15185. } // END OF FOR AC_QUANTITY
  15186. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15187. }
  15188. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15189. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15190. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15191. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15192. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15193. }
  15194. //2.10====================================== Voltage L3 ====================================================
  15195. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15196. {
  15197. // AC 3 phase L3 volatge
  15198. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15199. {
  15200. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15201. {
  15202. tempIndex = 2;
  15203. }
  15204. else
  15205. {
  15206. tempIndex = gun_index;
  15207. }
  15208. for (int index = 0; index < AC_QUANTITY; index++)
  15209. {
  15210. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15211. {
  15212. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15213. }
  15214. } // END OF FOR AC_QUANTITY
  15215. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15216. }
  15217. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15220. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15221. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15222. }
  15223. //====================== Start SoC ================================
  15224. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15225. {
  15226. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15227. 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))
  15228. {
  15229. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15230. {
  15231. tempIndex = ((gun_index==2) ? 1: 0);
  15232. }
  15233. else
  15234. {
  15235. tempIndex = gun_index;
  15236. }
  15237. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15238. {
  15239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15240. {
  15241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15242. {
  15243. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15244. }
  15245. }
  15246. }
  15247. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15248. {
  15249. for (int index = 0; index < CCS_QUANTITY; index++)
  15250. {
  15251. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15252. {
  15253. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15254. }
  15255. }
  15256. }
  15257. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15258. {
  15259. for (int index = 0; index < GB_QUANTITY; index++)
  15260. {
  15261. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15262. {
  15263. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15264. }
  15265. }
  15266. }
  15267. else if(gunType[gun_index] == GUN_TYPE_DO)
  15268. {
  15269. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15270. {
  15271. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15272. {
  15273. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15274. }
  15275. }
  15276. }
  15277. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15280. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15282. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15283. } // END FOR DC CASE
  15284. }
  15285. //======================================== Message create ==============================================
  15286. json_object *StopTransaction = json_object_new_object();
  15287. json_object *transactionDatas = json_object_new_array();
  15288. json_object *sampledValues = json_object_new_array();
  15289. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  15290. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  15291. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  15292. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  15293. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  15294. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15295. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  15296. {
  15297. json_object *transactionData = json_object_new_object();
  15298. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15299. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15300. {
  15301. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15302. {
  15303. json_object *sampledValue = json_object_new_object();
  15304. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15305. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15306. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15307. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15308. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15309. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15310. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15311. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15312. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15313. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15314. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15315. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15316. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15317. json_object_array_add(sampledValues, sampledValue);
  15318. }
  15319. }
  15320. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15321. json_object_array_add(transactionDatas, transactionData);
  15322. }
  15323. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15324. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15325. ,MESSAGE_TYPE_CALL
  15326. ,guid
  15327. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15328. json_object_put(StopTransaction);
  15329. // Check File "TempStopTransaction" Exist
  15330. if((access(TempStopTransaction,F_OK))!=-1)
  15331. {
  15332. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15333. fclose(fopen(TempStopTransaction, "w"));
  15334. }
  15335. else
  15336. {
  15337. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15338. FILE *log = fopen(TempStopTransaction, "w+");
  15339. if(log == NULL)
  15340. {
  15341. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15342. return ;
  15343. }
  15344. else
  15345. {
  15346. fclose(log);
  15347. }
  15348. }
  15349. //Add TempStopTransaction | Update TempStopTransaction
  15350. // open file for writing
  15351. FILE *outfile;
  15352. outfile = fopen (TempStopTransaction, "a");
  15353. //DEBUG_INFO("data = %s\n", queuedata);
  15354. fputs(queuedata, outfile);
  15355. fputs("\n", outfile);
  15356. fclose (outfile);
  15357. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15358. }
  15359. void checkTempStopTransaction(int gun_index)
  15360. {
  15361. FILE *fptr1;
  15362. char ch;
  15363. char str[QUEUE_MESSAGE_LENGTH]={0};
  15364. char guid[37]={0};
  15365. char tempdata[65]={0};
  15366. char connectorStr[2]={0};
  15367. char TempStopTransaction[256];
  15368. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15369. fptr1 = fopen(TempStopTransaction, "r");
  15370. //TempStopTransaction格式: 槍號,StopTransaction封包
  15371. if (!fptr1)
  15372. {
  15373. //printf(" File not found or unable to open the input file!!\n");
  15374. return ;
  15375. }
  15376. ch=fgetc(fptr1);
  15377. //printf(" Now the content of the file %s is : \n",fname);
  15378. rewind(fptr1);
  15379. if(ch!=EOF)
  15380. {
  15381. // copy all contents to the temporary file except the specific line
  15382. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15383. {
  15384. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15385. if(str[0]=='\0')
  15386. {
  15387. break;
  15388. }
  15389. //TempStopTransaction格式: 槍號,StopTransaction封包
  15390. strncpy(connectorStr, str, 1);
  15391. if(atoi(connectorStr) != (gun_index+1))
  15392. {
  15393. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15394. fclose(fptr1);
  15395. return ;
  15396. }
  15397. //random_uuid(guid);
  15398. strncpy(guid, str+6, 36); //copy guid
  15399. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15400. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15401. {
  15402. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15403. }
  15404. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15405. OCPP_insert_transaction_msg(NO, str);
  15406. memset(str,0,ARRAY_SIZE(str));
  15407. }
  15408. }
  15409. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15410. fclose(fptr1);
  15411. remove(TempStopTransaction); // remove the original file
  15412. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15413. }
  15414. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15415. {
  15416. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15417. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15418. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15419. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15420. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15421. }
  15422. int GetWebSocketPingInterval(void)
  15423. {
  15424. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15425. }
  15426. int GetServerSign(void)
  15427. {
  15428. return server_sign;
  15429. }
  15430. uint8_t GetOcppSecurityProfile()
  15431. {
  15432. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15433. }
  15434. void GetOcppChargerBoxId(uint8_t *data)
  15435. {
  15436. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  15437. }
  15438. void GetOcppSecurityPassword(uint8_t *data)
  15439. {
  15440. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15441. }
  15442. void SetOcppVersion(uint8_t *version)
  15443. {
  15444. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15445. DEBUG_INFO("ocpp version: %s\n", version);
  15446. if(strstr((char*)version, "ocpp1.6") != NULL)
  15447. {
  15448. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15449. }
  15450. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15451. {
  15452. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15453. system("pkill OcppBackend");
  15454. }
  15455. }
  15456. void SetServerSign(int value)
  15457. {
  15458. server_sign = value;
  15459. }
  15460. int GetBootNotificationInterval(void)
  15461. {
  15462. return BootNotificationInterval;
  15463. }
  15464. int GetInternetConn(void)
  15465. {
  15466. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15467. }
  15468. int GetBackendConnectionTimeout(void)
  15469. {
  15470. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15471. }
  15472. int isConnectorInitMode(int gun_index)
  15473. {
  15474. int tempIndex = 0;
  15475. int result = TRUE;
  15476. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15477. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15478. {
  15479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15480. {
  15481. tempIndex = ((gun_index==2) ? 1: 0);
  15482. }
  15483. else
  15484. {
  15485. tempIndex = gun_index;
  15486. }
  15487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15488. {
  15489. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15490. {
  15491. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15492. } //end of the same index
  15493. }//end of for CHAdeMO_QUANTITY
  15494. }
  15495. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15496. {
  15497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15498. {
  15499. tempIndex = ((gun_index==2) ? 1: 0);
  15500. }
  15501. else
  15502. {
  15503. tempIndex = gun_index;
  15504. }
  15505. for (int index = 0; index < CCS_QUANTITY; index++)
  15506. {
  15507. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15508. {
  15509. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15510. } //end of the same index
  15511. } // end of for CCS_QUANTITY
  15512. }
  15513. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15514. {
  15515. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15516. {
  15517. tempIndex = ((gun_index==2) ? 1: 0);
  15518. }
  15519. else
  15520. {
  15521. tempIndex = gun_index;
  15522. }
  15523. for (int index = 0; index < GB_QUANTITY; index++)
  15524. {
  15525. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15526. {
  15527. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15528. } //end of the same index
  15529. } // end of for GB_QUANTITY
  15530. }
  15531. else if(gunType[gun_index] == GUN_TYPE_DO)
  15532. {
  15533. tempIndex = gun_index;
  15534. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15535. {
  15536. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15537. {
  15538. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15539. } //end of the same index
  15540. }
  15541. }
  15542. else
  15543. {
  15544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15545. {
  15546. tempIndex = 2;
  15547. }
  15548. else
  15549. {
  15550. tempIndex = gun_index;
  15551. }
  15552. for (int index = 0; index < AC_QUANTITY; index++)
  15553. {
  15554. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15555. {
  15556. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15557. }//end of the same index
  15558. }//end of for AC_QUANTITY
  15559. }
  15560. return result;
  15561. }
  15562. void refreshProcDogTimer()
  15563. {
  15564. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  15565. }
  15566. void InitialSystemValue(void)
  15567. {
  15568. int connectorIndex = 0;
  15569. //int valueASCII = 0;
  15570. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15571. gunTotalNumber=0;
  15572. SystemInitial = 0;
  15573. localversion=0;
  15574. BootNotificationInterval = 0;
  15575. authorizeRetryTimes = 0;
  15576. GunStatusInterval = 10;
  15577. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15578. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15579. //Hear Beat
  15580. HeartBeatWithNOResponse = 0;
  15581. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15582. FirstHeartBeat = 0;
  15583. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15584. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15585. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15586. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15587. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15588. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15589. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15590. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15591. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15592. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15593. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15594. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15595. memset(gunType, 0, ARRAY_SIZE(gunType));
  15596. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15597. {
  15598. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15599. {
  15600. // DO series
  15601. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15602. {
  15603. SystemInitial = SystemInitial + 1;
  15604. gunTotalNumber = gunTotalNumber + 1;
  15605. gunType[connectorIndex] = GUN_TYPE_DO;
  15606. connectorIndex = connectorIndex + 1;
  15607. }
  15608. }
  15609. else
  15610. {
  15611. // DM, DW, DS series
  15612. //check connector / socket type (index: 8, 9, 10)
  15613. for(int index=7; index <10 ; index++)
  15614. {
  15615. if(index != 8)
  15616. {
  15617. // DC Connector
  15618. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15619. {
  15620. SystemInitial = SystemInitial + 1;
  15621. gunTotalNumber = gunTotalNumber + 1;
  15622. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15623. connectorIndex = connectorIndex + 1;
  15624. }
  15625. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15626. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15627. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15628. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15629. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15630. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15631. {
  15632. SystemInitial = SystemInitial + 1;
  15633. gunTotalNumber = gunTotalNumber + 1;
  15634. gunType[connectorIndex] = GUN_TYPE_CCS;
  15635. connectorIndex = connectorIndex + 1;
  15636. }
  15637. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15638. {
  15639. SystemInitial = SystemInitial + 1;
  15640. gunTotalNumber = gunTotalNumber + 1;
  15641. gunType[connectorIndex] = GUN_TYPE_GBT;
  15642. connectorIndex = connectorIndex + 1;
  15643. }
  15644. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15645. {
  15646. SystemInitial = SystemInitial + 1;
  15647. gunTotalNumber = gunTotalNumber + 1;
  15648. gunType[connectorIndex] = GUN_TYPE_DO;
  15649. connectorIndex = connectorIndex + 1;
  15650. }
  15651. }
  15652. else
  15653. {
  15654. // AC Connector
  15655. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15656. {
  15657. SystemInitial = SystemInitial + 1;
  15658. gunTotalNumber = gunTotalNumber + 1;
  15659. gunType[connectorIndex] = GUN_TYPE_AC;
  15660. connectorIndex = connectorIndex + 1;
  15661. }
  15662. }
  15663. }
  15664. }
  15665. //DEBUG_INFO("DC ...\n");
  15666. }
  15667. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15668. {
  15669. //check connector / socket type (index: 8, 9, 10)
  15670. for(int index=7; index <10 ; index++)
  15671. {
  15672. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15673. {
  15674. SystemInitial = SystemInitial + 1;
  15675. gunTotalNumber = gunTotalNumber + 1;
  15676. gunType[connectorIndex] = GUN_TYPE_AC;
  15677. connectorIndex = connectorIndex + 1;
  15678. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15679. }
  15680. }
  15681. }
  15682. //Status && ConnectorPlugIn Setting
  15683. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15684. {
  15685. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15686. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15687. }
  15688. for (int index = 0; index < CCS_QUANTITY; index++)
  15689. {
  15690. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15691. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15692. }
  15693. for (int index = 0; index < GB_QUANTITY; index++)
  15694. {
  15695. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15696. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15697. }
  15698. for (int index = 0; index < AC_QUANTITY; index++)
  15699. {
  15700. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15701. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15702. }
  15703. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15704. {
  15705. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15706. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15707. }
  15708. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15709. {
  15710. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15711. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15712. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15713. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15714. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  15715. }
  15716. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15717. clientTime.Heartbeat=time((time_t*)NULL);
  15718. sleep(1);
  15719. }
  15720. void LWS_Send(char *str)
  15721. {
  15722. //=====================================================
  15723. // Check InternetConn 0: disconnected, 1: connected
  15724. //====================================================
  15725. if(GetOcppConnStatus() == 0)
  15726. {
  15727. DEBUG_INFO("offline now !!!\n");
  15728. return;
  15729. }
  15730. // Only disable isWebsocketSendable operation initiated by charger
  15731. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15732. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15733. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15734. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15735. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15736. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15737. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15738. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15739. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15740. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15741. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15742. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15743. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15744. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15745. {
  15746. isWebsocketSendable = 0;
  15747. }
  15748. pthread_mutex_lock(&lock_send);
  15749. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15750. sprintf((char *)SendBuffer, "%s", str);
  15751. SendBufLen = strlen(str);
  15752. pthread_mutex_unlock(&lock_send);
  15753. lws_callback_on_writable(wsi_client);
  15754. //lws_service(context, 0);
  15755. //sleep(1);
  15756. }
  15757. void LWS_SendNow(char *str)
  15758. {
  15759. //=====================================================
  15760. // Check InternetConn 0: disconnected, 1: connected
  15761. //====================================================
  15762. if(GetOcppConnStatus() == 0)
  15763. {
  15764. DEBUG_INFO("offline now !!!\n");
  15765. return;
  15766. }
  15767. // Only disable isWebsocketSendable operation initiated by charger
  15768. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15769. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15770. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15771. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15772. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15773. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15774. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15775. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15776. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15777. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15778. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15779. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15780. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15781. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15782. {
  15783. isWebsocketSendable = 0;
  15784. }
  15785. pthread_mutex_lock(&lock_send);
  15786. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15787. sprintf((char *)SendBuffer, "%s", str);
  15788. SendBufLen = strlen(str);
  15789. pthread_mutex_unlock(&lock_send);
  15790. lws_callback_on_writable(wsi_client);
  15791. lws_service(context, 0);
  15792. //sleep(1);
  15793. }