MessageHandler.c 777 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146
  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. random_uuid(guid);
  3957. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3958. , MESSAGE_TYPE_CALL
  3959. , guid
  3960. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  3961. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  3962. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  3963. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  3964. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  3965. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  3966. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  3967. if((server_sign == TRUE) && isStateChanged)
  3968. {
  3969. LWS_Send(message);
  3970. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3971. 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*/)
  3972. {
  3973. //DEBUG_ERROR("statusNotification mapitem pass");
  3974. result = PASS;
  3975. }
  3976. }
  3977. else
  3978. {
  3979. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3980. result = PASS;
  3981. }
  3982. return result;
  3983. }
  3984. int sendStopTransactionRequest(int gun_index)
  3985. {
  3986. mtrace();
  3987. int result = FAIL;
  3988. //char message[1500]={0};
  3989. char guid[37]={0};
  3990. char tempdata[65]={0};
  3991. int tempIndex = 0;
  3992. char TempStopTransaction[256];
  3993. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  3994. //int idx_sample=0;
  3995. DEBUG_INFO("sendStopTransactionRequest \n");
  3996. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3997. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  3998. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3999. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4000. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4001. {
  4002. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4003. {
  4004. tempIndex = ((gun_index==2) ? 1: 0);
  4005. }
  4006. else
  4007. {
  4008. tempIndex = gun_index;
  4009. }
  4010. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4011. {
  4012. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4013. {
  4014. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4015. }
  4016. }// END OF CHAdeMO_QUANTITY
  4017. }
  4018. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4019. {
  4020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4021. {
  4022. tempIndex = ((gun_index==2) ? 1: 0);
  4023. }
  4024. else
  4025. {
  4026. tempIndex = gun_index;
  4027. }
  4028. for (int index = 0; index < CCS_QUANTITY; index++)
  4029. {
  4030. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4031. {
  4032. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4033. }
  4034. }// END OF CCS_QUANTITY
  4035. }
  4036. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4037. {
  4038. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4039. {
  4040. tempIndex = ((gun_index==2) ? 1: 0);
  4041. }
  4042. else
  4043. {
  4044. tempIndex = gun_index;
  4045. }
  4046. for (int index = 0; index < GB_QUANTITY; index++)
  4047. {
  4048. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4049. {
  4050. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4051. }
  4052. }// END OF GB_QUANTITY
  4053. }
  4054. else if(gunType[gun_index] == GUN_TYPE_DO)
  4055. {
  4056. tempIndex = gun_index;
  4057. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4058. {
  4059. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4060. {
  4061. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4062. }
  4063. }// END OF GB_QUANTITY
  4064. }
  4065. else
  4066. {
  4067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4068. {
  4069. tempIndex = 2;
  4070. }
  4071. else
  4072. {
  4073. tempIndex = gun_index;
  4074. }
  4075. for (int index = 0; index < AC_QUANTITY; index++)
  4076. {
  4077. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4078. {
  4079. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4080. }
  4081. }// END OF AC_QUANTITY
  4082. }
  4083. //====================================== Stop Transaction Time =====================================================
  4084. struct timeval tmnow;
  4085. struct tm *tm;
  4086. char buf[28];//, usec_buf[6];
  4087. gettimeofday(&tmnow, NULL);
  4088. time_t t;
  4089. t = time(NULL);
  4090. /*UTC time and date*/
  4091. tm = gmtime(&t);
  4092. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  4094. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  4095. random_uuid(guid);
  4096. /***********************************transactionData******************************************************/
  4097. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4098. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4099. //=================================
  4100. // Transaction_Begin
  4101. //=================================
  4102. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4103. {
  4104. //============================================ Energy.Active.Import.Interval ================================
  4105. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4106. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4107. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4108. 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*/]);
  4109. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4110. 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))
  4111. {
  4112. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4113. }
  4114. else
  4115. {
  4116. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4117. }
  4118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4120. }
  4121. //=================================
  4122. // Transaction_End
  4123. //=================================
  4124. // ================================= Current.Import L1 ===============================================
  4125. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4126. {
  4127. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4128. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4129. {
  4130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4131. {
  4132. tempIndex = ((gun_index==2) ? 1: 0);
  4133. }
  4134. else
  4135. {
  4136. tempIndex = gun_index;
  4137. }
  4138. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4139. {
  4140. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4141. {
  4142. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4143. }
  4144. }// End of for CHAdeMO_QUANTITY
  4145. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4146. }
  4147. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4148. {
  4149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4150. {
  4151. tempIndex = ((gun_index==2) ? 1: 0);
  4152. }
  4153. else
  4154. {
  4155. tempIndex = gun_index;
  4156. }
  4157. for (int index = 0; index < CCS_QUANTITY; index++)
  4158. {
  4159. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4160. {
  4161. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4162. }
  4163. }// End of for CCS_QUANTITY
  4164. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4165. }
  4166. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4167. {
  4168. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4169. {
  4170. tempIndex = ((gun_index==2) ? 1: 0);
  4171. }
  4172. else
  4173. {
  4174. tempIndex = gun_index;
  4175. }
  4176. for (int index = 0; index < GB_QUANTITY; index++)
  4177. {
  4178. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4179. {
  4180. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4181. }
  4182. }// End of for GB_QUANTITY
  4183. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4184. }
  4185. else if(gunType[gun_index] == GUN_TYPE_DO)
  4186. {
  4187. tempIndex = gun_index;
  4188. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4189. {
  4190. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4191. {
  4192. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4193. }
  4194. }
  4195. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4196. }
  4197. else
  4198. {
  4199. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4200. {
  4201. tempIndex = 2;
  4202. }
  4203. else
  4204. {
  4205. tempIndex = gun_index;
  4206. }
  4207. for (int index = 0; index < AC_QUANTITY; index++)
  4208. {
  4209. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4210. {
  4211. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4212. }
  4213. }// End of for AC_QUANTITY
  4214. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4215. }
  4216. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4217. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4220. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4221. }
  4222. // ================================= Energy.Active.Import.Interval ==============================================
  4223. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4224. {
  4225. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4226. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4227. {
  4228. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4229. {
  4230. tempIndex = ((gun_index==2) ? 1: 0);
  4231. }
  4232. else
  4233. {
  4234. tempIndex = gun_index;
  4235. }
  4236. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4237. {
  4238. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4239. {
  4240. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4241. }
  4242. }// END OF CHAdeMO_QUANTITY
  4243. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4244. }
  4245. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4246. {
  4247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4248. {
  4249. tempIndex = ((gun_index==2) ? 1: 0);
  4250. }
  4251. else
  4252. {
  4253. tempIndex = gun_index;
  4254. }
  4255. for (int index = 0; index < CCS_QUANTITY; index++)
  4256. {
  4257. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4258. {
  4259. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4260. }
  4261. }// END OF CCS_QUANTITY
  4262. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4263. }
  4264. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4265. {
  4266. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4267. {
  4268. tempIndex = ((gun_index==2) ? 1: 0);
  4269. }
  4270. else
  4271. {
  4272. tempIndex = gun_index;
  4273. }
  4274. for (int index = 0; index < GB_QUANTITY; index++)
  4275. {
  4276. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4277. {
  4278. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4279. }
  4280. }// END OF GB_QUANTITY
  4281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4282. }
  4283. else if(gunType[gun_index] == GUN_TYPE_DO)
  4284. {
  4285. tempIndex = gun_index;
  4286. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4287. {
  4288. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4289. {
  4290. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4291. }
  4292. }
  4293. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4294. }
  4295. else
  4296. {
  4297. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4298. {
  4299. tempIndex = 2;
  4300. }
  4301. else
  4302. {
  4303. tempIndex = gun_index;
  4304. }
  4305. for (int index = 0; index < AC_QUANTITY; index++)
  4306. {
  4307. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4308. {
  4309. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4310. }
  4311. }// END OF AC_QUANTITY
  4312. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4313. }
  4314. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4315. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4316. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4317. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4318. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4319. }
  4320. //=================================== Power.Active.Import ==================================================
  4321. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4322. {
  4323. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4324. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4325. {
  4326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4327. {
  4328. tempIndex = ((gun_index==2) ? 1: 0);
  4329. }
  4330. else
  4331. {
  4332. tempIndex = gun_index;
  4333. }
  4334. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4335. {
  4336. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4337. {
  4338. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4339. }
  4340. } // End for CHAdeMO_QUANTITY
  4341. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4342. }
  4343. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4344. {
  4345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4346. {
  4347. tempIndex = ((gun_index==2) ? 1: 0);
  4348. }
  4349. else
  4350. {
  4351. tempIndex = gun_index;
  4352. }
  4353. for (int index = 0; index < CCS_QUANTITY; index++)
  4354. {
  4355. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4356. {
  4357. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4358. }
  4359. } // END for CCS_QUANTITY
  4360. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4361. }
  4362. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4363. {
  4364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4365. {
  4366. tempIndex = ((gun_index==2) ? 1: 0);
  4367. }
  4368. else
  4369. {
  4370. tempIndex = gun_index;
  4371. }
  4372. for (int index = 0; index < GB_QUANTITY; index++)
  4373. {
  4374. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4375. {
  4376. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4377. }
  4378. }// END for GB_QUANTITY
  4379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4380. }
  4381. else if(gunType[gun_index] == GUN_TYPE_DO)
  4382. {
  4383. tempIndex = gun_index;
  4384. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4385. {
  4386. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4387. {
  4388. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4389. }
  4390. }
  4391. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4392. }
  4393. else
  4394. {
  4395. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4396. {
  4397. tempIndex = 2;
  4398. }
  4399. else
  4400. {
  4401. tempIndex = gun_index;
  4402. }
  4403. for (int index = 0; index < AC_QUANTITY; index++)
  4404. {
  4405. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4406. {
  4407. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4408. }
  4409. } // END for AC_QUANTITY
  4410. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4411. }
  4412. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4413. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4414. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4415. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4416. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4417. }
  4418. //============================ Voltage L1 ====================================
  4419. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4420. {
  4421. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4422. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4423. {
  4424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4425. {
  4426. tempIndex = ((gun_index==2) ? 1: 0);
  4427. }
  4428. else
  4429. {
  4430. tempIndex = gun_index;
  4431. }
  4432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4433. {
  4434. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4435. {
  4436. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4437. }
  4438. } // END OF FOR CHAdeMO_QUANTITY
  4439. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4440. }
  4441. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4442. {
  4443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4444. {
  4445. tempIndex = ((gun_index==2) ? 1: 0);
  4446. }
  4447. else
  4448. {
  4449. tempIndex = gun_index;
  4450. }
  4451. for (int index = 0; index < CCS_QUANTITY; index++)
  4452. {
  4453. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4454. {
  4455. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4456. }
  4457. } // END OF FOR CCS_QUANTITY
  4458. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4459. }
  4460. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4461. {
  4462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4463. {
  4464. tempIndex = ((gun_index==2) ? 1: 0);
  4465. }
  4466. else
  4467. {
  4468. tempIndex = gun_index;
  4469. }
  4470. for (int index = 0; index < GB_QUANTITY; index++)
  4471. {
  4472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4473. {
  4474. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4475. }
  4476. } // END OF FOR GB_QUANTITY
  4477. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4478. }
  4479. else if(gunType[gun_index] == GUN_TYPE_DO)
  4480. {
  4481. tempIndex = gun_index;
  4482. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4483. {
  4484. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4485. {
  4486. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4487. }
  4488. }
  4489. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4490. }
  4491. else
  4492. {
  4493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4494. {
  4495. tempIndex = 2;
  4496. }
  4497. else
  4498. {
  4499. tempIndex = gun_index;
  4500. }
  4501. for (int index = 0; index < AC_QUANTITY; index++)
  4502. {
  4503. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4504. {
  4505. 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
  4506. }
  4507. } // END OF FOR AC_QUANTITY
  4508. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4509. }
  4510. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4511. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4512. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4513. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4514. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4515. }
  4516. //====================== End SoC ================================
  4517. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4518. {
  4519. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4520. 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))
  4521. {
  4522. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4523. {
  4524. tempIndex = ((gun_index==2) ? 1: 0);
  4525. }
  4526. else
  4527. {
  4528. tempIndex = gun_index;
  4529. }
  4530. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4531. {
  4532. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4533. {
  4534. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4535. {
  4536. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4537. }
  4538. }
  4539. }
  4540. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4541. {
  4542. for (int index = 0; index < CCS_QUANTITY; index++)
  4543. {
  4544. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4545. {
  4546. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4547. }
  4548. }
  4549. }
  4550. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4551. {
  4552. for (int index = 0; index < GB_QUANTITY; index++)
  4553. {
  4554. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4555. {
  4556. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4557. }
  4558. }
  4559. }
  4560. else if(gunType[gun_index] == GUN_TYPE_DO)
  4561. {
  4562. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4563. {
  4564. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4565. {
  4566. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4567. }
  4568. }
  4569. }
  4570. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4571. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4572. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4573. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4574. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4575. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4576. } // END FOR DC CASE
  4577. }
  4578. // ================================= Current.Import L2 ===============================================
  4579. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4580. {
  4581. // AC 3 phse L2 current
  4582. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4583. {
  4584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4585. {
  4586. tempIndex = 2;
  4587. }
  4588. else
  4589. {
  4590. tempIndex = gun_index;
  4591. }
  4592. for (int index = 0; index < AC_QUANTITY; index++)
  4593. {
  4594. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4595. {
  4596. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4597. }
  4598. }// End of for AC_QUANTITY
  4599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4600. }
  4601. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4602. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4603. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4604. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4605. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4606. }
  4607. // ================================= Current.Import L3 ===============================================
  4608. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4609. {
  4610. // AC 3 phse L3 current
  4611. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4612. {
  4613. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4614. {
  4615. tempIndex = 2;
  4616. }
  4617. else
  4618. {
  4619. tempIndex = gun_index;
  4620. }
  4621. for (int index = 0; index < AC_QUANTITY; index++)
  4622. {
  4623. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4624. {
  4625. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4626. }
  4627. }// End of for AC_QUANTITY
  4628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4629. }
  4630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4631. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4632. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4633. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4634. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4635. }
  4636. //============================ Voltage L2 ====================================
  4637. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4638. {
  4639. // AC 3 phse L2 voltage
  4640. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4641. {
  4642. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4643. {
  4644. tempIndex = 2;
  4645. }
  4646. else
  4647. {
  4648. tempIndex = gun_index;
  4649. }
  4650. for (int index = 0; index < AC_QUANTITY; index++)
  4651. {
  4652. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4653. {
  4654. 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
  4655. }
  4656. } // END OF FOR AC_QUANTITY
  4657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4658. }
  4659. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4660. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4661. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4662. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4663. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4664. }
  4665. //============================ Voltage L3 ====================================
  4666. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4667. {
  4668. // AC 3 phse L3 voltage
  4669. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4670. {
  4671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4672. {
  4673. tempIndex = 2;
  4674. }
  4675. else
  4676. {
  4677. tempIndex = gun_index;
  4678. }
  4679. for (int index = 0; index < AC_QUANTITY; index++)
  4680. {
  4681. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4682. {
  4683. 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
  4684. }
  4685. } // END OF FOR AC_QUANTITY
  4686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4687. }
  4688. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4689. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4690. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4691. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4692. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4693. }
  4694. //====================== Start SoC ================================
  4695. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4696. {
  4697. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4698. 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))
  4699. {
  4700. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4701. {
  4702. tempIndex = ((gun_index==2) ? 1: 0);
  4703. }
  4704. else
  4705. {
  4706. tempIndex = gun_index;
  4707. }
  4708. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4709. {
  4710. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4711. {
  4712. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4713. {
  4714. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4715. }
  4716. }
  4717. }
  4718. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4719. {
  4720. for (int index = 0; index < CCS_QUANTITY; index++)
  4721. {
  4722. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4723. {
  4724. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4725. }
  4726. }
  4727. }
  4728. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4729. {
  4730. for (int index = 0; index < GB_QUANTITY; index++)
  4731. {
  4732. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4733. {
  4734. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4735. }
  4736. }
  4737. }
  4738. else if(gunType[gun_index] == GUN_TYPE_DO)
  4739. {
  4740. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4741. {
  4742. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4743. {
  4744. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4745. }
  4746. }
  4747. }
  4748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4749. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4750. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4751. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4753. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4754. } // END FOR DC CASE
  4755. }
  4756. //================================================ Message create ====================================================
  4757. json_object *StopTransaction = json_object_new_object();
  4758. json_object *transactionDatas = json_object_new_array();
  4759. json_object *sampledValues = json_object_new_array();
  4760. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  4761. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  4762. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  4763. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  4764. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  4765. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  4766. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  4767. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  4768. {
  4769. json_object *transactionData = json_object_new_object();
  4770. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4771. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4772. {
  4773. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4774. {
  4775. json_object *sampledValue = json_object_new_object();
  4776. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4777. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4778. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4779. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4780. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4781. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4782. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4783. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4784. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4785. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4786. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4787. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4788. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4789. json_object_array_add(sampledValues, sampledValue);
  4790. }
  4791. }
  4792. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4793. json_object_array_add(transactionDatas, transactionData);
  4794. }
  4795. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4796. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4797. ,MESSAGE_TYPE_CALL
  4798. ,guid
  4799. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4800. json_object_put(StopTransaction);
  4801. #if 1 // for TempStopTransaction
  4802. //Delete TempStopTransaction
  4803. if((access(TempStopTransaction,F_OK))!=-1)
  4804. {
  4805. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4806. }
  4807. #endif
  4808. #if 1
  4809. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4810. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4811. {
  4812. result = PASS;
  4813. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4814. }
  4815. #endif
  4816. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4817. OCPP_insert_transaction_msg(NO, queuedata);
  4818. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4819. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  4820. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  4821. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4822. {
  4823. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  4824. }
  4825. //for test
  4826. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4827. return result;
  4828. }
  4829. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4830. {
  4831. mtrace();
  4832. int result = FAIL;
  4833. char guid[37]={0};
  4834. char tempdata[65]={0};
  4835. int tempIndex = 0;
  4836. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4837. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4838. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4839. //set value
  4840. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4841. 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) )?
  4842. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  4843. -1);
  4844. random_uuid(guid);
  4845. //UTC Date time
  4846. struct timeval tmnow;
  4847. struct tm *tm;
  4848. char buf[28];//, usec_buf[6];
  4849. gettimeofday(&tmnow, NULL);
  4850. time_t t;
  4851. t = time(NULL);
  4852. /*UTC time and date*/
  4853. tm = gmtime(&t);
  4854. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4855. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4856. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4857. //********************************(1)Current.Import L1************************************************/
  4858. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4859. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4860. (dataType == ReadingContext_Trigger))
  4861. {
  4862. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4863. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4864. {
  4865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4866. {
  4867. tempIndex = ((gun_index==2) ? 1: 0);
  4868. }
  4869. else
  4870. {
  4871. tempIndex = gun_index;
  4872. }
  4873. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4874. {
  4875. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4876. {
  4877. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4878. }
  4879. }
  4880. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4881. }
  4882. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4883. {
  4884. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4885. {
  4886. tempIndex = ((gun_index==2) ? 1: 0);
  4887. }
  4888. else
  4889. {
  4890. tempIndex = gun_index;
  4891. }
  4892. for (int index = 0; index < CCS_QUANTITY; index++)
  4893. {
  4894. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4895. {
  4896. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4897. }
  4898. }
  4899. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4900. }
  4901. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4902. {
  4903. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4904. {
  4905. tempIndex = ((gun_index==2) ? 1: 0);
  4906. }
  4907. else
  4908. {
  4909. tempIndex = gun_index;
  4910. }
  4911. for (int index = 0; index < GB_QUANTITY; index++)
  4912. {
  4913. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4914. {
  4915. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4916. }
  4917. }
  4918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4919. }
  4920. else if(gunType[gun_index] == GUN_TYPE_DO)
  4921. {
  4922. tempIndex = gun_index;
  4923. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4924. {
  4925. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4926. {
  4927. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4928. }
  4929. }
  4930. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4931. }
  4932. else
  4933. {
  4934. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4935. {
  4936. tempIndex = 2;
  4937. }
  4938. else
  4939. {
  4940. tempIndex = gun_index;
  4941. }
  4942. for (int index = 0; index < AC_QUANTITY; index++)
  4943. {
  4944. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4945. {
  4946. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4947. }
  4948. }
  4949. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4950. }
  4951. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4952. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4953. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4954. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4955. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4956. }
  4957. //********************************(2)Energy.Active.Import.Register ************************************************/
  4958. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4959. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4960. (dataType == ReadingContext_Trigger))
  4961. {
  4962. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4963. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4964. {
  4965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4966. {
  4967. tempIndex = ((gun_index==2) ? 1: 0);
  4968. }
  4969. else
  4970. {
  4971. tempIndex = gun_index;
  4972. }
  4973. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4974. {
  4975. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4976. {
  4977. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4978. }
  4979. }
  4980. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4981. }
  4982. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4983. {
  4984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4985. {
  4986. tempIndex = ((gun_index==2) ? 1: 0);
  4987. }
  4988. else
  4989. {
  4990. tempIndex = gun_index;
  4991. }
  4992. for (int index = 0; index < CCS_QUANTITY; index++)
  4993. {
  4994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4995. {
  4996. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4997. }
  4998. }
  4999. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5000. }
  5001. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5002. {
  5003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5004. {
  5005. tempIndex = ((gun_index==2) ? 1: 0);
  5006. }
  5007. else
  5008. {
  5009. tempIndex = gun_index;
  5010. }
  5011. for (int index = 0; index < GB_QUANTITY; index++)
  5012. {
  5013. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5014. {
  5015. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5016. }
  5017. }
  5018. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5019. }
  5020. else if(gunType[gun_index] == GUN_TYPE_DO)
  5021. {
  5022. tempIndex = gun_index;
  5023. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5024. {
  5025. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5026. {
  5027. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5028. }
  5029. }
  5030. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5031. }
  5032. else
  5033. {
  5034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5035. {
  5036. tempIndex = 2;
  5037. }
  5038. else
  5039. {
  5040. tempIndex = gun_index;
  5041. }
  5042. for (int index = 0; index < AC_QUANTITY; index++)
  5043. {
  5044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5045. {
  5046. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5047. }
  5048. }
  5049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5050. }
  5051. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5052. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5053. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5054. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5055. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5056. }
  5057. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5058. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5059. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5060. (dataType == ReadingContext_Trigger))
  5061. {
  5062. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5063. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5064. {
  5065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5066. {
  5067. tempIndex = ((gun_index==2) ? 1: 0);
  5068. }
  5069. else
  5070. {
  5071. tempIndex = gun_index;
  5072. }
  5073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5074. {
  5075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5076. {
  5077. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5078. }
  5079. } // END OF FOR CHAdeMO_QUANTITY
  5080. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5081. }
  5082. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5083. {
  5084. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5085. {
  5086. tempIndex = ((gun_index==2) ? 1: 0);
  5087. }
  5088. else
  5089. {
  5090. tempIndex = gun_index;
  5091. }
  5092. for (int index = 0; index < CCS_QUANTITY; index++)
  5093. {
  5094. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5095. {
  5096. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5097. }
  5098. } // END OF CCS_QUANTITY
  5099. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5100. }
  5101. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5102. {
  5103. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5104. {
  5105. tempIndex = ((gun_index==2) ? 1: 0);
  5106. }
  5107. else
  5108. {
  5109. tempIndex = gun_index;
  5110. }
  5111. for (int index = 0; index < GB_QUANTITY; index++)
  5112. {
  5113. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5114. {
  5115. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5116. }
  5117. } // END OF GB_QUANTITY
  5118. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5119. }
  5120. else if(gunType[gun_index] == GUN_TYPE_DO)
  5121. {
  5122. tempIndex = gun_index;
  5123. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5124. {
  5125. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5126. {
  5127. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5128. }
  5129. }
  5130. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5131. }
  5132. else
  5133. {
  5134. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5135. {
  5136. tempIndex = 2;
  5137. }
  5138. else
  5139. {
  5140. tempIndex = gun_index;
  5141. }
  5142. for (int index = 0; index < AC_QUANTITY; index++)
  5143. {
  5144. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5145. {
  5146. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5147. }
  5148. }
  5149. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5150. }
  5151. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5152. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5153. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5154. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5155. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5156. }
  5157. //********************************(4)Power.Active.Import************************************************/
  5158. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5159. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5160. (dataType == ReadingContext_Trigger))
  5161. {
  5162. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5163. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5164. {
  5165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5166. {
  5167. tempIndex = ((gun_index==2) ? 1: 0);
  5168. }
  5169. else
  5170. {
  5171. tempIndex = gun_index;
  5172. }
  5173. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5174. {
  5175. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5176. {
  5177. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5178. }
  5179. } // END OF FOR
  5180. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5181. }
  5182. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5183. {
  5184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5185. {
  5186. tempIndex = ((gun_index==2) ? 1: 0);
  5187. }
  5188. else
  5189. {
  5190. tempIndex = gun_index;
  5191. }
  5192. for (int index = 0; index < CCS_QUANTITY; index++)
  5193. {
  5194. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5195. {
  5196. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5197. }
  5198. }
  5199. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5200. }
  5201. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5202. {
  5203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5204. {
  5205. tempIndex = ((gun_index==2) ? 1: 0);
  5206. }
  5207. else
  5208. {
  5209. tempIndex = gun_index;
  5210. }
  5211. for (int index = 0; index < GB_QUANTITY; index++)
  5212. {
  5213. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5214. {
  5215. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5216. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5217. }
  5218. }
  5219. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5220. }
  5221. else if(gunType[gun_index] == GUN_TYPE_DO)
  5222. {
  5223. tempIndex = gun_index;
  5224. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5225. {
  5226. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5227. {
  5228. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5229. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5230. }
  5231. }
  5232. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5233. }
  5234. else
  5235. {
  5236. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5237. {
  5238. tempIndex = 2;
  5239. }
  5240. else
  5241. {
  5242. tempIndex = gun_index;
  5243. }
  5244. for (int index = 0; index < AC_QUANTITY; index++)
  5245. {
  5246. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5247. {
  5248. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5249. }
  5250. }
  5251. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5252. }
  5253. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5254. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5255. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5256. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5257. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5258. }
  5259. //***********************************************(5)VOLTAGE L1******************************************************/
  5260. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5261. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5262. (dataType == ReadingContext_Trigger))
  5263. {
  5264. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5265. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5266. {
  5267. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5268. {
  5269. tempIndex = ((gun_index==2) ? 1: 0);
  5270. }
  5271. else
  5272. {
  5273. tempIndex = gun_index;
  5274. }
  5275. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5276. {
  5277. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5278. {
  5279. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5280. }
  5281. }
  5282. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5283. }
  5284. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5285. {
  5286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5287. {
  5288. tempIndex = ((gun_index==2) ? 1: 0);
  5289. }
  5290. else
  5291. {
  5292. tempIndex = gun_index;
  5293. }
  5294. for (int index = 0; index < CCS_QUANTITY; index++)
  5295. {
  5296. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5297. {
  5298. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5299. }
  5300. }
  5301. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5302. }
  5303. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5304. {
  5305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5306. {
  5307. tempIndex = ((gun_index==2) ? 1: 0);
  5308. }
  5309. else
  5310. {
  5311. tempIndex = gun_index;
  5312. }
  5313. for (int index = 0; index < GB_QUANTITY; index++)
  5314. {
  5315. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5316. {
  5317. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5318. }
  5319. }
  5320. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5321. }
  5322. else if(gunType[gun_index] == GUN_TYPE_DO)
  5323. {
  5324. tempIndex = gun_index;
  5325. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5326. {
  5327. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5328. {
  5329. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5330. }
  5331. }
  5332. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5333. }
  5334. else
  5335. {
  5336. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5337. {
  5338. tempIndex = 2;
  5339. }
  5340. else
  5341. {
  5342. tempIndex = gun_index;
  5343. }
  5344. for (int index = 0; index < AC_QUANTITY; index++)
  5345. {
  5346. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5347. {
  5348. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5349. }
  5350. }
  5351. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5352. }
  5353. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5354. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5355. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5356. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5357. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5358. }
  5359. //***********************************************(6)SOC******************************************************/
  5360. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5361. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5362. (dataType == ReadingContext_Trigger))
  5363. {
  5364. 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))
  5365. {
  5366. //idx_sample=5;
  5367. //sampledValue = NULL;
  5368. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5369. {
  5370. tempIndex = ((gun_index==2) ? 1: 0);
  5371. }
  5372. else
  5373. {
  5374. tempIndex = gun_index;
  5375. }
  5376. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5377. {
  5378. //tempIndex = ((gun_index==2) ? 1: 0);
  5379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5380. {
  5381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5382. {
  5383. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5384. }
  5385. }
  5386. }
  5387. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5388. {
  5389. //tempIndex = ((gun_index==2) ? 1: 0);
  5390. for (int index = 0; index < CCS_QUANTITY; index++)
  5391. {
  5392. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5393. {
  5394. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5395. }
  5396. }
  5397. }
  5398. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5399. {
  5400. //tempIndex = ((gun_index==2) ? 1: 0);
  5401. for (int index = 0; index < GB_QUANTITY; index++)
  5402. {
  5403. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5404. {
  5405. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5406. }
  5407. }
  5408. }
  5409. else if(gunType[gun_index] == GUN_TYPE_DO)
  5410. {
  5411. //tempIndex = ((gun_index==2) ? 1: 0);
  5412. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5413. {
  5414. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5415. {
  5416. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5417. }
  5418. }
  5419. }
  5420. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5421. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5422. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5423. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5424. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5425. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5426. }
  5427. }
  5428. //********************************(7)Current.Import L2************************************************/
  5429. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5430. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5431. (dataType == ReadingContext_Trigger))
  5432. {
  5433. // Only for AC 3 phase
  5434. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5435. {
  5436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5437. {
  5438. tempIndex = 2;
  5439. }
  5440. else
  5441. {
  5442. tempIndex = gun_index;
  5443. }
  5444. for (int index = 0; index < AC_QUANTITY; index++)
  5445. {
  5446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5447. {
  5448. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5449. }
  5450. }
  5451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5452. }
  5453. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5454. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5455. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5456. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5457. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5458. }
  5459. //********************************(8)Current.Import L3************************************************/
  5460. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5461. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5462. (dataType == ReadingContext_Trigger))
  5463. {
  5464. // Only for AC 3 phase
  5465. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5466. {
  5467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5468. {
  5469. tempIndex = 2;
  5470. }
  5471. else
  5472. {
  5473. tempIndex = gun_index;
  5474. }
  5475. for (int index = 0; index < AC_QUANTITY; index++)
  5476. {
  5477. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5478. {
  5479. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5480. }
  5481. }
  5482. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5483. }
  5484. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5485. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5486. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5487. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5488. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5489. }
  5490. //***********************************************(9)VOLTAGE L2******************************************************/
  5491. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5492. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5493. (dataType == ReadingContext_Trigger))
  5494. {
  5495. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5496. {
  5497. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5498. {
  5499. tempIndex = 2;
  5500. }
  5501. else
  5502. {
  5503. tempIndex = gun_index;
  5504. }
  5505. for (int index = 0; index < AC_QUANTITY; index++)
  5506. {
  5507. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5508. {
  5509. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5510. }
  5511. }
  5512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5513. }
  5514. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5515. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5516. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5517. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5518. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5519. }
  5520. //***********************************************(10)VOLTAGE L3******************************************************/
  5521. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5522. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5523. (dataType == ReadingContext_Trigger))
  5524. {
  5525. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5526. {
  5527. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5528. {
  5529. tempIndex = 2;
  5530. }
  5531. else
  5532. {
  5533. tempIndex = gun_index;
  5534. }
  5535. for (int index = 0; index < AC_QUANTITY; index++)
  5536. {
  5537. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5538. {
  5539. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5540. }
  5541. }
  5542. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5543. }
  5544. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5545. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5546. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5547. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5548. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5549. }
  5550. // Message create ====================================================================================================
  5551. if(TRUE)
  5552. {
  5553. json_object *MeterValueReq = json_object_new_object();
  5554. json_object *MeterValues = json_object_new_array();
  5555. json_object *sampledValues = json_object_new_array();
  5556. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  5557. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  5558. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  5559. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  5560. {
  5561. json_object *MeterValue = json_object_new_object();
  5562. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5563. {
  5564. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5565. {
  5566. json_object *sampledValue = json_object_new_object();
  5567. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5568. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5569. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5570. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5571. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5572. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5573. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5574. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5575. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5576. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5577. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5578. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5579. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5580. json_object_array_add(sampledValues, sampledValue);
  5581. }
  5582. }
  5583. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5584. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5585. json_object_array_add(MeterValues, MeterValue);
  5586. }
  5587. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5588. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5589. ,gun_index + 1
  5590. ,MESSAGE_TYPE_CALL
  5591. ,guid
  5592. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5593. json_object_put(MeterValueReq);
  5594. }
  5595. // Put request guid to hash map
  5596. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5597. 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*/)
  5598. {
  5599. result = PASS;
  5600. //DEBUG_INFO("MeterValues mapitem pass\n");
  5601. }
  5602. if((dataType != ReadingContext_Trigger) &&
  5603. (dataType != ReadingContext_Sample_Clock) &&
  5604. (ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1))
  5605. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5606. else
  5607. {
  5608. if(FirstHeartBeat)
  5609. LWS_Send(queuedata +2);
  5610. }
  5611. return result;
  5612. }
  5613. int sendLogStatusNotificationRequest(char *status)
  5614. {
  5615. mtrace();
  5616. int result = PASS;
  5617. char message[4096]={0};
  5618. char guid[37]={0};
  5619. char tempdata[128]={0};
  5620. json_object *LogStatusNotification = json_object_new_object();
  5621. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5622. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  5623. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  5624. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  5625. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  5626. random_uuid(guid);
  5627. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5628. json_object_put(LogStatusNotification);
  5629. LWS_Send(message);
  5630. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5631. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5632. {
  5633. result = PASS;
  5634. }
  5635. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  5636. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  5637. return result;
  5638. }
  5639. int sendSecurityEventNotificationRequest()
  5640. {
  5641. mtrace();
  5642. int result = PASS;
  5643. char message[4096]={0};
  5644. char guid[37]={0};
  5645. char tempdata[128]={0};
  5646. json_object *SecurityEventNotification = json_object_new_object();
  5647. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5648. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  5649. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  5650. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  5651. random_uuid(guid);
  5652. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5653. json_object_put(SecurityEventNotification);
  5654. LWS_Send(message);
  5655. sprintf(tempdata, "SecurityEventNotification,0");
  5656. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5657. {
  5658. result = PASS;
  5659. }
  5660. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  5661. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  5662. return result;
  5663. }
  5664. int sendSignCertificateRequest()
  5665. {
  5666. mtrace();
  5667. int result = PASS;
  5668. char message[4096]={0};
  5669. char guid[37]={0};
  5670. char tempdata[128]={0};
  5671. json_object *SignCertificate = json_object_new_object();
  5672. DEBUG_INFO("sendSignCertificateRequest...\n");
  5673. // Read csr file content
  5674. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  5675. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  5676. char *line = NULL;
  5677. size_t len = 0;
  5678. while(getline(&line, &len, fp) != -1)
  5679. {
  5680. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5681. {
  5682. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  5683. }
  5684. }
  5685. fclose(fp);
  5686. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  5687. random_uuid(guid);
  5688. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5689. json_object_put(SignCertificate);
  5690. LWS_Send(message);
  5691. sprintf(tempdata, "SignCertificate,0");
  5692. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5693. {
  5694. result = PASS;
  5695. }
  5696. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  5697. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  5698. return result;
  5699. }
  5700. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5701. {
  5702. mtrace();
  5703. int result = PASS;
  5704. char message[110]={0};
  5705. char guid[37]={0};
  5706. char tempdata[65]={0};
  5707. json_object *FirmwareStatusNotification = json_object_new_object();
  5708. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5709. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5710. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  5711. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  5712. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  5713. random_uuid(guid);
  5714. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5715. json_object_put(FirmwareStatusNotification);
  5716. LWS_Send(message);
  5717. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5718. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5719. {
  5720. result = PASS;
  5721. }
  5722. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5723. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5724. return result;
  5725. }
  5726. //==========================================
  5727. // send confirm routine
  5728. //==========================================
  5729. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5730. {
  5731. mtrace();
  5732. int result = FAIL;
  5733. char message[100]={0};
  5734. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5735. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5736. LWS_Send(message);
  5737. result = TRUE;
  5738. return result;
  5739. }
  5740. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5741. {
  5742. mtrace();
  5743. int result = FAIL;
  5744. char message[100]={0};
  5745. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5746. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5747. LWS_Send(message);
  5748. result = TRUE;
  5749. return result;
  5750. }
  5751. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5752. {
  5753. mtrace();
  5754. int result = FAIL;
  5755. char message[100]={0};
  5756. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5757. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5758. LWS_Send(message);
  5759. result = TRUE;
  5760. return result;
  5761. }
  5762. int sendClearCacheConfirmation(char *uuid,char *payload)
  5763. {
  5764. mtrace();
  5765. int result = FAIL;
  5766. char message[500]={0};
  5767. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5768. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5769. LWS_Send(message);
  5770. return result;
  5771. }
  5772. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5773. {
  5774. mtrace();
  5775. int result = FAIL;
  5776. char message[500]={0};
  5777. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5778. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5779. LWS_Send(message);
  5780. return result;
  5781. }
  5782. int sendDataTransferConfirmation(char *uuid,char *payload)
  5783. {
  5784. mtrace();
  5785. char statusStr[20]={0};
  5786. char dataStr[10]={0};
  5787. char sstr[20]={0};
  5788. int c = 0;
  5789. char *loc;
  5790. int result = FAIL;
  5791. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5792. /**********************status**************************/
  5793. loc = strstr(payload, "status");
  5794. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5795. c = 0;
  5796. while (loc[3+strlen("status")+c] != '\"')
  5797. {
  5798. sstr[c] = loc[3+strlen("status")+c];
  5799. c++;
  5800. }
  5801. sstr[c] = '\0';
  5802. strcpy(statusStr, sstr);
  5803. /**********************data**************************/
  5804. loc = strstr(payload, "data");
  5805. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5806. c = 0;
  5807. while (loc[3+strlen("data")+c] != '\"')
  5808. {
  5809. sstr[c] = loc[3+strlen("data")+c];
  5810. c++;
  5811. }
  5812. sstr[c] = '\0';
  5813. strcpy(dataStr, sstr);
  5814. return result;
  5815. }
  5816. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5817. {
  5818. mtrace();
  5819. int result = FAIL;
  5820. char message[1000]={0};
  5821. int CompositeScheduleIndex = 0;
  5822. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5823. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5824. if(nPeriod == 0)
  5825. {
  5826. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5827. {
  5828. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5829. ,MESSAGE_TYPE_CALLRESULT
  5830. ,uuid
  5831. ,payload
  5832. ,connectorIdInt);
  5833. }
  5834. else
  5835. {
  5836. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5837. ,MESSAGE_TYPE_CALLRESULT
  5838. ,uuid
  5839. ,payload
  5840. ,connectorIdInt
  5841. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5842. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5843. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5844. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5845. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5846. }
  5847. }
  5848. else
  5849. {
  5850. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5851. ,MESSAGE_TYPE_CALLRESULT
  5852. ,uuid
  5853. ,payload
  5854. ,connectorIdInt
  5855. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5856. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5857. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5858. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5859. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5860. {
  5861. if (idx_sample == 0)
  5862. {
  5863. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5864. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5865. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5866. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5867. }
  5868. else
  5869. {
  5870. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5871. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5872. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5873. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5874. }
  5875. }
  5876. sprintf(message + strlen(message), "]}}]");
  5877. }
  5878. LWS_Send(message);
  5879. result = TRUE;
  5880. return result;
  5881. }
  5882. int sendGetConfigurationConfirmation(char *uuid)
  5883. {
  5884. mtrace();
  5885. int result = FAIL;
  5886. int MaxKeySupported = 0;
  5887. int sentConfigurationNumber= 0;
  5888. int sentunConfigurationNumber= 0;
  5889. char message[4000]={0};
  5890. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5891. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5892. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5893. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5894. ,MESSAGE_TYPE_CALLRESULT
  5895. ,uuid );
  5896. //configuration key
  5897. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5898. {
  5899. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5900. {
  5901. if (sentConfigurationNumber == 0)
  5902. {
  5903. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5904. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5905. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5906. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5907. }
  5908. else
  5909. {
  5910. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5911. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5912. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5913. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5914. }
  5915. sentConfigurationNumber = sentConfigurationNumber + 1;
  5916. }
  5917. }
  5918. sprintf(message + strlen(message), "]");
  5919. if(UnknownKeynum != 0)
  5920. {
  5921. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5922. //unkown key
  5923. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5924. {
  5925. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5926. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5927. if(sentunConfigurationNumber == 0)
  5928. {
  5929. sprintf(message + strlen(message), "\"%s\""
  5930. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5931. }
  5932. else
  5933. {
  5934. sprintf(message + strlen(message), ",\"%s\""
  5935. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5936. }
  5937. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5938. }
  5939. sprintf(message + strlen(message), "]");
  5940. }
  5941. sprintf(message + strlen(message), "}]");
  5942. LWS_Send(message);
  5943. return result;
  5944. }
  5945. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5946. {
  5947. mtrace();
  5948. int result = FAIL;
  5949. char message[400]={0};
  5950. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5951. if(strcmp(payload,"")==0)
  5952. {
  5953. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5954. }
  5955. else
  5956. {
  5957. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5958. }
  5959. LWS_Send(message);
  5960. result = TRUE;
  5961. return result;
  5962. }
  5963. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5964. {
  5965. mtrace();
  5966. int result = FAIL;
  5967. char message[80]={0};
  5968. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5969. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  5970. LWS_Send(message);
  5971. result = TRUE;
  5972. return result;
  5973. }
  5974. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5975. {
  5976. mtrace();
  5977. int result = FAIL;
  5978. char message[80]={0};
  5979. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5980. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5981. LWS_Send(message);
  5982. result = TRUE;
  5983. return result;
  5984. }
  5985. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5986. {
  5987. mtrace();
  5988. int result = FAIL;
  5989. char message[80]={0};
  5990. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5991. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5992. LWS_Send(message);
  5993. result = TRUE;
  5994. return result;
  5995. }
  5996. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5997. {
  5998. mtrace();
  5999. int result = FAIL;
  6000. char message[80]={0};
  6001. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6002. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6003. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6004. LWS_Send(message);
  6005. result = TRUE;
  6006. return result;
  6007. }
  6008. int sendResetConfirmation(char *uuid,char *payload)
  6009. {
  6010. mtrace();
  6011. int result = FAIL;
  6012. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6013. char message[80]={0};
  6014. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  6015. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6016. LWS_Send(message);
  6017. result = TRUE;
  6018. return result;
  6019. }
  6020. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6021. {
  6022. mtrace();
  6023. int result = FAIL;
  6024. char message[500]={0};
  6025. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6026. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6027. LWS_Send(message);
  6028. result = TRUE;
  6029. return result;
  6030. }
  6031. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6032. {
  6033. mtrace();
  6034. int result = FAIL;
  6035. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6036. char message[80]={0};
  6037. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6038. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6039. LWS_Send(message);
  6040. result = TRUE;
  6041. return result;
  6042. }
  6043. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6044. {
  6045. mtrace();
  6046. int result = FAIL;
  6047. char message[80]={0};
  6048. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6049. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6050. LWS_Send(message);
  6051. result = TRUE;
  6052. return result;
  6053. }
  6054. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6055. {
  6056. mtrace();
  6057. int result = FAIL;
  6058. char message[80]={0};
  6059. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6060. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6061. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6062. LWS_Send(message);
  6063. result = TRUE;
  6064. return result;
  6065. }
  6066. int sendUpdateFirmwareConfirmation(char *uuid)
  6067. {
  6068. mtrace();
  6069. int result = FAIL;
  6070. char message[60]={0};
  6071. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6072. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6073. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6074. LWS_Send(message);
  6075. result = TRUE;
  6076. return result;
  6077. }
  6078. int sendCertificateSignedConfirmation(char *uuid)
  6079. {
  6080. mtrace();
  6081. int result = PASS;
  6082. char message[4096]={0};
  6083. json_object *CertificateSigned = json_object_new_object();
  6084. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6085. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  6086. sprintf(message,"[%d,\"%s\",%s]"
  6087. ,MESSAGE_TYPE_CALLRESULT
  6088. ,uuid
  6089. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6090. json_object_put(CertificateSigned);
  6091. LWS_Send(message);
  6092. return result;
  6093. }
  6094. int sendDeleteCertificateConfirmation(char *uuid)
  6095. {
  6096. mtrace();
  6097. int result = PASS;
  6098. char message[4096]={0};
  6099. json_object *DeleteCertificate = json_object_new_object();
  6100. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6101. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  6102. sprintf(message,"[%d,\"%s\",%s]"
  6103. ,MESSAGE_TYPE_CALLRESULT
  6104. ,uuid
  6105. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6106. json_object_put(DeleteCertificate);
  6107. LWS_Send(message);
  6108. return result;
  6109. }
  6110. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6111. {
  6112. mtrace();
  6113. int result = PASS;
  6114. char message[4096]={0};
  6115. json_object *ExtendedTriggerMessage = json_object_new_object();
  6116. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6117. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  6118. sprintf(message,"[%d,\"%s\",%s]"
  6119. ,MESSAGE_TYPE_CALLRESULT
  6120. ,uuid
  6121. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6122. json_object_put(ExtendedTriggerMessage);
  6123. LWS_Send(message);
  6124. return result;
  6125. }
  6126. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6127. {
  6128. mtrace();
  6129. int result = PASS;
  6130. char message[4096]={0};
  6131. json_object *GetInstalledCertificateIds = json_object_new_object();
  6132. json_object *certificateHashDataDatas = json_object_new_array();
  6133. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6134. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  6135. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6136. {
  6137. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6138. {
  6139. json_object *certificateHashData = json_object_new_object();
  6140. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6141. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6142. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6143. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6144. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6145. }
  6146. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6147. }
  6148. else
  6149. {
  6150. json_object_put(certificateHashDataDatas);
  6151. }
  6152. sprintf(message,"[%d,\"%s\",%s]"
  6153. ,MESSAGE_TYPE_CALLRESULT
  6154. ,uuid
  6155. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6156. json_object_put(GetInstalledCertificateIds);
  6157. LWS_Send(message);
  6158. return result;
  6159. }
  6160. int sendGetLogConfirmation(char *uuid)
  6161. {
  6162. mtrace();
  6163. int result = PASS;
  6164. char message[4096]={0};
  6165. json_object *GetLog = json_object_new_object();
  6166. DEBUG_INFO("sendGetLogConfirmation...\n");
  6167. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  6168. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  6169. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  6170. sprintf(message,"[%d,\"%s\",%s]"
  6171. ,MESSAGE_TYPE_CALLRESULT
  6172. ,uuid
  6173. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6174. json_object_put(GetLog);
  6175. LWS_Send(message);
  6176. return result;
  6177. }
  6178. int sendInstallCertificateConfirmation(char *uuid)
  6179. {
  6180. mtrace();
  6181. int result = PASS;
  6182. char message[4096]={0};
  6183. json_object *InstallCertificate = json_object_new_object();
  6184. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6185. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  6186. sprintf(message,"[%d,\"%s\",%s]"
  6187. ,MESSAGE_TYPE_CALLRESULT
  6188. ,uuid
  6189. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6190. json_object_put(InstallCertificate);
  6191. LWS_Send(message);
  6192. return result;
  6193. }
  6194. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6195. {
  6196. mtrace();
  6197. int result = PASS;
  6198. char message[4096]={0};
  6199. json_object *SignedUpdateFirmware = json_object_new_object();
  6200. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6201. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  6202. sprintf(message,"[%d,\"%s\",%s]"
  6203. ,MESSAGE_TYPE_CALLRESULT
  6204. ,uuid
  6205. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6206. json_object_put(SignedUpdateFirmware);
  6207. LWS_Send(message);
  6208. return result;
  6209. }
  6210. int sendUnknownConfirmation(char *uuid)
  6211. {
  6212. mtrace();
  6213. int result = PASS;
  6214. char message[256]={0};
  6215. DEBUG_INFO("sendUnknownConfirmation...\n");
  6216. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6217. LWS_Send(message);
  6218. return result;
  6219. }
  6220. //==========================================
  6221. // Handle server request routine Start
  6222. //==========================================
  6223. int handleCancelReservationRequest(char *uuid, char *payload)
  6224. {
  6225. mtrace();
  6226. int result = FAIL;
  6227. int gunNO = 0;
  6228. int reservationIdInt = -1;
  6229. char comfirmstr[20];
  6230. DEBUG_INFO("handleCancelReservationRequest...\n");
  6231. json_object *CancelReservation;
  6232. CancelReservation = json_tokener_parse(payload);
  6233. if(!is_error(CancelReservation))
  6234. {
  6235. // Required data
  6236. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6237. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6238. }
  6239. json_object_put(CancelReservation);
  6240. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6241. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6242. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6243. if(reservationIdInt != -1)
  6244. {
  6245. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6246. //check Transaction active
  6247. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6248. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6249. {
  6250. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6251. {
  6252. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6253. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6254. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6255. {
  6256. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6257. }
  6258. else
  6259. {
  6260. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6261. }
  6262. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6263. goto end;
  6264. }
  6265. }
  6266. for (int index = 0; index < CCS_QUANTITY; index++)
  6267. {
  6268. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6269. {
  6270. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6271. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6272. if(gunType[2] == GUN_TYPE_CCS)
  6273. {
  6274. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6275. }
  6276. else
  6277. {
  6278. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6279. }
  6280. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6281. goto end;
  6282. }
  6283. }
  6284. for (int index = 0; index < GB_QUANTITY; index++)
  6285. {
  6286. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6287. {
  6288. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6289. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6290. if(gunType[2] == GUN_TYPE_GBT)
  6291. {
  6292. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6293. }
  6294. else
  6295. {
  6296. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6297. }
  6298. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6299. goto end;
  6300. }
  6301. }
  6302. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6303. {
  6304. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6305. {
  6306. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6307. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6308. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6309. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6310. goto end;
  6311. }
  6312. }
  6313. for (int index = 0; index < AC_QUANTITY; index++)
  6314. {
  6315. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6316. {
  6317. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6318. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6320. {
  6321. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6322. }
  6323. else
  6324. {
  6325. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6326. }
  6327. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6328. goto end;
  6329. }
  6330. }
  6331. }
  6332. //The reservationId does NOT match the reservationId
  6333. sendCancelReservationConfirmation(uuid, comfirmstr);
  6334. end:
  6335. // Fill in ocpp packet uuid
  6336. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  6337. return result;
  6338. }
  6339. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6340. {
  6341. mtrace();
  6342. int result = FAIL;
  6343. int gunIndex = 0;
  6344. char typeStr[16]={0};
  6345. char comfirmstr[20];
  6346. int specificId = FALSE;
  6347. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6348. json_object *ChangeAvailability;
  6349. ChangeAvailability = json_tokener_parse(payload);
  6350. if(!is_error(ChangeAvailability))
  6351. {
  6352. // Required data
  6353. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6354. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6355. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6356. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6357. }
  6358. json_object_put(ChangeAvailability);
  6359. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6360. {
  6361. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6362. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6363. }
  6364. else if(gunIndex == 0)
  6365. {
  6366. for(int i=0; i < gunTotalNumber; i++)
  6367. {
  6368. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  6369. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  6370. }
  6371. }
  6372. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6373. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6374. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6375. {
  6376. specificId = TRUE;
  6377. }
  6378. if(specificId == FALSE)
  6379. goto end;
  6380. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6381. {
  6382. //----------------------gunIndex is 0 ------------------------------------------------//
  6383. if(gunIndex == 0)
  6384. {
  6385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6386. {
  6387. for(int i=0; i < gunTotalNumber; i++)
  6388. {
  6389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6390. {
  6391. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6392. {
  6393. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6394. {
  6395. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6396. goto end;
  6397. }
  6398. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6399. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6400. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6401. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6402. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6403. {
  6404. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6405. goto end;
  6406. }
  6407. }
  6408. }//END FOR CHAdeMO_QUANTITY
  6409. for (int index = 0; index < CCS_QUANTITY; index++)
  6410. {
  6411. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6412. {
  6413. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6414. {
  6415. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6416. goto end;
  6417. }
  6418. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6419. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6420. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6421. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6422. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6423. {
  6424. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6425. goto end;
  6426. }
  6427. }
  6428. }//END FOR CCS_QUANTITY
  6429. for (int index = 0; index < GB_QUANTITY; index++)
  6430. {
  6431. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6432. {
  6433. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6434. {
  6435. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6436. goto end;
  6437. }
  6438. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6439. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6440. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6441. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6442. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6443. {
  6444. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6445. goto end;
  6446. }
  6447. }
  6448. }// END FOR GB_QUANTITY
  6449. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6450. {
  6451. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6452. {
  6453. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6454. {
  6455. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6456. goto end;
  6457. }
  6458. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6459. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6460. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6461. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6462. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6463. {
  6464. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6465. goto end;
  6466. }
  6467. }
  6468. }// END FOR GENERAL_GUN_QUANTITY
  6469. for (int index = 0; index < AC_QUANTITY; index++)
  6470. {
  6471. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6472. {
  6473. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6474. {
  6475. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6476. goto end;
  6477. }
  6478. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6479. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6480. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6481. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6482. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6483. {
  6484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6485. goto end;
  6486. }
  6487. }
  6488. }//END FOR AC_QUANTITY
  6489. }// END FOR gunTotalNumber
  6490. }
  6491. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6492. {
  6493. for(int i=0; i < gunTotalNumber; i++)
  6494. {
  6495. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6496. {
  6497. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6498. goto end;
  6499. }
  6500. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6501. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6502. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6503. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6504. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6505. {
  6506. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6507. goto end;
  6508. }
  6509. }
  6510. }
  6511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6512. goto end;
  6513. }
  6514. //----------------------gunIndex is not 0 ------------------------------------------------//
  6515. //check Transaction active
  6516. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6517. {
  6518. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6519. {
  6520. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6521. {
  6522. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6523. goto end;
  6524. }
  6525. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6526. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6527. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6528. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6529. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6530. {
  6531. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6532. goto end;
  6533. }
  6534. else
  6535. {
  6536. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6537. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6538. goto end;
  6539. }
  6540. }
  6541. }//END FOR CHAdeMO_QUANTITY
  6542. for (int index = 0; index < CCS_QUANTITY; index++)
  6543. {
  6544. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6545. {
  6546. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6547. {
  6548. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6549. goto end;
  6550. }
  6551. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6552. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6553. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6554. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6555. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6556. {
  6557. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6558. goto end;
  6559. }
  6560. else
  6561. {
  6562. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6563. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6564. goto end;
  6565. }
  6566. }
  6567. }//END FOR CCS_QUANTITY
  6568. for (int index = 0; index < GB_QUANTITY; index++)
  6569. {
  6570. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6571. {
  6572. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6573. {
  6574. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6575. goto end;
  6576. }
  6577. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6578. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6579. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6580. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6581. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6582. {
  6583. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6584. goto end;
  6585. }
  6586. else
  6587. {
  6588. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6589. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6590. goto end;
  6591. }
  6592. }
  6593. }// END FOR GB_QUANTITY
  6594. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6595. {
  6596. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6597. {
  6598. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6599. {
  6600. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6601. goto end;
  6602. }
  6603. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6604. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6605. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6606. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6607. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6608. {
  6609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6610. goto end;
  6611. }
  6612. else
  6613. {
  6614. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6615. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6616. goto end;
  6617. }
  6618. }
  6619. }// END FOR GENERAL_GUN_QUANTITY
  6620. for (int index = 0; index < AC_QUANTITY; index++)
  6621. {
  6622. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6623. {
  6624. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6625. {
  6626. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6627. goto end;
  6628. }
  6629. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6630. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6631. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6632. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6633. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6634. {
  6635. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6636. goto end;
  6637. }
  6638. else
  6639. {
  6640. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6641. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6642. goto end;
  6643. }
  6644. }
  6645. }//END FOR AC_QUANTITY
  6646. }//END FOR AvailabilityTypeStr[Inoperative]
  6647. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6648. {
  6649. //----------------------gunIndex is 0 ------------------------------------------------//
  6650. if(gunIndex == 0)
  6651. {
  6652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6653. {
  6654. for(int i=0; i < gunTotalNumber; i++)
  6655. {
  6656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6657. {
  6658. 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
  6659. {
  6660. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6661. goto end;
  6662. }
  6663. }//END FOR CHAdeMO_QUANTITY
  6664. for (int index = 0; index < CCS_QUANTITY; index++)
  6665. {
  6666. 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
  6667. {
  6668. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6669. goto end;
  6670. }
  6671. }//END FOR CCS_QUANTITY
  6672. for (int index = 0; index < GB_QUANTITY; index++)
  6673. {
  6674. 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
  6675. {
  6676. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6678. goto end;
  6679. }
  6680. }// END FOR GB_QUANTITY
  6681. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6682. {
  6683. 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
  6684. {
  6685. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6686. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6687. goto end;
  6688. }
  6689. }// END FOR GENERAL_GUN_QUANTITY
  6690. for (int index = 0; index < AC_QUANTITY; index++)
  6691. {
  6692. 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
  6693. {
  6694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6695. goto end;
  6696. }
  6697. }//END FOR CHAdeMO_QUANTITY
  6698. }// END FOR gunTotalNumber
  6699. }
  6700. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6701. {
  6702. for(int i=0; i < gunTotalNumber; i++)
  6703. {
  6704. for (int index = 0; index < AC_QUANTITY; index++)
  6705. {
  6706. 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
  6707. {
  6708. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6709. goto end;
  6710. }
  6711. }//END FOR CHAdeMO_QUANTITY
  6712. } // END FOR gunTotalNumber
  6713. }
  6714. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6715. goto end;
  6716. }
  6717. //----------------------gunIndex is not 0 ------------------------------------------------//
  6718. //check Transaction active
  6719. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6720. {
  6721. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6722. {
  6723. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6724. goto end;
  6725. }
  6726. }//END FOR CHAdeMO_QUANTITY
  6727. for (int index = 0; index < CCS_QUANTITY; index++)
  6728. {
  6729. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6730. {
  6731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6732. goto end;
  6733. }
  6734. }//END FOR CCS_QUANTITY
  6735. for (int index = 0; index < GB_QUANTITY; index++)
  6736. {
  6737. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6738. {
  6739. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6740. goto end;
  6741. }
  6742. }// END FOR GB_QUANTITY
  6743. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6744. {
  6745. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6746. {
  6747. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6748. goto end;
  6749. }
  6750. }// END FOR GENERAL_GUN_QUANTITY
  6751. for (int index = 0; index < AC_QUANTITY; index++)
  6752. {
  6753. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6754. {
  6755. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6756. goto end;
  6757. }
  6758. }//END FOR AC_QUANTITY
  6759. }//END FOR AvailabilityTypeStr[Operative]
  6760. end:
  6761. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6762. {
  6763. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6764. }
  6765. else
  6766. {
  6767. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6768. }
  6769. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6770. {
  6771. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6772. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6773. }
  6774. else if(gunIndex == 0)
  6775. {
  6776. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6777. {
  6778. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6779. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6780. }
  6781. }
  6782. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6783. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6784. return result;
  6785. }
  6786. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6787. {
  6788. mtrace();
  6789. int result = FAIL;
  6790. char keystr[40]={0};
  6791. char valuestr[256]={0};
  6792. char comfirmstr[20]={0};
  6793. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6794. json_object *ChangeConfiguration;
  6795. ChangeConfiguration = json_tokener_parse(payload);
  6796. if(!is_error(ChangeConfiguration))
  6797. {
  6798. // Required data
  6799. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6800. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6801. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6802. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6803. }
  6804. json_object_put(ChangeConfiguration);
  6805. if((uuid==NULL) || (payload ==NULL) )
  6806. {
  6807. DEBUG_ERROR("Payload is null\n");
  6808. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6809. }
  6810. else
  6811. {
  6812. int status = setKeyValue(keystr, valuestr);
  6813. switch(status)
  6814. {
  6815. case ConfigurationStatus_Accepted:
  6816. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6817. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  6818. StoreConfigurationTable();
  6819. break;
  6820. case RebootRequired:
  6821. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6822. StoreConfigurationTable();
  6823. break;
  6824. case NotSupported:
  6825. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6826. break;
  6827. case ConfigurationStatus_Rejected:
  6828. default:
  6829. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6830. break;
  6831. }
  6832. }
  6833. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6834. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  6835. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6836. {
  6837. ChageWebSocketPingInterval(atoi(valuestr));
  6838. }
  6839. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  6840. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6841. {
  6842. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  6843. SetOcppConnStatus(FALSE);
  6844. }
  6845. return result;
  6846. }
  6847. int handleClearCacheRequest(char *uuid, char *payload)
  6848. {
  6849. mtrace();
  6850. int result = FAIL;
  6851. char comfirmstr[20];
  6852. char rmFileCmd[100]={0};
  6853. struct stat stats;
  6854. DEBUG_INFO("handleClearCacheRequest...\n");
  6855. stat("/Storage/OCPP_PH", &stats);
  6856. // Check for directory existence
  6857. if (S_ISDIR(stats.st_mode) == 1)
  6858. {}
  6859. else
  6860. {
  6861. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6862. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  6863. system(rmFileCmd);
  6864. }
  6865. if(OCPP_cleanLocalCache())
  6866. {
  6867. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6868. }
  6869. else
  6870. {
  6871. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6872. }
  6873. sendClearCacheConfirmation(uuid, comfirmstr);
  6874. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6875. return result;
  6876. }
  6877. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6878. {
  6879. mtrace();
  6880. int result = FAIL;
  6881. int resultRename;
  6882. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6883. char chargingProfilePurposeStr[26]={0};
  6884. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6885. char tempchargingProfilePurposeStr[26]={0};
  6886. char str[100]={0};
  6887. char fname[200]={0};
  6888. char comfirmstr[20]={0};
  6889. char word[1600]={0};
  6890. int clearflag = FALSE;
  6891. int chargingProfileIdIsNULL = FALSE;
  6892. int connectorIsNULL = FALSE;
  6893. int chargingProfilePurposeIsNULL = FALSE;
  6894. int stackLevelIsNULL = FALSE;
  6895. //int GotoEnd = FALSE;
  6896. FILE *fptr1, *fptr2;
  6897. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  6898. int n_chargingProfile=0;
  6899. int isEmptyFile = FALSE;
  6900. char sLineWord[1600]={0};
  6901. char chargingProfiles[10][100]={0};
  6902. int ChargeProfileCount = 0;
  6903. int ch;
  6904. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6905. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6906. json_object *ClearChargingProfile;
  6907. ClearChargingProfile = json_tokener_parse(payload);
  6908. if(!is_error(ClearChargingProfile))
  6909. {
  6910. // Optional data
  6911. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6912. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6913. else
  6914. chargingProfileIdIsNULL = TRUE;
  6915. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6916. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6917. else
  6918. connectorIsNULL = TRUE;
  6919. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6920. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6921. else
  6922. chargingProfilePurposeIsNULL = TRUE;
  6923. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6924. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6925. else
  6926. stackLevelIsNULL = TRUE;
  6927. }
  6928. json_object_put(ClearChargingProfile);
  6929. if(connectorIsNULL == FALSE)
  6930. {
  6931. switch(connectorIdInt)
  6932. {
  6933. case 0:
  6934. if(chargingProfilePurposeIsNULL == TRUE)
  6935. {
  6936. int l = 0;
  6937. strcpy(fname, ChargePointMaxProfile_JSON);
  6938. if((access(fname,F_OK))!=-1)
  6939. {
  6940. strcpy(chargingProfiles[l], fname);
  6941. l = l + 1;
  6942. }
  6943. strcpy(fname, TxDefaultProfile_0_JSON);
  6944. if((access(fname,F_OK))!=-1)
  6945. {
  6946. strcpy(chargingProfiles[l], fname);
  6947. l = l + 1;
  6948. }
  6949. ChargeProfileCount = l;
  6950. }
  6951. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6952. {
  6953. strcpy(fname, ChargePointMaxProfile_JSON);
  6954. if((access(fname,F_OK))!=-1)
  6955. {
  6956. strcpy(chargingProfiles[0], fname);
  6957. ChargeProfileCount = 1;
  6958. }
  6959. }
  6960. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6961. {
  6962. strcpy(fname, TxDefaultProfile_0_JSON);
  6963. if((access(fname,F_OK))!=-1)
  6964. {
  6965. strcpy(chargingProfiles[0], fname);
  6966. ChargeProfileCount = 1;
  6967. }
  6968. }
  6969. break;
  6970. default:
  6971. if(chargingProfilePurposeIsNULL == TRUE)
  6972. {
  6973. int m = 0;
  6974. memset(fname, 0, ARRAY_SIZE(fname));
  6975. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  6976. if((access(fname,F_OK))!=-1)
  6977. {
  6978. strcpy(chargingProfiles[m], fname);
  6979. m = m + 1;
  6980. }
  6981. memset(fname, 0, ARRAY_SIZE(fname));
  6982. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  6983. if((access(fname,F_OK))!=-1)
  6984. {
  6985. strcpy(chargingProfiles[m], fname);
  6986. m = m + 1;
  6987. }
  6988. ChargeProfileCount = m;
  6989. }
  6990. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6991. {
  6992. //strcpy(fname, TxDefaultProfile_1_JSON);
  6993. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  6994. if((access(fname,F_OK))!=-1)
  6995. {
  6996. strcpy(chargingProfiles[0], fname);
  6997. ChargeProfileCount = 1;
  6998. }
  6999. }
  7000. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7001. {
  7002. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7003. if((access(fname,F_OK))!=-1)
  7004. {
  7005. strcpy(chargingProfiles[0], fname);
  7006. ChargeProfileCount = 1;
  7007. }
  7008. //strcpy(fname, TxProfile_1_JSON);
  7009. }
  7010. //strcpy(fname, ChargePointMaxProfile_JSON );
  7011. break;
  7012. }
  7013. }
  7014. else // Check all Charging Profiles
  7015. {
  7016. int i = 0;
  7017. char fnametemp[200]={0};
  7018. ChargeProfileCount = 0;
  7019. //Check ChargePointMaxProfile.json exit
  7020. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  7021. {
  7022. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  7023. i = i + 1;
  7024. }
  7025. //Check TxDefaultProfile_0.json exit
  7026. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  7027. {
  7028. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  7029. i = i + 1;
  7030. }
  7031. //Check TxDefaultProfile_%d.json
  7032. for(int j=1; j <= gunTotalNumber; j++)
  7033. {
  7034. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7035. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  7036. if((access(fnametemp,F_OK))!=-1)
  7037. {
  7038. strcpy(chargingProfiles[i], fnametemp);
  7039. i = i + 1;
  7040. }
  7041. }
  7042. //Check TxProfile_%d.json
  7043. for(int j=1; j <= gunTotalNumber; j++)
  7044. {
  7045. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7046. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  7047. if((access(fnametemp,F_OK))!=-1)
  7048. {
  7049. strcpy(chargingProfiles[i], fnametemp);
  7050. i = i + 1;
  7051. }
  7052. }
  7053. ChargeProfileCount = i;
  7054. }// End connectorIsNULL is TRUE
  7055. if(ChargeProfileCount == 0)
  7056. {
  7057. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7058. goto end;
  7059. }
  7060. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7061. {
  7062. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7063. goto end;
  7064. }
  7065. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7066. {
  7067. memset(str, 0, ARRAY_SIZE(str));
  7068. // clear temp file
  7069. sprintf(str,"rm -f %s",temp);
  7070. system(str);
  7071. for(int k=0; k < ChargeProfileCount; k++)
  7072. {
  7073. memset(str, 0, ARRAY_SIZE(str));
  7074. //clear file in C
  7075. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7076. system(str);
  7077. }
  7078. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7079. goto end;
  7080. }
  7081. else if(connectorIsNULL == TRUE)
  7082. {
  7083. for(int k=0; k < ChargeProfileCount; k++)
  7084. {
  7085. fptr1 = fopen(chargingProfiles[k], "r");
  7086. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  7087. //Check Charging Profile Count
  7088. while(fscanf(fptr1, "%s", word) != EOF)
  7089. {
  7090. //DEBUG_INFO("word=%s\n",word);
  7091. if(strstr(word, "chargingProfileId")!= NULL)
  7092. {
  7093. //DEBUG_INFO("test chargingProfileId \n");
  7094. n_chargingProfile = n_chargingProfile + 1;
  7095. //DEBUG_INFO("chargingProfileId Found\n");
  7096. }
  7097. }
  7098. rewind(fptr1);
  7099. //search Charging Profile Element
  7100. //int i= 0;
  7101. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7102. {
  7103. json_object *tmpProfilee;
  7104. tmpProfilee = json_tokener_parse(sLineWord);
  7105. if(!is_error(tmpProfilee))
  7106. {
  7107. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7108. {
  7109. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7110. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7111. }
  7112. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7113. {
  7114. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7115. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7116. }
  7117. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7118. {
  7119. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7120. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7121. }
  7122. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7123. {
  7124. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7125. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7126. }
  7127. }
  7128. json_object_put(tmpProfilee);
  7129. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7130. {
  7131. //------- not write to fptr2-------//
  7132. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7133. //clearflag = TRUE;
  7134. }
  7135. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7136. {
  7137. //------- not write to fptr2-------//
  7138. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7139. }
  7140. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7141. {
  7142. //------- not write to fptr2-------//
  7143. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7144. }
  7145. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7146. {
  7147. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7148. }
  7149. else
  7150. {
  7151. fprintf(fptr2, sLineWord);//writing data into file
  7152. }
  7153. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7154. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7155. if(clearflag == TRUE)
  7156. {
  7157. fclose(fptr1);
  7158. fclose(fptr2);
  7159. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7160. system(str);
  7161. // clear temp file
  7162. sprintf(str,"rm -f %s",temp);
  7163. system(str);
  7164. }
  7165. else
  7166. {
  7167. fclose(fptr1);
  7168. fclose(fptr2);
  7169. memset(str, 0, ARRAY_SIZE(str));
  7170. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7171. system(str);
  7172. resultRename = rename(temp, chargingProfiles[k]);
  7173. if(resultRename == 0)
  7174. {
  7175. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7176. }
  7177. else
  7178. {
  7179. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7180. }
  7181. if(comfirmstr[0]== 0)
  7182. {
  7183. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7184. }
  7185. //Check chargingProfile is empty file
  7186. /*------ Read the file ----------------*/
  7187. fptr1=fopen(chargingProfiles[k],"r");
  7188. ch=fgetc(fptr1);
  7189. rewind(fptr1);
  7190. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7191. if(ch!=EOF)
  7192. {
  7193. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7194. {
  7195. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7196. if(sLineWord[0]=='\0')
  7197. {
  7198. isEmptyFile = TRUE;
  7199. break;
  7200. }
  7201. else
  7202. {
  7203. isEmptyFile = FALSE;
  7204. break;
  7205. }
  7206. }
  7207. }
  7208. else
  7209. isEmptyFile = TRUE;
  7210. fclose(fptr1);
  7211. if(isEmptyFile == TRUE)
  7212. {
  7213. memset(str, 0, ARRAY_SIZE(str));
  7214. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7215. system(str);
  7216. }
  7217. }
  7218. }// End of while(int k=0; k < ChargePointCount; k++)
  7219. }
  7220. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7221. {
  7222. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7223. for(int k=0; k < ChargeProfileCount; k++)
  7224. {
  7225. fptr1 = fopen(chargingProfiles[k], "r");
  7226. fptr2 = fopen(temp, "w+");
  7227. //Check Charging Profile Count
  7228. while(fscanf(fptr1, "%s", word) != EOF)
  7229. {
  7230. //DEBUG_INFO("word=%s\n",word);
  7231. if(strstr(word, "chargingProfileId")!= NULL)
  7232. {
  7233. n_chargingProfile = n_chargingProfile + 1;
  7234. }
  7235. }
  7236. rewind(fptr1);
  7237. //search Charging Profile Element
  7238. //int i= 0;
  7239. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7240. {
  7241. json_object *tmpProfilee;
  7242. tmpProfilee = json_tokener_parse(sLineWord);
  7243. if(!is_error(tmpProfilee))
  7244. {
  7245. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7246. {
  7247. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7248. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7249. }
  7250. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7251. {
  7252. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7253. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7254. }
  7255. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7256. {
  7257. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7258. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7259. }
  7260. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7261. {
  7262. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7263. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7264. }
  7265. }
  7266. json_object_put(tmpProfilee);
  7267. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7268. {
  7269. //------- not write to fptr2-------//
  7270. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7271. //clearflag = TRUE;
  7272. }
  7273. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7274. {
  7275. //------- not write to fptr2-------//
  7276. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7277. }
  7278. else if(stackLevelIsNULL == TRUE)
  7279. {
  7280. //Clear Whole File
  7281. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7282. clearflag = TRUE;
  7283. break;
  7284. }
  7285. else
  7286. {
  7287. fprintf(fptr2, sLineWord);//writing data into file
  7288. }
  7289. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7290. }
  7291. if(clearflag == TRUE)
  7292. {
  7293. fclose(fptr1);
  7294. fclose(fptr2);
  7295. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7296. system(str);
  7297. // clear temp file
  7298. sprintf(str,"rm -f %s",temp);
  7299. system(str);
  7300. }
  7301. else
  7302. {
  7303. fclose(fptr1);
  7304. fclose(fptr2);
  7305. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7306. system(str);
  7307. resultRename = rename(temp, chargingProfiles[k]);
  7308. if(resultRename == 0)
  7309. {
  7310. DEBUG_INFO("File ChargingProfile renamed successfully");
  7311. }
  7312. else
  7313. {
  7314. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7315. }
  7316. if(comfirmstr[0]== 0)
  7317. {
  7318. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7319. }
  7320. //Check chargingProfile is empty file
  7321. /*------ Read the file ----------------*/
  7322. fptr1=fopen(chargingProfiles[k],"r");
  7323. ch=fgetc(fptr1);
  7324. rewind(fptr1);
  7325. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7326. if(ch!=EOF)
  7327. {
  7328. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7329. {
  7330. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7331. if(sLineWord[0]=='\0')
  7332. {
  7333. isEmptyFile = TRUE;
  7334. break;
  7335. }
  7336. else
  7337. {
  7338. isEmptyFile = FALSE;
  7339. break;
  7340. }
  7341. }
  7342. }
  7343. else
  7344. isEmptyFile = TRUE;
  7345. fclose(fptr1);
  7346. if(isEmptyFile == TRUE)
  7347. {
  7348. memset(str, 0, ARRAY_SIZE(str));
  7349. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7350. system(str);
  7351. }
  7352. /*------- End of reading ---------------*/
  7353. }
  7354. } // while(int k=0; k < ChargeProfileCount; k++)
  7355. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7356. end:
  7357. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7358. {
  7359. if(connectorIdInt == 0)
  7360. {
  7361. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7362. {
  7363. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  7364. }
  7365. }
  7366. else
  7367. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  7368. }
  7369. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7370. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7371. return result;
  7372. }
  7373. void createFirmwareVersionByDataTransfer(void)
  7374. {
  7375. json_object *FirmwareDataTransfer = json_object_new_object();
  7376. // AC & DC model
  7377. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7378. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7379. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7380. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7381. // DC model
  7382. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7383. {
  7384. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7385. {
  7386. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7387. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7388. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7389. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7390. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7391. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7392. }
  7393. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7394. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7395. {
  7396. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7397. }
  7398. }
  7399. else
  7400. {
  7401. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7402. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7403. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7404. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7405. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7406. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7407. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7408. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7409. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7410. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7411. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7412. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7413. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7414. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7415. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7416. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7417. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7418. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7419. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7420. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7421. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7422. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7423. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7424. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7425. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7426. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7427. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7428. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7429. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7430. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7431. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7432. }
  7433. // 4G model
  7434. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7435. {
  7436. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7437. }
  7438. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7439. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7440. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7441. json_object_put(FirmwareDataTransfer);
  7442. }
  7443. int handleDataTransferRequest(char *uuid, char *payload)
  7444. {
  7445. mtrace();
  7446. json_object *response = json_object_new_object();
  7447. int result = FAIL;
  7448. char tempvendorId[255]={0};
  7449. char tempmessageId[50]={0};
  7450. char tempdata[512]={0};
  7451. char message[2048]={0};
  7452. DEBUG_INFO("handleDataTransferRequest...\n");
  7453. if((uuid != NULL) && (payload != NULL))
  7454. {
  7455. json_object *DataTransfer;
  7456. DataTransfer = json_tokener_parse(payload);
  7457. if(!is_error(DataTransfer))
  7458. {
  7459. // Required data
  7460. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7461. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7462. // Optional data
  7463. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7464. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7465. if(json_object_object_get(DataTransfer, "data") != NULL)
  7466. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7467. result = PASS;
  7468. }
  7469. json_object_put(DataTransfer);
  7470. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7471. {
  7472. // Send all moudle firmware version on EVSE
  7473. createFirmwareVersionByDataTransfer();
  7474. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7475. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  7476. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7477. json_object_put(response);
  7478. }
  7479. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7480. {
  7481. system("/usr/bin/run_tmate_restart.sh &");
  7482. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7483. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7484. json_object_put(response);
  7485. }
  7486. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7487. {
  7488. json_object *data;
  7489. data = json_tokener_parse(tempdata);
  7490. if(!is_error(data))
  7491. {
  7492. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7493. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7494. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7495. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7496. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7497. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7498. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7499. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7500. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7501. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7502. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7503. }
  7504. else
  7505. {
  7506. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7507. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7508. }
  7509. json_object_put(data);
  7510. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7511. json_object_put(response);
  7512. }
  7513. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7514. {
  7515. json_object *data;
  7516. data = json_tokener_parse(tempdata);
  7517. if(!is_error(data))
  7518. {
  7519. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7520. if(json_object_object_get(data, "idToken") != NULL)
  7521. {
  7522. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7523. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7524. }
  7525. if(json_object_object_get(data, "price") != NULL)
  7526. {
  7527. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7528. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7529. }
  7530. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7531. }
  7532. else
  7533. {
  7534. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7535. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7536. }
  7537. json_object_put(data);
  7538. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7539. json_object_put(response);
  7540. }
  7541. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7542. {
  7543. json_object *data;
  7544. data = json_tokener_parse(tempdata);
  7545. if(!is_error(data))
  7546. {
  7547. if(json_object_object_get(data, "txId") != NULL)
  7548. {
  7549. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7550. for(int idx = 0;idx<gunTotalNumber;idx++)
  7551. {
  7552. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7553. {
  7554. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7555. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7556. if(json_object_object_get(data, "description") != NULL)
  7557. {
  7558. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7559. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7560. }
  7561. }
  7562. }
  7563. }
  7564. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7565. }
  7566. else
  7567. {
  7568. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7569. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7570. }
  7571. json_object_put(data);
  7572. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7573. json_object_put(response);
  7574. }
  7575. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7576. {
  7577. json_object *data;
  7578. data = json_tokener_parse(tempdata);
  7579. if(!is_error(data))
  7580. {
  7581. if(json_object_object_get(data, "txId") != NULL)
  7582. {
  7583. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7584. for(int idx = 0;idx<gunTotalNumber;idx++)
  7585. {
  7586. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7587. {
  7588. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7589. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7590. if(json_object_object_get(data, "description") != NULL)
  7591. {
  7592. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7593. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7594. }
  7595. }
  7596. }
  7597. }
  7598. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7599. }
  7600. else
  7601. {
  7602. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7603. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7604. }
  7605. json_object_put(data);
  7606. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7607. json_object_put(response);
  7608. }
  7609. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7610. {
  7611. json_object *data;
  7612. data = json_tokener_parse(tempdata);
  7613. if(!is_error(data))
  7614. {
  7615. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7616. if(json_object_object_get(data, "Content_Type") != NULL)
  7617. {
  7618. 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))
  7619. {
  7620. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7621. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7622. {
  7623. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7624. }
  7625. }
  7626. else
  7627. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7628. }
  7629. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7630. }
  7631. else
  7632. {
  7633. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7634. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7635. }
  7636. json_object_put(data);
  7637. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7638. json_object_put(response);
  7639. }
  7640. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  7641. {
  7642. json_object *data;
  7643. data = json_tokener_parse(tempdata);
  7644. if(!is_error(data))
  7645. {
  7646. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7647. if(json_object_object_get(data, "Page_Index") != NULL)
  7648. {
  7649. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7650. }
  7651. if(json_object_object_get(data, "Duration") != NULL)
  7652. {
  7653. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7654. }
  7655. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7656. }
  7657. else
  7658. {
  7659. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7660. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7661. }
  7662. json_object_put(data);
  7663. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7664. json_object_put(response);
  7665. }
  7666. else
  7667. {
  7668. // Can not find valid message id
  7669. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7670. }
  7671. }
  7672. else
  7673. {
  7674. // Payload is null
  7675. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7676. }
  7677. LWS_Send(message);
  7678. return result;
  7679. }
  7680. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7681. {
  7682. mtrace();
  7683. int result = FAIL;
  7684. int connectorIdInt, durationInt;
  7685. char chargingRateUnitStr[4]={0};
  7686. char comfirmstr[20];
  7687. int confirmPeriods = 0;
  7688. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7689. json_object *GetCompositeSchedule;
  7690. GetCompositeSchedule = json_tokener_parse(payload);
  7691. if(!is_error(GetCompositeSchedule))
  7692. {
  7693. // Required data
  7694. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7695. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7696. else
  7697. connectorIdInt = -1;
  7698. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7699. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7700. else
  7701. durationInt = 86400;
  7702. // Optional data
  7703. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7704. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7705. }
  7706. json_object_put(GetCompositeSchedule);
  7707. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7708. if((connectorIdInt == 0) ||
  7709. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7710. {
  7711. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7712. struct StructChargingProfile tmpProfile[1];
  7713. if(strstr(chargingRateUnitStr, "W") != NULL)
  7714. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7715. else
  7716. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7717. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7718. {
  7719. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7720. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7721. }
  7722. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7723. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7724. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7725. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7726. {
  7727. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7728. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7729. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7730. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7731. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7732. {
  7733. confirmPeriods = idx;
  7734. break;
  7735. }
  7736. }
  7737. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7738. {
  7739. confirmPeriods += 1;
  7740. }
  7741. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7742. }
  7743. else
  7744. {
  7745. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7746. }
  7747. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7748. return result;
  7749. }
  7750. int handleGetConfigurationRequest(char *uuid, char *payload)
  7751. {
  7752. mtrace();
  7753. int result = FAIL;
  7754. int MaxKeySupported = 0;
  7755. int n_keys = 0;
  7756. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7757. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7758. json_object *GetConfiguration;
  7759. GetConfiguration = json_tokener_parse(payload);
  7760. if(!is_error(GetConfiguration))
  7761. {
  7762. // Optional data
  7763. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7764. {
  7765. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7766. {
  7767. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7768. n_keys = idx + 1;
  7769. }
  7770. }
  7771. }
  7772. json_object_put(GetConfiguration);
  7773. UnknownKeynum = 0;
  7774. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7775. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7776. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7777. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7778. if(n_keys != 0)
  7779. {
  7780. for(int i=0;i<n_keys;i++)
  7781. {
  7782. getKeyValue(requestKey[i]);
  7783. }
  7784. }
  7785. else
  7786. {
  7787. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7788. getKeyValue("");
  7789. }
  7790. processUnkownKey();
  7791. sendGetConfigurationConfirmation(uuid);
  7792. return result;
  7793. }
  7794. static char fnamePlusPath[100]={0};
  7795. static char fnamePWithNoPath[60]={0};
  7796. void checkUploadLog(void)
  7797. {
  7798. FILE *fp;
  7799. /* Open the command for reading. */
  7800. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7801. if (fp == NULL) {
  7802. printf("Failed to run command\n" );
  7803. exit(1);
  7804. }
  7805. int ftppathlen = 0;
  7806. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7807. int i = 0;
  7808. /* Read the output a line at a time - output it. */
  7809. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7810. if(i==0)
  7811. {
  7812. ftppathlen = strlen(fnamePlusPath);
  7813. printf("%s\n", fnamePlusPath);
  7814. fnamePlusPath[ftppathlen]='\0';
  7815. break;
  7816. }
  7817. i= i+1;
  7818. }
  7819. /* close */
  7820. pclose(fp);
  7821. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7822. {
  7823. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7824. {
  7825. fnamePlusPath[k]='\0';
  7826. }
  7827. }
  7828. i=1;
  7829. //char fname[60]={0};
  7830. while(i < ftppathlen)
  7831. {
  7832. int len=ftppathlen-i;
  7833. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7834. {
  7835. printf("compare '/' all right\n");
  7836. break;
  7837. }
  7838. i=i+1;
  7839. }
  7840. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7841. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7842. fnamePWithNoPath[i+1] = '\0';
  7843. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7844. {
  7845. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7846. {
  7847. fnamePWithNoPath[j]='\0';
  7848. }
  7849. }
  7850. FILE* fp1 = fopen(fnamePlusPath, "r");
  7851. if (fp1)
  7852. {
  7853. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7854. // file exists
  7855. fclose(fp1);
  7856. }
  7857. else
  7858. {
  7859. // file doesn't exist
  7860. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7861. }
  7862. }
  7863. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7864. {
  7865. mtrace();
  7866. int result = FAIL;
  7867. time_t CurrentTime;
  7868. struct tm *tm;
  7869. pthread_t th_Status;
  7870. CurrentTime = time(NULL);
  7871. tm = localtime(&CurrentTime);
  7872. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  7873. 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);
  7874. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  7875. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7876. return result;
  7877. }
  7878. void* GetDiagnosticsProcess(void* data)
  7879. {
  7880. pthread_detach(pthread_self());
  7881. mtrace();
  7882. int retriesInt=0, retryIntervalInt=0;
  7883. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7884. 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};
  7885. int port=0;
  7886. int isSuccess = FALSE;
  7887. char ftpbuf[200]={0};
  7888. char cmdBuf[2048];
  7889. struct tm *tmNow;
  7890. time_t CurrentTime;
  7891. struct tm tmStart;
  7892. struct tm tmStop;
  7893. CurrentTime = time(NULL);
  7894. tmNow=localtime(&CurrentTime);
  7895. uint16_t targetYear, targetMonth;
  7896. json_object *GetDiagnostics;
  7897. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7898. GetDiagnostics = json_tokener_parse(data);
  7899. if(!is_error(GetDiagnostics))
  7900. {
  7901. // Required data
  7902. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7903. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7904. // Optional data
  7905. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7906. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7907. else
  7908. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7909. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7910. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7911. else
  7912. retryIntervalInt = 30;
  7913. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7914. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7915. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7916. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7917. }
  7918. json_object_put(GetDiagnostics);
  7919. // Pack log to compress file
  7920. 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) &&
  7921. (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))
  7922. {
  7923. // Pack system log
  7924. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7925. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7926. targetYear = tmStart.tm_year;
  7927. targetMonth = tmStart.tm_mon;
  7928. do
  7929. {
  7930. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7931. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7932. if(targetMonth+1>=13)
  7933. {
  7934. targetYear += 1;
  7935. targetMonth = 1;
  7936. }
  7937. else
  7938. {
  7939. targetMonth += 1;
  7940. }
  7941. }while((targetYear < (tmNow->tm_year+1900)) ||
  7942. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7943. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7944. system(cmdBuf);
  7945. // Pack charging & event log
  7946. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7947. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7948. targetYear = tmStart.tm_year;
  7949. targetMonth = tmStart.tm_mon;
  7950. do
  7951. {
  7952. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7953. if(targetMonth+1>=13)
  7954. {
  7955. targetYear += 1;
  7956. targetMonth = 1;
  7957. }
  7958. else
  7959. {
  7960. targetMonth += 1;
  7961. }
  7962. }while((targetYear < (tmNow->tm_year+1900)) ||
  7963. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7964. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7965. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7966. system(cmdBuf);
  7967. // Combine log file
  7968. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7969. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7970. }
  7971. else
  7972. {
  7973. system("exec /root/logPackTools 'log' 6");
  7974. }
  7975. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  7976. system(cmdBuf);
  7977. checkUploadLog();
  7978. //****************location*******************/
  7979. if(strcmp(locationstr,"")==0)
  7980. {
  7981. DEBUG_INFO("location is <Empty>!\n");
  7982. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7983. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7984. goto end;
  7985. }
  7986. memset(protocol, 0, ARRAY_SIZE(protocol));
  7987. memset(user, 0, ARRAY_SIZE(user) );
  7988. memset(password, 0, ARRAY_SIZE(password));
  7989. memset(host, 0, ARRAY_SIZE(host));
  7990. memset(path, 0, ARRAY_SIZE(path));
  7991. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7992. memset(host1, 0, ARRAY_SIZE(host1));
  7993. memset(path1, 0, ARRAY_SIZE(path1));
  7994. /*location: ftp://user:password@host:port/path*/
  7995. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7996. if((access(fnamePlusPath,F_OK))!=-1)
  7997. {
  7998. DEBUG_INFO("fnamePlusPath exist.\n");
  7999. }
  8000. else
  8001. {
  8002. DEBUG_INFO("fnamePlusPath not exist!\n");
  8003. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8004. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8005. goto end;
  8006. }
  8007. if(strchr(locationstr,'@')==NULL)
  8008. {
  8009. sscanf(locationstr,
  8010. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8011. protocol, host, &port, path);
  8012. strcpy(user,"anonymous");
  8013. strcpy(password,"");
  8014. }
  8015. else
  8016. {
  8017. //DEBUG_INFO("pch=%s\n", pch);
  8018. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8019. protocol, user, password, host, &port, path);
  8020. }
  8021. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8022. {
  8023. DEBUG_INFO("protocol is not ftp/http ! \n");
  8024. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8025. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8026. goto end;
  8027. }
  8028. if(strncmp(locationstr,"http", 4) == 0)
  8029. {
  8030. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8031. sprintf(ftppath,"/%s", path);
  8032. do
  8033. {
  8034. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8035. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8036. sleep(3);
  8037. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8038. if(!isSuccess)
  8039. {
  8040. DEBUG_INFO("Diagnostics fail.\n");
  8041. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8042. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8043. sleep(retryIntervalInt);
  8044. }
  8045. else
  8046. {
  8047. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8048. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8049. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8050. }
  8051. retriesInt--;
  8052. }while((isSuccess == 0)&&(retriesInt >= 0));
  8053. }
  8054. else
  8055. {
  8056. sscanf(host,"%[^/]%s",host1, path1);
  8057. if(strlen(path) > 0)
  8058. sprintf(ftppath,"/%s", path);
  8059. else
  8060. sprintf(ftppath,"/%s", path1);
  8061. int ftppathlen=strlen(ftppath);
  8062. int i=1;
  8063. char filenametemp[50];
  8064. while(i < ftppathlen)
  8065. {
  8066. int len=ftppathlen-i;
  8067. if(ftppath[len]== 47) // '/' ascll code: 47
  8068. {
  8069. DEBUG_INFO("find '/' all right\n");
  8070. break;
  8071. }
  8072. i=i+1;
  8073. }
  8074. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8075. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8076. filenametemp[i+1] = 0;
  8077. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  8078. if(port == 0)
  8079. port = 21;
  8080. do
  8081. {
  8082. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8083. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8084. sleep(3);
  8085. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8086. if(!isSuccess)
  8087. {
  8088. DEBUG_INFO("Diagnostics fail.\n");
  8089. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8090. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8091. sleep(retryIntervalInt);
  8092. }
  8093. else
  8094. {
  8095. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8096. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8097. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8098. }
  8099. retriesInt--;
  8100. }while((!isSuccess)&&(retriesInt >= 0));
  8101. }
  8102. end:
  8103. system("rm -f /mnt/*");
  8104. sleep(5);
  8105. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8106. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8107. pthread_exit(NULL);
  8108. }
  8109. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8110. {
  8111. mtrace();
  8112. int result = FAIL;
  8113. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8114. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8115. {
  8116. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8117. localversion = -1;
  8118. }
  8119. else
  8120. {
  8121. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8122. OCPP_getListVerion();
  8123. }
  8124. //from db.OCPP_getListVerion
  8125. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = localversion;
  8126. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  8127. sendGetLocalListVersionConfirmation(uuid,"");
  8128. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  8129. return result;
  8130. }
  8131. int handleRemoteStartRequest(char *uuid, char *payload)
  8132. {
  8133. mtrace();
  8134. int result = FAIL;
  8135. int connectorIdInt=0;
  8136. int tempIndex = 0;
  8137. int connectorIdIsNULL, chargingProfileIsNULL;
  8138. char comfirmstr[20]={0};
  8139. char cmdBuf[512];
  8140. json_object *RemoteStartTransaction;
  8141. FILE *fp;
  8142. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8143. if(server_pending == TRUE)
  8144. {
  8145. return 0;
  8146. }
  8147. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8148. RemoteStartTransaction = json_tokener_parse(payload);
  8149. if(!is_error(RemoteStartTransaction))
  8150. {
  8151. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8152. {
  8153. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8154. if(connectorIdInt <= gunTotalNumber)
  8155. {
  8156. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8157. // Required data
  8158. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8159. // Optional data
  8160. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8161. {
  8162. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8163. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8164. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8165. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8166. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8167. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8168. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8169. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8170. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8171. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8172. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8173. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8174. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8175. {
  8176. 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")));
  8177. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8178. 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"));
  8179. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8180. 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"));
  8181. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8182. 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")));
  8183. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8184. {
  8185. 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++)
  8186. {
  8187. 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"));
  8188. 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"));
  8189. 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)
  8190. 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"));
  8191. }
  8192. }
  8193. }
  8194. }
  8195. else
  8196. chargingProfileIsNULL = TRUE;
  8197. }
  8198. }
  8199. else
  8200. connectorIdIsNULL = TRUE;
  8201. }
  8202. else
  8203. connectorIdIsNULL = TRUE;
  8204. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8205. {
  8206. DEBUG_WARN("Connector id is NULL\n.");
  8207. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8208. goto end;
  8209. }
  8210. /*
  8211. enum _SYSTEM_STATUS
  8212. {
  8213. S_BOOTING = 0,
  8214. S_IDLE, = 1
  8215. S_AUTHORIZING, = 2
  8216. S_REASSIGN_CHECK, = 3
  8217. S_REASSIGN, = 4
  8218. S_PRECHARGE, = 5
  8219. S_PREPARING_FOR_EV, = 6
  8220. S_PREPARING_FOR_EVSE, = 7
  8221. S_CHARGING, = 8
  8222. S_TERMINATING, = 9
  8223. S_COMPLETE, = 10
  8224. S_ALARM, = 11
  8225. S_FAULT = 12
  8226. }
  8227. */
  8228. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8229. {
  8230. //check Transaction active
  8231. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8232. {
  8233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8234. {
  8235. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8236. }
  8237. else
  8238. {
  8239. tempIndex = connectorIdInt -1;
  8240. }
  8241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8242. {
  8243. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8244. {
  8245. 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))
  8246. {
  8247. //Reserved
  8248. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8249. }
  8250. 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))
  8251. {
  8252. //Reserved
  8253. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8254. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8255. goto end;
  8256. }
  8257. else
  8258. {
  8259. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8260. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8261. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8262. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8263. {
  8264. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8265. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8266. goto end;
  8267. }
  8268. }//END FOR ELSE
  8269. }
  8270. }// END FOR CHAdeMO_QUANTITY
  8271. }
  8272. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8273. {
  8274. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8275. {
  8276. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8277. }
  8278. else
  8279. {
  8280. tempIndex = connectorIdInt -1;
  8281. }
  8282. for (int index = 0; index < CCS_QUANTITY; index++)
  8283. {
  8284. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8285. {
  8286. 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))
  8287. {
  8288. //Reserved
  8289. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8290. }
  8291. 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))
  8292. {
  8293. //Reserved
  8294. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8295. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8296. goto end;
  8297. }
  8298. else
  8299. {
  8300. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8301. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8302. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8303. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8304. {
  8305. DEBUG_WARN("CCS connector not allow start\n.");
  8306. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8307. goto end;
  8308. }
  8309. }// END FOR ELSE
  8310. }
  8311. }// END FOR CCS_QUANTITY
  8312. }
  8313. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8314. {
  8315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8316. {
  8317. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8318. }
  8319. else
  8320. {
  8321. tempIndex = connectorIdInt -1;
  8322. }
  8323. for (int index = 0; index < GB_QUANTITY; index++)
  8324. {
  8325. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8326. {
  8327. 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))
  8328. {
  8329. //Reserved
  8330. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8331. }
  8332. 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))
  8333. {
  8334. //Reserved
  8335. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8336. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8337. goto end;
  8338. }
  8339. else
  8340. {
  8341. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8342. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8343. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8344. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8345. {
  8346. DEBUG_WARN("GB connector not allow start\n.");
  8347. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8348. goto end;
  8349. }
  8350. }// END FOR ELSE
  8351. }
  8352. } // END FOR GB_QUANTITY
  8353. }
  8354. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8355. {
  8356. tempIndex = connectorIdInt -1;
  8357. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8358. {
  8359. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8360. {
  8361. 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))
  8362. {
  8363. //Reserved
  8364. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8365. }
  8366. 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))
  8367. {
  8368. //Reserved
  8369. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8370. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8371. goto end;
  8372. }
  8373. else
  8374. {
  8375. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8376. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8377. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8378. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8379. {
  8380. DEBUG_WARN("GB connector not allow start\n.");
  8381. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8382. goto end;
  8383. }
  8384. }// END FOR ELSE
  8385. }
  8386. } // END FOR GB_QUANTITY
  8387. }
  8388. else
  8389. {
  8390. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8391. {
  8392. tempIndex = 2;
  8393. }
  8394. else
  8395. {
  8396. tempIndex = connectorIdInt -1;
  8397. }
  8398. for (int index = 0; index < AC_QUANTITY; index++)
  8399. {
  8400. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8401. {
  8402. 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))
  8403. {
  8404. //Reserved
  8405. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8406. }
  8407. 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))
  8408. {
  8409. //Reserved
  8410. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8411. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8412. goto end;
  8413. }
  8414. else
  8415. {
  8416. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8417. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8418. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8419. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8420. {
  8421. DEBUG_WARN("AC connector not allow start\n.");
  8422. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8423. goto end;
  8424. }
  8425. }//END FOR ELSE
  8426. }
  8427. }// END FOR AC_QUANTITY
  8428. }
  8429. if(chargingProfileIsNULL == FALSE)
  8430. {
  8431. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8432. {
  8433. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8434. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8435. //memset idTag
  8436. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8437. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8438. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8439. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8440. // Save profile to file
  8441. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8442. system(cmdBuf);
  8443. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8444. fp = fopen(cmdBuf, "w");
  8445. 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));
  8446. fclose(fp);
  8447. }
  8448. else
  8449. {
  8450. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8451. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8452. }
  8453. }
  8454. else
  8455. {
  8456. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8457. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8458. //memset idTag
  8459. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8460. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8461. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8462. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8463. }
  8464. }
  8465. else
  8466. {
  8467. DEBUG_WARN("Connector id over\n.");
  8468. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8469. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8470. }
  8471. end:
  8472. json_object_put(RemoteStartTransaction);
  8473. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8474. {
  8475. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8476. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8477. }
  8478. //OCPP send RemoteStartConfirmation by first.
  8479. sendRemoteStartConfirmation(uuid, comfirmstr);
  8480. return result;
  8481. }
  8482. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8483. {
  8484. mtrace();
  8485. int result = FAIL;
  8486. int match = FALSE;
  8487. int GunNO = 0;
  8488. int tempIndex = 0;
  8489. int transactionIdInt=0;
  8490. int transactionIdIsNULL= TRUE;
  8491. char comfirmstr[20];
  8492. json_object *RemoteStopTransaction;
  8493. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8494. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8495. if(server_pending == TRUE)
  8496. {
  8497. return 0;
  8498. }
  8499. RemoteStopTransaction = json_tokener_parse(payload);
  8500. if(!is_error(RemoteStopTransaction))
  8501. {
  8502. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8503. {
  8504. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8505. transactionIdIsNULL = FALSE;
  8506. }
  8507. }
  8508. json_object_put(RemoteStopTransaction);
  8509. if(transactionIdIsNULL == FALSE)
  8510. {
  8511. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8512. {
  8513. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8514. {
  8515. //check Transaction active
  8516. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8517. {
  8518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8519. {
  8520. tempIndex = ((gun_index==2) ? 1: 0);
  8521. }
  8522. else
  8523. {
  8524. tempIndex = gun_index;
  8525. }
  8526. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8527. {
  8528. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8529. {
  8530. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8531. {
  8532. match = TRUE;
  8533. GunNO = gun_index;
  8534. }
  8535. }
  8536. }// END FOR CHAdeMO_QUANTITY
  8537. }
  8538. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8539. {
  8540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8541. {
  8542. tempIndex = ((gun_index==2) ? 1: 0);
  8543. }
  8544. else
  8545. {
  8546. tempIndex = gun_index;
  8547. }
  8548. for (int index = 0; index < CCS_QUANTITY; index++)
  8549. {
  8550. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8551. {
  8552. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8553. {
  8554. match = TRUE;
  8555. GunNO = gun_index;
  8556. }
  8557. }
  8558. }// END FOR CCS_QUANTITY
  8559. }
  8560. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8561. {
  8562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8563. {
  8564. tempIndex = ((gun_index==2) ? 1: 0);
  8565. }
  8566. else
  8567. {
  8568. tempIndex = gun_index;
  8569. }
  8570. for (int index = 0; index < GB_QUANTITY; index++)
  8571. {
  8572. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8573. {
  8574. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8575. {
  8576. match = TRUE;
  8577. GunNO = gun_index;
  8578. }
  8579. }
  8580. }// END FOR GB_QUANTITY
  8581. }
  8582. else if(gunType[gun_index] == GUN_TYPE_DO)
  8583. {
  8584. tempIndex = gun_index;
  8585. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8586. {
  8587. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8588. {
  8589. 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
  8590. {
  8591. match = TRUE;
  8592. GunNO = gun_index;
  8593. }
  8594. }
  8595. }// END FOR GB_QUANTITY
  8596. }
  8597. else
  8598. {
  8599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8600. {
  8601. tempIndex = 2;
  8602. }
  8603. else
  8604. {
  8605. tempIndex = gun_index;
  8606. }
  8607. for (int index = 0; index < AC_QUANTITY; index++)
  8608. {
  8609. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8610. {
  8611. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8612. {
  8613. match = TRUE;
  8614. GunNO = gun_index;
  8615. }
  8616. }
  8617. }// END FOR CHAdeMO_QUANTITY
  8618. } // END FOR AC ELSE
  8619. }// CHECK IF ResponseTransactionId == transactionIdInt
  8620. }//END FOR
  8621. if( match == TRUE)
  8622. {
  8623. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8624. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8625. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8626. }
  8627. else
  8628. {
  8629. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8630. }
  8631. }
  8632. else
  8633. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8634. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8635. return result;
  8636. }
  8637. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8638. {
  8639. mtrace();
  8640. int result = FAIL;
  8641. int connectorIdInt=0, reservationIdInt=0;
  8642. int tempIndex = 0;
  8643. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8644. char comfirmstr[20]={0};
  8645. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8646. int c = 0;
  8647. char *loc;
  8648. //char *ptr;
  8649. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8650. strcpy(sstrtemp, stringtrimspace(payload));
  8651. //***(1)connectorId ****/
  8652. c=0;
  8653. loc = strstr(sstrtemp, "connectorId");
  8654. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8655. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8656. {
  8657. sstr[c] = loc[strlen("connectorId")+2+c];
  8658. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8659. c++;
  8660. }
  8661. sstr[c] = '\0';
  8662. connectorIdInt = atoi(sstr);
  8663. //***(2)expiryDate ****/
  8664. loc = strstr(sstrtemp, "expiryDate");
  8665. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8666. c = 0;
  8667. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8668. {
  8669. sstr[c] = loc[3+strlen("expiryDate")+c];
  8670. c++;
  8671. }
  8672. sstr[c] = '\0';
  8673. strcpy(expiryDatestr, sstr);
  8674. //***(3)idTag ****/
  8675. loc = strstr(sstrtemp, "idTag");
  8676. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8677. c = 0;
  8678. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8679. {
  8680. sstr[c] = loc[3+strlen("idTag")+c];
  8681. c++;
  8682. }
  8683. sstr[c] = '\0';
  8684. strcpy(idTagstr, sstr);
  8685. //***(4)parentIdTag ****/
  8686. loc = strstr(sstrtemp, "parentIdTag");
  8687. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8688. c = 0;
  8689. if(loc == NULL)
  8690. {
  8691. strcpy(parentIdTagstr, "");
  8692. }
  8693. else
  8694. {
  8695. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8696. {
  8697. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8698. c++;
  8699. }
  8700. sstr[c] = '\0';
  8701. strcpy(parentIdTagstr, sstr);
  8702. }
  8703. //***(5)reservationId ****/
  8704. c=0;
  8705. loc = strstr(sstrtemp, "reservationId");
  8706. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8707. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8708. {
  8709. sstr[c] = loc[strlen("reservationId")+2+c];
  8710. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8711. c++;
  8712. }
  8713. sstr[c] = '\0';
  8714. reservationIdInt = atoi(sstr);
  8715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8716. /*
  8717. enum SYSTEM_STATUS
  8718. {
  8719. SYS_MODE_BOOTING = 0,
  8720. SYS_MODE_IDLE = 1,
  8721. SYS_MODE_AUTHORIZING = 2,
  8722. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8723. SYS_MODE_REASSIGN = 4,
  8724. SYS_MODE_PREPARING = 5,
  8725. SYS_MODE_PREPARE_FOR_EV = 6,
  8726. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8727. SYS_MODE_CHARGING = 8,
  8728. SYS_MODE_TERMINATING = 9,
  8729. SYS_MODE_COMPLETE = 10,
  8730. SYS_MODE_ALARM = 11,
  8731. SYS_MODE_FAULT = 12,
  8732. SYS_MODE_RESERVATION = 13,
  8733. SYS_MODE_BOOKING = 14,
  8734. SYS_MODE_MAINTAIN = 15,
  8735. SYS_MODE_DEBUG = 16,
  8736. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8737. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8738. SYS_MODE_UPDATE = 19
  8739. };
  8740. */
  8741. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8742. {
  8743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8744. goto end;
  8745. }
  8746. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8747. {
  8748. //check Transaction active
  8749. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8750. {
  8751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8752. {
  8753. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8754. }
  8755. else
  8756. {
  8757. tempIndex = connectorIdInt -1;
  8758. }
  8759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8760. {
  8761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8762. {
  8763. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8764. {
  8765. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8766. {
  8767. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8768. {
  8769. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8770. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8771. }
  8772. 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'))
  8773. {
  8774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8775. }
  8776. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8777. {
  8778. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8779. }
  8780. else
  8781. {
  8782. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8783. }
  8784. }
  8785. 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
  8786. {
  8787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8788. }
  8789. }
  8790. else
  8791. {
  8792. //replace reservation
  8793. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8794. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8795. }
  8796. }
  8797. } // END FOR CHAdeMO_QUANTITY
  8798. }
  8799. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8800. {
  8801. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8802. {
  8803. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8804. }
  8805. else
  8806. {
  8807. tempIndex = connectorIdInt -1;
  8808. }
  8809. for (int index = 0; index < CCS_QUANTITY; index++)
  8810. {
  8811. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8812. {
  8813. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8814. {
  8815. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8816. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8817. {
  8818. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8819. {
  8820. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8822. }
  8823. 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'))
  8824. {
  8825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8826. }
  8827. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8828. {
  8829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8830. }
  8831. else
  8832. {
  8833. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8834. }
  8835. }
  8836. 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
  8837. {
  8838. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8839. }
  8840. }
  8841. else
  8842. {
  8843. //replace reservation
  8844. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8845. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8846. }
  8847. }
  8848. } // END FOR CCS_QUANTITY
  8849. }
  8850. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8851. {
  8852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8853. {
  8854. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8855. }
  8856. else
  8857. {
  8858. tempIndex = connectorIdInt -1;
  8859. }
  8860. for (int index = 0; index < GB_QUANTITY; index++)
  8861. {
  8862. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8863. {
  8864. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8865. {
  8866. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8867. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8868. {
  8869. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8870. {
  8871. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8872. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8873. }
  8874. 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'))
  8875. {
  8876. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8877. }
  8878. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8879. {
  8880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8881. }
  8882. else
  8883. {
  8884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8885. }
  8886. }
  8887. 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
  8888. {
  8889. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8890. }
  8891. }
  8892. else
  8893. {
  8894. //replace reservation
  8895. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8896. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8897. }
  8898. }
  8899. }// END FOR GB_QUANTITY
  8900. }
  8901. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8902. {
  8903. tempIndex = connectorIdInt -1;
  8904. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8905. {
  8906. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8907. {
  8908. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8909. {
  8910. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8911. 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
  8912. {
  8913. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8914. {
  8915. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8917. }
  8918. 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'))
  8919. {
  8920. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8921. }
  8922. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8923. {
  8924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8925. }
  8926. else
  8927. {
  8928. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8929. }
  8930. }
  8931. 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
  8932. {
  8933. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8934. }
  8935. }
  8936. else
  8937. {
  8938. //replace reservation
  8939. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8940. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8941. }
  8942. }
  8943. }// END FOR GB_QUANTITY
  8944. }
  8945. else
  8946. {
  8947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8948. {
  8949. tempIndex = 2;
  8950. }
  8951. else
  8952. {
  8953. tempIndex = (connectorIdInt -1);
  8954. }
  8955. for (int index = 0; index < AC_QUANTITY; index++)
  8956. {
  8957. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8958. {
  8959. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8960. {
  8961. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8962. {
  8963. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8964. {
  8965. 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))
  8966. {
  8967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8968. }
  8969. else
  8970. {
  8971. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8973. }
  8974. }
  8975. 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'))
  8976. {
  8977. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8978. }
  8979. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8980. {
  8981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8982. }
  8983. else
  8984. {
  8985. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8986. }
  8987. }
  8988. 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
  8989. {
  8990. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8991. }
  8992. }
  8993. else
  8994. {
  8995. //replace reservation
  8996. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8998. }
  8999. }
  9000. } // END FOR AC_QUANTITY
  9001. }
  9002. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9003. }
  9004. else if(connectorIdInt == 0)
  9005. {
  9006. //check Transaction active
  9007. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9008. {
  9009. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9010. {
  9011. 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'))
  9012. {
  9013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9014. goto end;
  9015. }
  9016. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9017. {
  9018. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9019. goto end;
  9020. }
  9021. 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
  9022. {
  9023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9024. goto end;
  9025. }
  9026. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9027. {
  9028. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9029. goto end;
  9030. }
  9031. }
  9032. }// END FOR CHAdeMO_QUANTITY
  9033. for (int index = 0; index < CCS_QUANTITY; index++)
  9034. {
  9035. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9036. {
  9037. 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'))
  9038. {
  9039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9040. goto end;
  9041. }
  9042. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9043. {
  9044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9045. goto end;
  9046. }
  9047. 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
  9048. {
  9049. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9050. goto end;
  9051. }
  9052. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9053. {
  9054. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9055. goto end;
  9056. }
  9057. }
  9058. } // END FOR CCS_QUANTITY
  9059. for (int index = 0; index < GB_QUANTITY; index++)
  9060. {
  9061. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9062. {
  9063. 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'))
  9064. {
  9065. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9066. goto end;
  9067. }
  9068. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9069. {
  9070. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9071. goto end;
  9072. }
  9073. 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
  9074. {
  9075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9076. goto end;
  9077. }
  9078. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9079. {
  9080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9081. goto end;
  9082. }
  9083. }
  9084. } // END FOR GB_QUANTITY
  9085. for (int index = 0; index < AC_QUANTITY; index++)
  9086. {
  9087. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9088. {
  9089. 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'))
  9090. {
  9091. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9092. goto end;
  9093. }
  9094. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9095. {
  9096. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9097. goto end;
  9098. }
  9099. 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
  9100. {
  9101. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9102. goto end;
  9103. }
  9104. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9105. {
  9106. 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))
  9107. {
  9108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9109. goto end;
  9110. }
  9111. }
  9112. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9113. {
  9114. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9115. goto end;
  9116. }
  9117. }
  9118. }// END FOR AC_QUANTITY
  9119. //The connectorId is 0
  9120. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  9121. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9122. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9123. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  9124. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9125. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  9126. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9127. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  9128. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  9129. result = TRUE;
  9130. return result;
  9131. }
  9132. else
  9133. {
  9134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9135. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9136. }
  9137. if(strcmp(comfirmstr,"Accepted") == 0)
  9138. {
  9139. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9140. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9141. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9142. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9143. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9144. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  9145. result = TRUE;
  9146. return result;
  9147. }
  9148. end:
  9149. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9150. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9151. return result;
  9152. }
  9153. int handleResetRequest(char *uuid, char *payload)
  9154. {
  9155. mtrace();
  9156. int result = FAIL;
  9157. char sstr[10]={0},sstrtemp[30]={ 0 };
  9158. char typestr[10]={0};
  9159. char comfirmstr[20]={0};
  9160. int c = 0;
  9161. char *loc;
  9162. DEBUG_INFO("handleResetRequest...\n");
  9163. strcpy(sstrtemp, stringtrimspace(payload));
  9164. loc = strstr(sstrtemp, "type");
  9165. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9166. c = 0;
  9167. while (loc[3+strlen("type")+c] != '\"')
  9168. {
  9169. sstr[c] = loc[3+strlen("type")+c];
  9170. c++;
  9171. }
  9172. sstr[c] = '\0';
  9173. strcpy(typestr,sstr);
  9174. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  9175. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9176. {
  9177. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  9178. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  9179. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9180. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9181. }
  9182. else
  9183. {
  9184. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9185. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9186. result = PASS;
  9187. }
  9188. sendResetConfirmation(uuid, comfirmstr);
  9189. return result;
  9190. }
  9191. int handleSendLocalListRequest(char *uuid, char *payload)
  9192. {
  9193. mtrace();
  9194. int result = FAIL;
  9195. int listVersionInt;
  9196. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9197. char listsearch[]="listVersion";
  9198. char updateTypesearch[]="updateType";
  9199. char localAuthorizationListsearch[]="localAuthorizationList";
  9200. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9201. char CardList[500][160]={0};
  9202. char updateTypestr[15]={0};
  9203. char idTagstr[20]={0};
  9204. char parentIdTag[20]={0};
  9205. char expiryDate[30]={0};
  9206. char idTagstatus[16]={0};
  9207. int c = 0;
  9208. int i = 0;
  9209. char *delim1 = "}";
  9210. char * pch;
  9211. char *loc;
  9212. //char *ptr;
  9213. char comfirmstr[20];
  9214. //int n_localAuthorizations = 0;
  9215. int checkState_Faulted = FALSE;
  9216. DEBUG_INFO("handleSendLocalListRequest...\n");
  9217. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9218. {
  9219. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9220. goto end;
  9221. }
  9222. //check Charge Point state
  9223. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9224. {
  9225. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9226. {
  9227. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9228. }
  9229. }
  9230. for (int index = 0; index < CCS_QUANTITY; index++)
  9231. {
  9232. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9233. {
  9234. checkState_Faulted = TRUE; //OCPP Status
  9235. }
  9236. }
  9237. for (int index = 0; index < GB_QUANTITY; index++)
  9238. {
  9239. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9240. {
  9241. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9242. }
  9243. }
  9244. //check Charge Point state
  9245. for (int index = 0; index < AC_QUANTITY; index++)
  9246. {
  9247. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9248. {
  9249. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9250. }
  9251. }
  9252. if(checkState_Faulted == TRUE)
  9253. {
  9254. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9255. goto end;
  9256. }
  9257. //Filter payload space
  9258. strcpy(sstrtemp, stringtrimspace(payload));
  9259. //listVersion
  9260. c = 0;
  9261. loc = strstr(sstrtemp, listsearch);
  9262. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9263. {
  9264. sstr[c] = loc[strlen("listVersion")+2+c];
  9265. c++;
  9266. }
  9267. sstr[c] = '\0';
  9268. listVersionInt = atoi(sstr);
  9269. ShmOCPP16DataPH->SendLocalList.ListVersion = listVersionInt;
  9270. //updateType
  9271. loc = strstr(sstrtemp, updateTypesearch);
  9272. c = 0;
  9273. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9274. {
  9275. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9276. c++;
  9277. }
  9278. sstr[c] = '\0';
  9279. strcpy(updateTypestr, sstr);
  9280. sprintf((char *)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", updateTypestr);
  9281. //localAuthorizationList
  9282. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9283. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9284. if(loc != NULL) // localAuthorizationList is not NULL
  9285. {
  9286. //Check UpdateType
  9287. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9288. {
  9289. //Local list full update
  9290. printf("Local list full update.\n");
  9291. OCPP_getListVerion();
  9292. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9293. {
  9294. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9295. goto end;
  9296. }
  9297. OCPP_cleanLocalList();
  9298. }
  9299. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9300. {
  9301. //Local list different update
  9302. printf("Local list different update.\n");
  9303. OCPP_getListVerion();
  9304. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9305. {
  9306. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9307. goto end;
  9308. }
  9309. }
  9310. else
  9311. {
  9312. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9313. goto end;
  9314. }
  9315. c = 0;
  9316. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9317. {
  9318. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9319. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9320. c++;
  9321. }
  9322. sstr[c] = '\0';
  9323. //DEBUG_INFO("sstr=%s\n", sstr);
  9324. //parsing strings to words
  9325. i = 0;
  9326. pch = strtok(sstr,delim1);
  9327. while (pch != NULL)
  9328. {
  9329. strcpy(CardList[i], pch);
  9330. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9331. pch = strtok (NULL, delim1);
  9332. i = i + 1;
  9333. }
  9334. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9335. //local Authorizations List Numbers
  9336. //n_localAuthorizations = i;
  9337. ShmOCPP16DataPH->SendLocalList.ListVersion = listVersionInt;
  9338. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9339. c= 0;
  9340. while(c < i) // i is CardList Number
  9341. {
  9342. //Search "IdToken"
  9343. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9344. loc = strstr(CardList[c], "idTag");
  9345. int j = 0;
  9346. while (loc[3+strlen("idTag")+j] != '\"')
  9347. {
  9348. sstr[j] = loc[3+strlen("idTag")+j];
  9349. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9350. j++;
  9351. }
  9352. sstr[j] = '\0';
  9353. strcpy(idTagstr, sstr);
  9354. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9355. //Search "expiryDate"
  9356. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9357. loc = strstr(CardList[c], "expiryDate");
  9358. j = 0;
  9359. if(loc != NULL)
  9360. {
  9361. while (loc[3+strlen("expiryDate")+j] != '\"')
  9362. {
  9363. sstr[j] = loc[3+strlen("expiryDate")+j];
  9364. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9365. j++;
  9366. }
  9367. sstr[j] = '\0';
  9368. strcpy(expiryDate, sstr);
  9369. }
  9370. else
  9371. {
  9372. strcpy(expiryDate, "");
  9373. }
  9374. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9375. //Search "parentIdTag"
  9376. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9377. loc = strstr(CardList[c], "parentIdTag");
  9378. j = 0;
  9379. if(loc != NULL)
  9380. {
  9381. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9382. {
  9383. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9384. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9385. j++;
  9386. }
  9387. sstr[j] = '\0';
  9388. strcpy(parentIdTag, sstr);
  9389. }
  9390. else
  9391. {
  9392. strcpy(parentIdTag, "");
  9393. }
  9394. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9395. //Search "status"
  9396. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9397. loc = strstr(CardList[c], "status");
  9398. j = 0;
  9399. while (loc[3+strlen("status")+j] != '\"')
  9400. {
  9401. sstr[j] = loc[3+strlen("status")+j];
  9402. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9403. j++;
  9404. }
  9405. sstr[j] = '\0';
  9406. strcpy(idTagstatus, sstr);
  9407. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9408. OCPP_getIdTagFromLocalList(idTagstr);
  9409. //OCPP_getIdTagFromLocalList("test"); For Test
  9410. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9411. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9412. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9413. {
  9414. //Local list full update
  9415. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9416. // update list
  9417. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9418. //DEBUG_INFO("Local list full update. 1\n");
  9419. //OCPP_get_TableAuthlocalAllData();
  9420. //DEBUG_INFO("Local list full update. 2\n");
  9421. }
  9422. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9423. {
  9424. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9425. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9426. }
  9427. strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9428. strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9429. strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9430. strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9431. c++;
  9432. }
  9433. }
  9434. else
  9435. {
  9436. //Check UpdateType
  9437. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9438. {
  9439. //Local list full update
  9440. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9441. OCPP_cleanLocalList();
  9442. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9443. goto end;
  9444. }
  9445. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9446. {
  9447. //Local list different update
  9448. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9449. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9450. goto end;
  9451. }
  9452. }
  9453. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9454. end:
  9455. sendSendLocalListConfirmation(uuid, comfirmstr);
  9456. //ShmOCPP16DataPH->MsMsg.bits.SendLocalListConf = 1;
  9457. return result;
  9458. }
  9459. #define MAX 200
  9460. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9461. {
  9462. mtrace();
  9463. int result = FAIL;
  9464. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9465. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9466. char chargingProfilePurposeStr[30]={0};
  9467. char chargingProfileKindStr[16]={0};
  9468. char recurrencyKindStr[10]={0};
  9469. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9470. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9471. int chargingSchedulePeriodCount = 0;
  9472. char comfirmstr[20]={0};
  9473. int meet= FALSE;
  9474. FILE *fptr1;
  9475. char filename[MAX]={0};
  9476. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  9477. char rmFileCmd[50]={0};
  9478. char tempchargingProfilePurposeStr[30]={0};
  9479. char word[1600]={0};
  9480. int n_chargingProfile = 0;
  9481. json_object *SetChargingProfile;
  9482. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9483. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9484. SetChargingProfile = json_tokener_parse(payload);
  9485. if(!is_error(SetChargingProfile))
  9486. {
  9487. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9488. {
  9489. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9490. if(connectorIdInt == 0)
  9491. {
  9492. memset(&ShmOCPP16DataPH->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9493. ShmOCPP16DataPH->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9494. }
  9495. else
  9496. {
  9497. memset(&ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9498. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9499. }
  9500. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9501. }
  9502. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9503. {
  9504. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9505. {
  9506. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9507. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9508. {
  9509. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9510. }
  9511. else
  9512. {
  9513. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9514. }
  9515. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9516. }
  9517. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9518. {
  9519. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9520. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9521. {
  9522. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9523. }
  9524. else
  9525. {
  9526. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9527. }
  9528. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9529. }
  9530. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9531. {
  9532. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9533. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9534. {
  9535. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9536. }
  9537. else
  9538. {
  9539. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9540. }
  9541. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9542. }
  9543. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9544. {
  9545. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9546. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9547. {
  9548. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9549. }
  9550. else
  9551. {
  9552. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9553. }
  9554. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9555. }
  9556. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9557. {
  9558. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9559. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9560. {
  9561. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9562. }
  9563. else
  9564. {
  9565. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9566. }
  9567. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9568. }
  9569. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9570. {
  9571. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9572. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9573. {
  9574. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9575. }
  9576. else
  9577. {
  9578. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9579. }
  9580. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9581. }
  9582. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9583. {
  9584. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9585. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9586. {
  9587. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9588. }
  9589. else
  9590. {
  9591. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9592. }
  9593. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9594. }
  9595. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9596. {
  9597. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9598. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9599. {
  9600. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9601. }
  9602. else
  9603. {
  9604. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9605. }
  9606. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9607. }
  9608. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9609. {
  9610. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9611. {
  9612. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9613. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9614. {
  9615. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9616. }
  9617. else
  9618. {
  9619. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9620. }
  9621. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9622. }
  9623. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9624. {
  9625. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9626. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9627. {
  9628. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9629. }
  9630. else
  9631. {
  9632. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9633. }
  9634. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9635. }
  9636. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9637. {
  9638. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9639. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9640. {
  9641. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9642. }
  9643. else
  9644. {
  9645. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9646. }
  9647. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9648. }
  9649. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9650. {
  9651. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9652. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9653. {
  9654. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9655. }
  9656. else
  9657. {
  9658. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9659. }
  9660. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9661. }
  9662. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9663. {
  9664. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9665. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9666. if(chargingSchedulePeriodCount <= 10)
  9667. {
  9668. 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++)
  9669. {
  9670. 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)
  9671. {
  9672. 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"));
  9673. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9674. {
  9675. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9676. }
  9677. else
  9678. {
  9679. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9680. }
  9681. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9682. }
  9683. 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)
  9684. {
  9685. 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"));
  9686. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9687. {
  9688. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9689. }
  9690. else
  9691. {
  9692. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9693. }
  9694. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9695. }
  9696. 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)
  9697. {
  9698. 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"));
  9699. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9700. {
  9701. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9702. }
  9703. else
  9704. {
  9705. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9706. }
  9707. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9708. }
  9709. }
  9710. }
  9711. }
  9712. }
  9713. }
  9714. }
  9715. json_object_put(SetChargingProfile);
  9716. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9717. {
  9718. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9719. goto end;
  9720. }
  9721. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9722. {
  9723. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9724. if(connectorIdInt != 0)
  9725. {
  9726. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9727. goto end;
  9728. }
  9729. strcpy(filename, ChargePointMaxProfile_JSON );
  9730. fptr1 = fopen(filename, "r");
  9731. if (!fptr1)
  9732. {
  9733. //file not exist
  9734. DEBUG_INFO("Unable to open the input file!!\n");
  9735. fptr1 = fopen(filename, "w+");
  9736. }
  9737. else
  9738. {
  9739. //Check Charging Profile Count
  9740. while(fscanf(fptr1, "%s", word) != EOF)
  9741. {
  9742. //DEBUG_INFO("word=%s\n",word);
  9743. if(strstr(word, "chargingProfileId")!= NULL)
  9744. {
  9745. //DEBUG_INFO("test chargingProfileId \n");
  9746. n_chargingProfile = n_chargingProfile + 1;
  9747. //DEBUG_INFO("chargingProfileId Found\n");
  9748. }
  9749. }
  9750. }
  9751. fclose(fptr1);
  9752. }
  9753. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9754. {
  9755. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9756. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9757. {
  9758. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9759. goto end;
  9760. }
  9761. memset(filename, 0, ARRAY_SIZE(filename));
  9762. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  9763. fptr1 = fopen(filename, "r");
  9764. if (!fptr1)
  9765. {
  9766. //file not exist
  9767. //DEBUG_INFO("Unable to open the input file!!\n");
  9768. fptr1 = fopen(filename, "w+");
  9769. }
  9770. else
  9771. {
  9772. //Check Charging Profile Count
  9773. while(fscanf(fptr1, "%s", word) != EOF)
  9774. {
  9775. //DEBUG_INFO("word=%s\n",word);
  9776. if(strstr(word, "chargingProfileId")!= NULL)
  9777. {
  9778. //DEBUG_INFO("test chargingProfileId \n");
  9779. n_chargingProfile = n_chargingProfile + 1;
  9780. //DEBUG_INFO("chargingProfileId Found\n");
  9781. }
  9782. }
  9783. }
  9784. fclose(fptr1);
  9785. }
  9786. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9787. {
  9788. //printf("set chargingProfile 1-4\n");
  9789. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9790. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9791. if(connectorIdInt == 0)
  9792. {
  9793. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9794. goto end;
  9795. }
  9796. int tempIndex = 0;
  9797. //check Transaction active
  9798. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9799. {
  9800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9801. {
  9802. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9803. }
  9804. else
  9805. {
  9806. tempIndex = connectorIdInt -1;
  9807. }
  9808. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9809. {
  9810. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9811. {
  9812. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9813. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9814. {
  9815. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9816. {
  9817. meet = TRUE;
  9818. break;
  9819. }
  9820. }
  9821. }
  9822. }
  9823. }
  9824. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9825. {
  9826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9827. {
  9828. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9829. }
  9830. else
  9831. {
  9832. tempIndex = connectorIdInt -1;
  9833. }
  9834. for (int index = 0; index < CCS_QUANTITY; index++)
  9835. {
  9836. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9837. {
  9838. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9839. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9840. {
  9841. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9842. {
  9843. meet = TRUE;
  9844. break;
  9845. }
  9846. }
  9847. }
  9848. }
  9849. }
  9850. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9851. {
  9852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9853. {
  9854. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9855. }
  9856. else
  9857. {
  9858. tempIndex = connectorIdInt -1;
  9859. }
  9860. for (int index = 0; index < GB_QUANTITY; index++)
  9861. {
  9862. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9863. {
  9864. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9865. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9866. {
  9867. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9868. {
  9869. meet = TRUE;
  9870. break;
  9871. }
  9872. }
  9873. }
  9874. }
  9875. }
  9876. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9877. {
  9878. tempIndex = connectorIdInt -1;
  9879. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9880. {
  9881. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9882. {
  9883. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9884. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9885. {
  9886. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9887. {
  9888. meet = TRUE;
  9889. break;
  9890. }
  9891. }
  9892. }
  9893. }
  9894. }
  9895. else
  9896. {
  9897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9898. {
  9899. tempIndex = 2;
  9900. }
  9901. else
  9902. {
  9903. tempIndex = (connectorIdInt -1);
  9904. }
  9905. for (int index = 0; index < AC_QUANTITY; index++)
  9906. {
  9907. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9908. {
  9909. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9910. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9911. {
  9912. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9913. {
  9914. meet = TRUE;
  9915. break;
  9916. }
  9917. }
  9918. }
  9919. }
  9920. }
  9921. //check Transaction active
  9922. if(meet == FALSE)
  9923. {
  9924. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9925. goto end;
  9926. }
  9927. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9928. {
  9929. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9930. goto end;
  9931. }
  9932. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9933. fptr1 = fopen(filename, "r");
  9934. if (!fptr1)
  9935. {
  9936. //file not exist
  9937. DEBUG_INFO("Unable to open the input file!!\n");
  9938. fptr1 = fopen(filename, "w+");
  9939. }
  9940. else
  9941. {
  9942. //Check Charging Profile Count
  9943. while(fscanf(fptr1, "%s", word) != EOF)
  9944. {
  9945. //DEBUG_INFO("word=%s\n",word);
  9946. if(strstr(word, "chargingProfileId")!= NULL)
  9947. {
  9948. //DEBUG_INFO("test chargingProfileId \n");
  9949. n_chargingProfile = n_chargingProfile + 1;
  9950. //DEBUG_INFO("chargingProfileId Found\n");
  9951. }
  9952. }
  9953. }
  9954. fclose(fptr1);
  9955. }
  9956. // Check ChargeProfileMaxStackLevel
  9957. if(n_chargingProfile >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9958. {
  9959. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9960. goto end;
  9961. }
  9962. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9963. {
  9964. int i = 0;
  9965. char fnametemp[200]={0};
  9966. n_chargingProfile = 0;
  9967. //Check ChargePointMaxProfile.json exit
  9968. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  9969. {
  9970. fptr1 = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  9971. //Check Charging Profile Count
  9972. while(fscanf(fptr1, "%s", word) != EOF)
  9973. {
  9974. //DEBUG_INFO("word=%s\n",word);
  9975. if(strstr(word, "chargingProfileId")!= NULL)
  9976. {
  9977. //DEBUG_INFO("test chargingProfileId \n");
  9978. n_chargingProfile = n_chargingProfile + 1;
  9979. i = i + 1;
  9980. //DEBUG_INFO("chargingProfileId Found\n");
  9981. }
  9982. memset(word, 0, ARRAY_SIZE(word));
  9983. }
  9984. fclose(fptr1);
  9985. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9986. }
  9987. //Check TxDefaultProfile_0.json exit
  9988. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  9989. {
  9990. i = 0;
  9991. fptr1 = fopen("/Storage/OCPP_PH/TxDefaultProfile_0.json", "r");
  9992. //Check Charging Profile Count
  9993. while(fscanf(fptr1, "%s", word) != EOF)
  9994. {
  9995. //DEBUG_INFO("word=%s\n",word);
  9996. if(strstr(word, "chargingProfileId")!= NULL)
  9997. {
  9998. //DEBUG_INFO("test chargingProfileId \n");
  9999. n_chargingProfile = n_chargingProfile + 1;
  10000. i = i + 1;
  10001. //DEBUG_INFO("chargingProfileId Found\n");
  10002. }
  10003. memset(word, 0, ARRAY_SIZE(word));
  10004. }
  10005. fclose(fptr1);
  10006. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10007. }
  10008. //Check TxDefaultProfile_%d.json
  10009. for(int j=1; j <= gunTotalNumber; j++)
  10010. {
  10011. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10012. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  10013. if((access(fnametemp,F_OK))!=-1)
  10014. {
  10015. i = 0;
  10016. fptr1 = fopen(fnametemp, "r");
  10017. //Check Charging Profile Count
  10018. while(fscanf(fptr1, "%s", word) != EOF)
  10019. {
  10020. //DEBUG_INFO("word=%s\n",word);
  10021. if(strstr(word, "chargingProfileId")!= NULL)
  10022. {
  10023. //DEBUG_INFO("test chargingProfileId \n");
  10024. n_chargingProfile = n_chargingProfile + 1;
  10025. i = i + 1;
  10026. //DEBUG_INFO("chargingProfileId Found\n");
  10027. }
  10028. memset(word, 0, ARRAY_SIZE(word));
  10029. }
  10030. fclose(fptr1);
  10031. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10032. }
  10033. }
  10034. //Check TxProfile_%d.json
  10035. for(int j=1; j <= gunTotalNumber; j++)
  10036. {
  10037. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10038. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  10039. if((access(fnametemp,F_OK))!=-1)
  10040. {
  10041. i = 0;
  10042. fptr1 = fopen(fnametemp, "r");
  10043. //Check Charging Profile Count
  10044. while(fscanf(fptr1, "%s", word) != EOF)
  10045. {
  10046. //DEBUG_INFO("word=%s\n",word);
  10047. if(strstr(word, "chargingProfileId")!= NULL)
  10048. {
  10049. //DEBUG_INFO("test chargingProfileId \n");
  10050. n_chargingProfile = n_chargingProfile + 1;
  10051. i = i + 1;
  10052. //DEBUG_INFO("chargingProfileId Found\n");
  10053. }
  10054. memset(word, 0, ARRAY_SIZE(word));
  10055. }
  10056. fclose(fptr1);
  10057. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10058. }
  10059. }
  10060. if( n_chargingProfile > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10061. {
  10062. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10063. goto end;
  10064. }
  10065. }
  10066. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10067. //**********************************Write to File********************************************************/
  10068. FILE *infile;
  10069. FILE *outfile;
  10070. infile = fopen (filename, "r");
  10071. outfile = fopen (tempfile, "w");
  10072. int d =0;
  10073. d = fgetc(infile);
  10074. rewind(infile);
  10075. if(d == EOF)
  10076. {
  10077. // Profile is empty
  10078. fprintf(outfile,"%s\n",payload);
  10079. fclose(infile);
  10080. fclose(outfile);
  10081. sprintf(rmFileCmd,"rm -f %s",filename);
  10082. system(rmFileCmd);
  10083. rename(tempfile, filename);
  10084. }
  10085. else
  10086. {
  10087. // Profile is not empty
  10088. char buf[2048]={0};
  10089. int ChargingProfileAdded = FALSE;
  10090. while (fgets(buf, sizeof(buf), infile) != NULL)
  10091. {
  10092. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10093. json_object *tmpChargingProfile;
  10094. tmpChargingProfile = json_tokener_parse(buf);
  10095. if(!is_error(SetChargingProfile))
  10096. {
  10097. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10098. {
  10099. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10100. }
  10101. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10102. {
  10103. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10104. {
  10105. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10106. }
  10107. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10108. {
  10109. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10110. }
  10111. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10112. {
  10113. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10114. }
  10115. }
  10116. }
  10117. json_object_put(tmpChargingProfile);
  10118. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10119. {
  10120. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10121. {
  10122. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10123. if(ChargingProfileAdded == FALSE)
  10124. {
  10125. fprintf(outfile,"%s\n",payload);
  10126. ChargingProfileAdded = TRUE;
  10127. }
  10128. }
  10129. else
  10130. {
  10131. if(tempstackLevelInt < stackLevelInt)
  10132. {
  10133. if(ChargingProfileAdded == FALSE)
  10134. {
  10135. fprintf(outfile,"%s\n",buf);
  10136. fprintf(outfile,"%s\n",payload);
  10137. ChargingProfileAdded = TRUE;
  10138. }
  10139. else
  10140. {
  10141. fprintf(outfile,"%s\n",buf);
  10142. }
  10143. }
  10144. else
  10145. {
  10146. if(ChargingProfileAdded == FALSE)
  10147. {
  10148. fprintf(outfile,"%s\n",buf);
  10149. fprintf(outfile,"%s\n",payload);
  10150. ChargingProfileAdded = TRUE;
  10151. }
  10152. else
  10153. {
  10154. fprintf(outfile,"%s\n",buf);
  10155. }
  10156. }
  10157. }
  10158. }
  10159. else
  10160. {
  10161. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10162. {
  10163. if(ChargingProfileAdded == FALSE)
  10164. {
  10165. fprintf(outfile,"%s\n",buf);
  10166. fprintf(outfile,"%s\n",payload);
  10167. ChargingProfileAdded = TRUE;
  10168. }
  10169. else
  10170. {
  10171. fprintf(outfile,"%s\n",buf);
  10172. }
  10173. }
  10174. else if(tempstackLevelInt < stackLevelInt)
  10175. {
  10176. if(ChargingProfileAdded == FALSE)
  10177. {
  10178. fprintf(outfile,"%s\n",buf);
  10179. fprintf(outfile,"%s\n",payload);
  10180. ChargingProfileAdded = TRUE;
  10181. }
  10182. else
  10183. {
  10184. fprintf(outfile,"%s\n",buf);
  10185. }
  10186. }
  10187. else
  10188. {
  10189. if(ChargingProfileAdded == FALSE)
  10190. {
  10191. fprintf(outfile,"%s\n",buf);
  10192. fprintf(outfile,"%s\n",payload);
  10193. ChargingProfileAdded = TRUE;
  10194. }
  10195. else
  10196. {
  10197. fprintf(outfile,"%s\n",buf);
  10198. }
  10199. }
  10200. }
  10201. } // end of while loop
  10202. fclose(infile);
  10203. fclose(outfile);
  10204. sprintf(rmFileCmd,"rm -f %s",filename);
  10205. system(rmFileCmd);
  10206. rename(tempfile, filename);
  10207. }
  10208. sleep(1);
  10209. result = TRUE;
  10210. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10211. end:
  10212. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10213. {
  10214. if(connectorIdInt == 0)
  10215. {
  10216. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10217. {
  10218. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  10219. }
  10220. }
  10221. else
  10222. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  10223. }
  10224. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10225. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10226. return result;
  10227. }
  10228. int handleTriggerMessageRequest(char *uuid, char *payload)
  10229. {
  10230. mtrace();
  10231. int result = FAIL;
  10232. int connectorIdIsNULL = FALSE;
  10233. int connectorIdInt =0;
  10234. char sstr[40]={0},sstrtemp[100]={ 0 };
  10235. char requestedMessagestr[40]={0};
  10236. char comfirmstr[20]={0};
  10237. int c = 0;
  10238. char *loc;
  10239. DEBUG_INFO("handleTriggerMessageRequest\n");
  10240. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10241. strcpy(sstrtemp, stringtrimspace(payload));
  10242. c = 0;
  10243. loc = strstr(sstrtemp, "requestedMessage");
  10244. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10245. {
  10246. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10247. c++;
  10248. }
  10249. sstr[c] = '\0';
  10250. strcpy(requestedMessagestr, sstr);
  10251. c = 0;
  10252. loc = strstr(sstrtemp, "connectorId");
  10253. if(loc == NULL)
  10254. {
  10255. connectorIdIsNULL = TRUE;
  10256. }
  10257. else
  10258. {
  10259. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10260. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10261. {
  10262. sstr[c] = loc[strlen("connectorId")+2+c];
  10263. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10264. c++;
  10265. }
  10266. sstr[c] = '\0';
  10267. connectorIdInt = atoi(sstr);
  10268. }
  10269. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10270. {
  10271. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10272. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10273. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10274. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10275. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10276. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10277. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10278. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10279. {
  10280. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10281. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10282. return TRUE;
  10283. }
  10284. else
  10285. {
  10286. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10287. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10288. }
  10289. }
  10290. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10291. {
  10292. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10293. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10294. return TRUE;
  10295. }
  10296. //==========================
  10297. // Trigger message
  10298. //==========================
  10299. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10300. {
  10301. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10302. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10303. {
  10304. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10305. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10306. }
  10307. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10308. }
  10309. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10310. {
  10311. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  10312. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10313. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10314. }
  10315. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10316. {
  10317. //sendBootNotificationRequest();
  10318. server_sign = FALSE;
  10319. }
  10320. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10321. {
  10322. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10323. }
  10324. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10325. {
  10326. if(connectorIdIsNULL == FALSE)
  10327. {
  10328. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10329. {
  10330. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10331. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10332. }
  10333. }
  10334. else
  10335. {
  10336. for(int idx=0;idx< gunTotalNumber;idx++)
  10337. {
  10338. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10339. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10340. }
  10341. }
  10342. }
  10343. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10344. {
  10345. if(connectorIdIsNULL == FALSE)
  10346. {
  10347. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10348. {
  10349. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10350. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10351. }
  10352. }
  10353. else
  10354. {
  10355. for(int idx=0;idx< gunTotalNumber;idx++)
  10356. {
  10357. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  10358. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10359. }
  10360. }
  10361. }
  10362. return result;
  10363. }
  10364. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10365. {
  10366. mtrace();
  10367. int result = FAIL;
  10368. int connectorIdInt =0;
  10369. char comfirmstr[20]={0};
  10370. int tempIndex = 0;
  10371. json_object *UnlockConnector;
  10372. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10373. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10374. UnlockConnector = json_tokener_parse(payload);
  10375. if(!is_error(UnlockConnector))
  10376. {
  10377. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10378. {
  10379. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10380. }
  10381. }
  10382. json_object_put(UnlockConnector);
  10383. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10384. if(gunTotalNumber == 0)
  10385. {
  10386. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10387. goto end;
  10388. }
  10389. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10390. {
  10391. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10392. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10393. goto end;
  10394. }
  10395. else
  10396. {
  10397. //check Transaction active
  10398. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10399. {
  10400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10401. {
  10402. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10403. }
  10404. else
  10405. {
  10406. tempIndex = connectorIdInt -1;
  10407. }
  10408. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10409. {
  10410. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10411. {
  10412. //stop Transaction
  10413. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10414. }
  10415. }
  10416. }
  10417. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10418. {
  10419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10420. {
  10421. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10422. }
  10423. else
  10424. {
  10425. tempIndex = connectorIdInt -1;
  10426. }
  10427. for (int index = 0; index < CCS_QUANTITY; index++)
  10428. {
  10429. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10430. {
  10431. //stop Transaction
  10432. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10433. }
  10434. }
  10435. }
  10436. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10437. {
  10438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10439. {
  10440. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10441. }
  10442. else
  10443. {
  10444. tempIndex = connectorIdInt -1;
  10445. }
  10446. for (int index = 0; index < GB_QUANTITY; index++)
  10447. {
  10448. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10449. {
  10450. //stop Transaction
  10451. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10452. }
  10453. }
  10454. }
  10455. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10456. {
  10457. tempIndex = connectorIdInt -1;
  10458. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10459. {
  10460. 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)))
  10461. {
  10462. //stop Transaction
  10463. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10464. }
  10465. }
  10466. }
  10467. else
  10468. {
  10469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10470. {
  10471. tempIndex = 2;
  10472. }
  10473. else
  10474. {
  10475. tempIndex = connectorIdInt-1;
  10476. }
  10477. for (int index = 0; index < AC_QUANTITY; index++)
  10478. {
  10479. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10480. {
  10481. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10482. }
  10483. }
  10484. }
  10485. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10486. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  10487. result = TRUE;
  10488. return result;
  10489. }
  10490. end:
  10491. //json_object_put(obj); --- remove temporally
  10492. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10493. return result;
  10494. }
  10495. static char UpdateFirmwarepayloadData[300]={0};
  10496. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10497. {
  10498. mtrace();
  10499. int result = FAIL;
  10500. pthread_t t;
  10501. sendUpdateFirmwareConfirmation(uuid);
  10502. memset(UpdateFirmwarepayloadData, 0, 300);
  10503. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10504. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10505. ////pthread_join(t, NULL); //
  10506. //pthread_detach(t);
  10507. //sendUpdateFirmwareConfirmation(uuid);
  10508. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  10509. return result;
  10510. }
  10511. void *UpdateFirmwareProcess(void *data)
  10512. {
  10513. pthread_detach(pthread_self());
  10514. mtrace();
  10515. int retriesInt =0, retryIntervalInt=0;
  10516. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10517. int port=0;
  10518. char locationstr[512]={0}, retrieveDatestr[36]={0};
  10519. int isSuccess = 0;
  10520. char ftpbuf[512];
  10521. char temp[100];
  10522. char * pch;
  10523. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10524. json_object *UpdateFirmware;
  10525. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10526. if(!is_error(UpdateFirmware))
  10527. {
  10528. // Required data
  10529. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10530. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10531. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10532. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10533. // Optional data
  10534. if(json_object_object_get(UpdateFirmware, "retries"))
  10535. {
  10536. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10537. }
  10538. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10539. {
  10540. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10541. }
  10542. }
  10543. json_object_put(UpdateFirmware);
  10544. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10545. memset(path, 0, ARRAY_SIZE(path));
  10546. // Wait retrieveData
  10547. if(strlen(retrieveDatestr) > 10)
  10548. {
  10549. do
  10550. {
  10551. sleep(1);
  10552. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10553. }
  10554. // Ready to download
  10555. system("rm -f /mnt/*");
  10556. if(strncmp(locationstr,"http", 4) == 0)
  10557. {
  10558. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10559. sprintf(ftppath,"/%s", path);
  10560. DEBUG_INFO("locationstr: %s\n", locationstr);
  10561. DEBUG_INFO("protocol: %s\n",protocol);
  10562. DEBUG_INFO("host: %s\n",host);
  10563. DEBUG_INFO("path: %s\n",path);
  10564. DEBUG_INFO("ftppath: %s\n",ftppath);
  10565. int ftppathlen=strlen(ftppath);
  10566. int i=1;
  10567. char filenametemp[50];
  10568. while(i < ftppathlen)
  10569. {
  10570. int len=ftppathlen-i;
  10571. if(ftppath[len]== 47) // '/' ascll code: 47
  10572. {
  10573. DEBUG_INFO("compare '/' all right\n");
  10574. break;
  10575. }
  10576. i=i+1;
  10577. }
  10578. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10579. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10580. filenametemp[i+1] = 0;
  10581. do
  10582. {
  10583. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10584. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10585. sleep(1);
  10586. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10587. if(!isSuccess)
  10588. {
  10589. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10590. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10591. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10592. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10593. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10594. }
  10595. else
  10596. {
  10597. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10598. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10599. }
  10600. retriesInt--;
  10601. }while((isSuccess == 0)&&(retriesInt >= 0));
  10602. }
  10603. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10604. {
  10605. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10606. memset(temp, 0, ARRAY_SIZE(temp));
  10607. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10608. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10609. int ftppathlen=strlen(ftpbuf);
  10610. int i=1;
  10611. char filenametemp[50];
  10612. while(i < ftppathlen)
  10613. {
  10614. int len=ftppathlen-i;
  10615. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10616. {
  10617. DEBUG_INFO(" compare '/' all right\n");
  10618. break;
  10619. }
  10620. i=i+1;
  10621. }
  10622. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10623. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10624. filenametemp[i+1] = 0;
  10625. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10626. pch=strchr(temp,'@');
  10627. if(pch==NULL)
  10628. {
  10629. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10630. protocol, host, &port, path);
  10631. strcpy(user,"anonymous");
  10632. strcpy(password,"");
  10633. }
  10634. else
  10635. {
  10636. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10637. protocol, user, password, host, &port, path);
  10638. }
  10639. sscanf(host,"%[^/]%s",host1, path1);
  10640. sprintf(ftppath,"%s", path1);
  10641. //DEBUG_INFO("protocol =%s\n",protocol);
  10642. //DEBUG_INFO("user =%s\n",user);
  10643. //DEBUG_INFO("password =%s\n",password);
  10644. //DEBUG_INFO("host1 =%s\n",host1);
  10645. //DEBUG_INFO("port =%d\n",port);
  10646. //DEBUG_INFO("path1 =%s\n",path1);
  10647. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10648. //ftpFile(host, user, password, port, ftppath, fname);
  10649. //download firmware pthred
  10650. if(port == 0)
  10651. {
  10652. port = 21;
  10653. }
  10654. do
  10655. {
  10656. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10657. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10658. sleep(1);
  10659. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10660. if(!isSuccess)
  10661. {
  10662. //BulldogUtil.sleepMs(interval*1000);
  10663. DEBUG_INFO("Update firmware request and download file fail.\n");
  10664. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10665. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10666. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10667. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10668. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10669. }
  10670. else
  10671. {
  10672. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10673. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10674. }
  10675. retriesInt--;
  10676. }while((!isSuccess)&&(retriesInt >= 0));
  10677. }
  10678. else
  10679. {
  10680. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10681. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10682. sleep(1);
  10683. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10684. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10685. }
  10686. // OCPPPH only, must announce CSU upgrade firmware
  10687. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10688. pthread_exit(NULL);
  10689. }
  10690. int handleCertificateSignedRequest(char *uuid, char *payload)
  10691. {
  10692. mtrace();
  10693. int result = PASS;
  10694. json_object *CertificateSigned;
  10695. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10696. CertificateSigned = json_tokener_parse(payload);
  10697. if(!is_error(CertificateSigned))
  10698. {
  10699. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10700. }
  10701. json_object_put(CertificateSigned);
  10702. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  10703. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  10704. fclose(fp);
  10705. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10706. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  10707. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  10708. sendCertificateSignedConfirmation(uuid);
  10709. return result;
  10710. }
  10711. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10712. {
  10713. mtrace();
  10714. int result = PASS;
  10715. json_object *DeleteCertificate;
  10716. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10717. DeleteCertificate = json_tokener_parse(payload);
  10718. if(!is_error(DeleteCertificate))
  10719. {
  10720. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10721. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10722. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10723. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10724. }
  10725. json_object_put(DeleteCertificate);
  10726. /*
  10727. * TODO: Delete certificateSigned process
  10728. */
  10729. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  10730. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  10731. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  10732. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  10733. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  10734. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  10735. sendDeleteCertificateConfirmation(uuid);
  10736. return result;
  10737. }
  10738. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10739. {
  10740. mtrace();
  10741. int result = PASS;
  10742. json_object *ExtendedTriggerMessage;
  10743. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10744. ExtendedTriggerMessage = json_tokener_parse(payload);
  10745. if(!is_error(ExtendedTriggerMessage))
  10746. {
  10747. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10748. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10749. {
  10750. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10751. }
  10752. else
  10753. {
  10754. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  10755. }
  10756. }
  10757. json_object_put(ExtendedTriggerMessage);
  10758. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  10759. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  10760. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10761. {
  10762. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10763. }
  10764. else
  10765. {
  10766. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10767. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10768. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10769. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10770. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10771. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10772. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10773. {
  10774. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10775. }
  10776. else
  10777. {
  10778. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10779. }
  10780. }
  10781. sendExtendedTriggerMessageConfirmation(uuid);
  10782. //==========================
  10783. // Trigger message
  10784. //==========================
  10785. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10786. {
  10787. //sendBootNotificationRequest();
  10788. server_sign = FALSE;
  10789. }
  10790. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10791. {
  10792. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  10793. }
  10794. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10795. {
  10796. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10797. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10798. {
  10799. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10800. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10801. }
  10802. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10803. }
  10804. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10805. {
  10806. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10807. }
  10808. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10809. {
  10810. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10811. {
  10812. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10813. }
  10814. else
  10815. {
  10816. for(int idx=0;idx< gunTotalNumber;idx++)
  10817. {
  10818. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10819. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10820. }
  10821. }
  10822. }
  10823. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10824. {
  10825. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  10826. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  10827. {
  10828. 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\" &");
  10829. }
  10830. }
  10831. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10832. {
  10833. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10834. {
  10835. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10836. }
  10837. else
  10838. {
  10839. for(int idx=0;idx< gunTotalNumber;idx++)
  10840. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10841. }
  10842. }
  10843. return result;
  10844. }
  10845. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10846. {
  10847. mtrace();
  10848. int result = PASS;
  10849. json_object *GetInstalledCertificateIds;
  10850. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10851. GetInstalledCertificateIds = json_tokener_parse(payload);
  10852. if(!is_error(GetInstalledCertificateIds))
  10853. {
  10854. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10855. }
  10856. json_object_put(GetInstalledCertificateIds);
  10857. /*
  10858. * TODO: Return installed certificate process
  10859. */
  10860. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10861. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  10862. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10863. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  10864. sendGetInstalledCertificateIdsConfirmation(uuid);
  10865. return result;
  10866. }
  10867. int handleGetLogRequest(char *uuid, char *payload)
  10868. {
  10869. mtrace();
  10870. int result = PASS;
  10871. json_object *GetLog;
  10872. DEBUG_INFO("handleGetLogRequest...\n");
  10873. GetLog = json_tokener_parse(payload);
  10874. if(!is_error(GetLog))
  10875. {
  10876. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10877. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10878. if(json_object_object_get(GetLog, "retries") != NULL)
  10879. {
  10880. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10881. }
  10882. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10883. {
  10884. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10885. }
  10886. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10887. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10888. {
  10889. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10890. }
  10891. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10892. {
  10893. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10894. }
  10895. }
  10896. json_object_put(GetLog);
  10897. /*
  10898. * TODO: Upload log process
  10899. */
  10900. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  10901. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  10902. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  10903. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  10904. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  10905. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  10906. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  10907. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  10908. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  10909. sendGetLogConfirmation(uuid);
  10910. return result;
  10911. }
  10912. int handleInstallCertificateRequest(char *uuid, char *payload)
  10913. {
  10914. mtrace();
  10915. int result = PASS;
  10916. json_object *InstallCertificate;
  10917. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10918. InstallCertificate = json_tokener_parse(payload);
  10919. if(!is_error(InstallCertificate))
  10920. {
  10921. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10922. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10923. /*
  10924. * TODO: Install certificate process
  10925. */
  10926. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  10927. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  10928. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  10929. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  10930. sendInstallCertificateConfirmation(uuid);
  10931. }
  10932. json_object_put(InstallCertificate);
  10933. return result;
  10934. }
  10935. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10936. {
  10937. mtrace();
  10938. int result = PASS;
  10939. json_object *SignedUpdateFirmware;
  10940. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10941. SignedUpdateFirmware = json_tokener_parse(payload);
  10942. if(!is_error(SignedUpdateFirmware))
  10943. {
  10944. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10945. {
  10946. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10947. }
  10948. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10949. {
  10950. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10951. }
  10952. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10953. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10954. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10955. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10956. {
  10957. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10958. }
  10959. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10960. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10961. }
  10962. json_object_put(SignedUpdateFirmware);
  10963. /*
  10964. * TODO: Upgrade firmware process
  10965. */
  10966. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10967. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  10968. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  10969. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  10970. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  10971. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  10972. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  10973. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  10974. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  10975. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  10976. sendInstallCertificateConfirmation(uuid);
  10977. return result;
  10978. }
  10979. int handleUnknownRequest(char *uuid, char *payload)
  10980. {
  10981. mtrace();
  10982. int result = PASS;
  10983. DEBUG_INFO("handleUnknownRequest...\n");
  10984. sendUnknownConfirmation(uuid);
  10985. result = PASS;
  10986. return result;
  10987. }
  10988. //==========================================
  10989. // Handle server response routine
  10990. //==========================================
  10991. void handleAuthorizeResponse(char *payload, int gun_index)
  10992. {
  10993. mtrace();
  10994. char expiryDatestr[30]={0};
  10995. char parentIdTagstr[20]={0};
  10996. char statusstr[20]={0};
  10997. int expiryDateISNULL=FALSE;
  10998. int parentIdTagISNULL=FALSE;
  10999. DEBUG_INFO("handleAuthorizeResponse...\n");
  11000. json_object *Authorize;
  11001. Authorize = json_tokener_parse(payload);
  11002. if(!is_error(Authorize))
  11003. {
  11004. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11005. {
  11006. // Required data
  11007. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11008. // Optional data
  11009. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11010. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11011. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11012. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11013. }
  11014. }
  11015. json_object_put(Authorize);
  11016. if(expiryDateISNULL == FALSE)
  11017. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11018. if(parentIdTagISNULL == FALSE)
  11019. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11020. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11021. //Update idTag information to authorization cache if supproted
  11022. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11023. {
  11024. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11025. }
  11026. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11027. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11028. authorizeRetryTimes = 0;
  11029. }
  11030. void handleBootNotificationResponse(char *payload, int gun_index)
  11031. {
  11032. mtrace();
  11033. char statusStr[12]={0};
  11034. char currentTimeStr[30]={0};
  11035. int intervalInt = 0;
  11036. DEBUG_INFO("handleBootNotificationResponse...\n");
  11037. json_object *BootNotification;
  11038. BootNotification = json_tokener_parse(payload);
  11039. if(!is_error(BootNotification))
  11040. {
  11041. // Required data
  11042. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11043. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11044. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11045. }
  11046. json_object_put(BootNotification);
  11047. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11048. BootNotificationInterval = intervalInt;
  11049. HeartBeatWaitTime = intervalInt;
  11050. //write back to ShmOCPP16DataPH->BootNotification
  11051. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11052. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11053. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11054. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11055. {
  11056. server_sign = TRUE;
  11057. server_pending =FALSE;
  11058. }
  11059. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11060. {
  11061. server_pending = TRUE;
  11062. }
  11063. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11064. srand(time(NULL));
  11065. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11066. SetOcppConnStatus(TRUE);
  11067. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11068. }
  11069. void handleDataTransferResponse(char *payload, int gun_index)
  11070. {
  11071. char sstr[160]={0};//sstr[200]={ 0 };
  11072. int c = 0;
  11073. char *loc;
  11074. DEBUG_INFO("handleDataTransferResponse ...\n");
  11075. loc = strstr(payload, "status");
  11076. printf("loc=%s\n",loc);
  11077. c = 0;
  11078. while (loc[3+strlen("status")+c] != '\"')
  11079. {
  11080. sstr[c] = loc[3+strlen("status")+c];
  11081. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11082. c++;
  11083. }
  11084. sstr[c] = '\0';
  11085. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11086. }
  11087. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11088. {
  11089. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11090. //struct json_object *obj;
  11091. // obj = json_tokener_parse(payload);
  11092. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11093. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11094. //No fields are defined.
  11095. }
  11096. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11097. {
  11098. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11099. //struct json_object *obj;
  11100. // obj = json_tokener_parse(payload);
  11101. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11102. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11103. //No fields are defined.
  11104. }
  11105. void handleHeartbeatResponse(char *payload, int gun_index)
  11106. {
  11107. mtrace();
  11108. DEBUG_INFO("handleHeartbeatResponse...\n");
  11109. json_object *Heartbeat;
  11110. Heartbeat = json_tokener_parse(payload);
  11111. if(!is_error(Heartbeat))
  11112. {
  11113. // Required data
  11114. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11115. }
  11116. json_object_put(Heartbeat);
  11117. if(FirstHeartBeat == 0)
  11118. {
  11119. FirstHeartBeat = 1;
  11120. DEBUG_INFO("FirstHeartBeat \n");
  11121. }
  11122. HeartBeatWithNOResponse = 0;
  11123. clientTime.Heartbeat=time((time_t*)NULL);
  11124. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11125. }
  11126. void handleMeterValuesResponse(char *payload, int gun_index)
  11127. {
  11128. mtrace();
  11129. DEBUG_INFO("handleMeterValuesResponse...\n");
  11130. }
  11131. void handleStartTransactionResponse(char *payload, int gun_index)
  11132. {
  11133. mtrace();
  11134. //int transactionIdInt = 0;
  11135. FILE *outfile;
  11136. char data[100]={0};
  11137. DEBUG_INFO("handleStartTransactionResponse...\n");
  11138. json_object *StartTransaction;
  11139. StartTransaction = json_tokener_parse(payload);
  11140. if(!is_error(StartTransaction))
  11141. {
  11142. // Required data
  11143. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11144. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11145. // Optional data
  11146. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11147. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11148. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11149. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11150. }
  11151. json_object_put(StartTransaction);
  11152. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11153. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11154. //-----------Start : write to the Queue TransactionId file -----------------//
  11155. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11156. {}
  11157. else
  11158. {
  11159. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  11160. if(log == NULL)
  11161. {
  11162. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11163. return ;
  11164. }
  11165. else
  11166. {
  11167. fclose(log);
  11168. }
  11169. }
  11170. // open file for writing
  11171. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11172. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  11173. {
  11174. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  11175. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11176. fputs(data, outfile);
  11177. fclose (outfile);
  11178. }
  11179. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11180. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11181. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11182. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  11183. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11184. }
  11185. void handleStatusNotificationResponse(char *payload, int gun_index)
  11186. {
  11187. mtrace();
  11188. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11189. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11190. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11191. }
  11192. void handleStopTransactionnResponse(char *payload, int gun_index)
  11193. {
  11194. mtrace();
  11195. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11196. json_object *StopTransaction;
  11197. StopTransaction = json_tokener_parse(payload);
  11198. if(!is_error(StopTransaction))
  11199. {
  11200. // Optional data
  11201. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11202. {
  11203. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11204. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11205. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11206. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11207. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11208. }
  11209. }
  11210. json_object_put(StopTransaction);
  11211. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11212. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11213. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11214. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11215. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11216. }
  11217. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11218. {
  11219. mtrace();
  11220. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11221. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  11222. }
  11223. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11224. {
  11225. mtrace();
  11226. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11227. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  11228. }
  11229. void handleSignCertificateResponse(char *payload, int gun_index)
  11230. {
  11231. mtrace();
  11232. DEBUG_INFO("handleSignCertificateResponse...\n");
  11233. json_object *SignCertificate;
  11234. SignCertificate = json_tokener_parse(payload);
  11235. if(!is_error(SignCertificate))
  11236. {
  11237. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11238. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  11239. }
  11240. json_object_put(SignCertificate);
  11241. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  11242. }
  11243. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11244. {
  11245. mtrace();
  11246. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11247. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11248. }
  11249. //==========================================
  11250. // Handle Error routine
  11251. //==========================================
  11252. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11253. {
  11254. mtrace();
  11255. #ifdef SystemLogMessage
  11256. DEBUG_INFO("errorCode: %s\n", errorCode);
  11257. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11258. DEBUG_INFO("errorDetails: %s\n", payload);
  11259. #endif
  11260. }
  11261. //===============================================
  11262. // Common routine
  11263. //===============================================
  11264. int initialConfigurationTable(void)
  11265. {
  11266. //clock_t start_t, end_t, total_t;
  11267. FILE *fp;
  11268. FILE *outfile;
  11269. char str[512]={0};
  11270. char sstr[256]={0};
  11271. int c = 0;
  11272. char *loc;
  11273. int confVersion = 3;
  11274. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11275. //start_t = clock();
  11276. //printf("Starting of the program, start_t = %ld\n", start_t);
  11277. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11278. // Check configuration file size is correct
  11279. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  11280. {
  11281. struct stat st;
  11282. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  11283. if(st.st_size < 3100)
  11284. {
  11285. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  11286. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11287. }
  11288. }
  11289. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  11290. {
  11291. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11292. if(outfile == NULL)
  11293. {
  11294. DEBUG_INFO("Error opening file\n");
  11295. return FALSE;
  11296. }
  11297. /*Core Profile*/
  11298. //AllowOfflineTxForUnknownId
  11299. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11301. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11303. //AuthorizationCacheEnabled
  11304. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11308. //AuthorizeRemoteTxRequests
  11309. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11310. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11313. //BlinkRepeat
  11314. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11315. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11316. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11318. //ClockAlignedDataInterval
  11319. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11320. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11321. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11323. //ConnectionTimeOut
  11324. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11328. //GetConfigurationMaxKeys
  11329. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11330. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11331. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11333. // HeartbeatInterval
  11334. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11335. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11336. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11338. // LightIntensity
  11339. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11340. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11341. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11343. // LocalAuthorizeOffline
  11344. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11345. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11348. // LocalPreAuthorize
  11349. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11350. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11351. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11353. // MaxEnergyOnInvalidId
  11354. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11355. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11358. // MeterValuesAlignedData
  11359. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11361. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11363. else
  11364. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11366. // MeterValuesAlignedDataMaxLength
  11367. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11369. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11371. else
  11372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11374. // MeterValuesSampledData
  11375. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11379. else
  11380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11382. // MeterValuesSampledDataMaxLength
  11383. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11384. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11386. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11387. else
  11388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11390. // MeterValueSampleInterval
  11391. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11392. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11393. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11395. // MinimumStatusDuration
  11396. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11397. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11399. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11401. // NumberOfConnectors
  11402. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11404. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11405. {
  11406. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11407. }
  11408. else
  11409. {
  11410. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11411. }
  11412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11413. // ResetRetries
  11414. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11415. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11416. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11418. // ConnectorPhaseRotation
  11419. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11420. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11421. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11423. // ConnectorPhaseRotationMaxLength
  11424. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11425. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11426. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11428. // StopTransactionOnEVSideDisconnect
  11429. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11430. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11431. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11433. // StopTransactionOnInvalidId
  11434. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11435. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11436. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11438. // StopTxnAlignedData
  11439. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11440. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11441. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11443. // StopTxnAlignedDataMaxLength
  11444. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11445. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11446. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11448. // StopTxnSampledData
  11449. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11450. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11451. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11452. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11453. else
  11454. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11456. // StopTxnSampledDataMaxLength
  11457. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11458. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11460. {
  11461. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11462. }
  11463. else
  11464. {
  11465. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11466. }
  11467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11468. // SupportedFeatureProfiles
  11469. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11470. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11471. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11473. // SupportedFeatureProfilesMaxLength
  11474. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11475. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11476. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11478. // TransactionMessageAttempts
  11479. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11480. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11481. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11482. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11484. // TransactionMessageRetryInterval
  11485. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11486. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11487. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11488. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11490. // UnlockConnectorOnEVSideDisconnect
  11491. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11492. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11493. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11495. // WebSocketPingInterval
  11496. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11497. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11498. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11500. // QueueOffLineStartTransactionMessage
  11501. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11502. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11503. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11505. // AuthorizationKey
  11506. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11507. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11508. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  11509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11510. // SecurityProfile
  11511. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11512. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11513. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  11514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11515. // DefaultPrice
  11516. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11517. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11518. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11520. // CustomDisplayCostAndPrice
  11521. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11522. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11523. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11525. // CustomIdleFeeAfterStop
  11526. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11527. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11528. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11530. // Configuration Version
  11531. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11532. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11533. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11535. //* Local Auth List Management Profile*/
  11536. #if 0
  11537. //For OCTT Test Case
  11538. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11539. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11540. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11541. #endif
  11542. #if 1
  11543. //LocalAuthListEnabled
  11544. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11545. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11546. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11548. #endif
  11549. //LocalAuthListMaxLength
  11550. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11551. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11552. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11554. //SendLocalListMaxLength
  11555. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11556. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11557. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11559. //ReserveConnectorZeroSupported
  11560. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11561. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11562. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11564. //* Smart Charging Profile */
  11565. //ChargeProfileMaxStackLevel
  11566. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11567. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11568. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11570. // ChargingScheduleAllowedChargingRateUnit
  11571. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11572. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11573. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  11574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11575. // ChargingScheduleMaxPeriods
  11576. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11577. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11578. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11580. // ConnectorSwitch3to1PhaseSupported
  11581. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11582. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11583. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  11584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11585. // MaxChargingProfilesInstalled
  11586. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11587. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11588. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11590. fclose(outfile);
  11591. }
  11592. else
  11593. {
  11594. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  11595. char keystr[60]={0};
  11596. char readonlystr[10]={0};
  11597. char valuestr[256]={0};
  11598. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  11599. if(fp == NULL) {
  11600. DEBUG_INFO("Error opening file");
  11601. return FALSE;
  11602. }
  11603. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11604. {
  11605. //DEBUG_INFO("Get Configuration \n");
  11606. if(strlen(str) > 0)
  11607. {
  11608. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11609. //*************************key*********************************/
  11610. if(strstr(str, "key") != NULL)
  11611. {
  11612. loc = strstr(str, "key");
  11613. c = 0;
  11614. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11615. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11616. {
  11617. sstr[c] = loc[strlen("key")+3+c];
  11618. c++;
  11619. }
  11620. sstr[c] = '\0';
  11621. strcpy(keystr,sstr);
  11622. }
  11623. //*************************readonly*********************************/
  11624. if(strstr(str, "readonly") != NULL)
  11625. {
  11626. loc = strstr(str, "readonly");
  11627. c = 0;
  11628. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11629. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11630. {
  11631. sstr[c] = loc[strlen("readonly")+2+c];
  11632. c++;
  11633. }
  11634. sstr[c] = '\0';
  11635. strcpy(readonlystr,sstr);
  11636. }
  11637. //*************************value*********************************/
  11638. if(strstr(str, "value") != NULL)
  11639. {
  11640. loc = strstr(str, "value");
  11641. c = 0;
  11642. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11643. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11644. {
  11645. sstr[c] = loc[strlen("value")+3+c];
  11646. c++;
  11647. }
  11648. sstr[c] = '\0';
  11649. strcpy(valuestr,sstr);
  11650. }
  11651. // DEBUG_INFO("keystr=%s\n",keystr);
  11652. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11653. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11654. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11655. {
  11656. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11657. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11658. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11659. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11660. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11661. }
  11662. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11663. {
  11664. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11665. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11666. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11667. }
  11668. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11669. {
  11670. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11671. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11672. }
  11673. if(strcmp(keystr, "BlinkRepeat") == 0)
  11674. {
  11675. //Charger.BlinkRepeat = Integer.parseInt(value);
  11676. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11677. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11678. }
  11679. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11680. {
  11681. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11682. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11683. }
  11684. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11685. {
  11686. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11687. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11688. }
  11689. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11690. {
  11691. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11692. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11693. }
  11694. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11695. {
  11696. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11697. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11698. HeartBeatWaitTime = atoi(valuestr);
  11699. }
  11700. if(strcmp(keystr, "LightIntensity") == 0)
  11701. {
  11702. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11703. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11704. }
  11705. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11706. {
  11707. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11708. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11709. }
  11710. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11711. {
  11712. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11713. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11714. }
  11715. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11716. {
  11717. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11718. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11719. }
  11720. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11721. {
  11722. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11723. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11724. }
  11725. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11726. {
  11727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11728. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11729. }
  11730. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11731. {
  11732. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11733. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11734. }
  11735. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11736. {
  11737. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11738. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11739. }
  11740. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11741. {
  11742. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11743. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11744. }
  11745. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11746. {
  11747. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11748. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11749. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11750. }
  11751. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11752. {
  11753. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11754. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11755. }
  11756. if(strcmp(keystr, "ResetRetries") == 0)
  11757. {
  11758. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11759. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11760. }
  11761. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11762. {
  11763. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11764. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11765. }
  11766. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11767. {
  11768. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11769. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11770. }
  11771. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11772. {
  11773. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11774. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11775. }
  11776. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11777. {
  11778. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11779. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11780. }
  11781. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11782. {
  11783. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11784. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11785. }
  11786. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11787. {
  11788. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11789. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11790. }
  11791. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11792. {
  11793. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11794. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11795. }
  11796. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11797. {
  11798. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11799. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11800. }
  11801. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11802. {
  11803. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11804. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11805. }
  11806. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11807. {
  11808. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11809. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11810. }
  11811. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11812. {
  11813. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11814. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11815. TransactionMessageAttemptsValue = atoi(valuestr);
  11816. }
  11817. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11818. {
  11819. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11820. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11821. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11822. }
  11823. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11824. {
  11825. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11826. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11827. }
  11828. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11829. {
  11830. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11831. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11832. }
  11833. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11834. {
  11835. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11836. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11837. }
  11838. if(strcmp(keystr, "AuthorizationKey") == 0)
  11839. {
  11840. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11841. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11842. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11843. }
  11844. if(strcmp(keystr, "SecurityProfile") == 0)
  11845. {
  11846. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11847. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11848. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  11849. }
  11850. if(strcmp(keystr, "DefaultPrice") == 0)
  11851. {
  11852. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11853. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11854. }
  11855. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11856. {
  11857. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11858. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11859. }
  11860. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11861. {
  11862. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11863. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11864. }
  11865. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11866. {
  11867. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11868. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11869. }
  11870. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11871. {
  11872. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11873. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11874. }
  11875. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11876. {
  11877. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11878. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11879. }
  11880. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11881. {
  11882. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11883. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11884. }
  11885. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11886. {
  11887. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11888. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11889. }
  11890. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11891. {
  11892. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11893. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11894. }
  11895. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11896. {
  11897. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11898. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11899. }
  11900. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11901. {
  11902. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11903. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11904. }
  11905. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11906. {
  11907. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11908. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11909. }
  11910. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11911. {
  11912. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11913. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11914. }
  11915. }
  11916. }
  11917. fclose(fp);
  11918. }
  11919. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11920. {
  11921. return PASS;
  11922. }
  11923. else
  11924. {
  11925. return FAIL;
  11926. }
  11927. }
  11928. void StoreConfigurationTable(void)
  11929. {
  11930. FILE *outfile;
  11931. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11932. if(outfile == NULL)
  11933. {
  11934. DEBUG_INFO("Error opening file");
  11935. return ;
  11936. }
  11937. /*Core Profile*/
  11938. //AllowOfflineTxForUnknownId
  11939. /*
  11940. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11941. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11944. */
  11945. //DEBUG_INFO("data=%s\n",data);
  11946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11947. //AuthorizationCacheEnabled
  11948. /*
  11949. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11951. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11952. */
  11953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11954. //AuthorizeRemoteTxRequests
  11955. /*
  11956. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11958. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11959. */
  11960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11961. //BlinkRepeat
  11962. /*
  11963. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11966. */
  11967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11968. //ClockAlignedDataInterval
  11969. /*
  11970. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11972. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11973. */
  11974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11975. //ConnectionTimeOut
  11976. /*
  11977. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11979. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11980. */
  11981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11982. //GetConfigurationMaxKeys
  11983. /*
  11984. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11987. */
  11988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11989. // HeartbeatInterval
  11990. /*
  11991. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11993. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11994. */
  11995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11996. // LightIntensity
  11997. /*
  11998. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12001. */
  12002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12003. // LocalAuthorizeOffline
  12004. /*
  12005. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12008. */
  12009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12010. // LocalPreAuthorize
  12011. /*
  12012. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12014. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12015. */
  12016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12017. // MaxEnergyOnInvalidId
  12018. /*
  12019. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12020. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12022. */
  12023. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12025. // MeterValuesAlignedData
  12026. /*
  12027. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12030. */
  12031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12032. // MeterValuesAlignedDataMaxLength
  12033. /*
  12034. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12037. */
  12038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12039. // MeterValuesSampledData
  12040. /*
  12041. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12044. */
  12045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12046. // MeterValuesSampledDataMaxLength
  12047. /*
  12048. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12051. */
  12052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12053. // MeterValueSampleInterval
  12054. /*
  12055. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12058. */
  12059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12060. // MinimumStatusDuration
  12061. /*
  12062. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12065. */
  12066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12067. // NumberOfConnectors
  12068. /*
  12069. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12070. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12072. {
  12073. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12074. }
  12075. else
  12076. {
  12077. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12078. }
  12079. */
  12080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12081. // ResetRetries
  12082. /*
  12083. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12085. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12086. */
  12087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12088. // ConnectorPhaseRotation
  12089. /*
  12090. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12093. */
  12094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12095. // ConnectorPhaseRotationMaxLength
  12096. /*
  12097. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12098. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12099. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12100. */
  12101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12102. // StopTransactionOnEVSideDisconnect
  12103. /*
  12104. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12106. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12107. */
  12108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12109. // StopTransactionOnInvalidId
  12110. /*
  12111. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12114. */
  12115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12116. // StopTxnAlignedData
  12117. /*
  12118. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12121. */
  12122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12123. // StopTxnAlignedDataMaxLength
  12124. /*
  12125. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12127. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12128. */
  12129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12130. // StopTxnSampledData
  12131. /*
  12132. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12133. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12135. */
  12136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12137. // StopTxnSampledDataMaxLength
  12138. /*
  12139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12142. */
  12143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12144. // SupportedFeatureProfiles
  12145. /*
  12146. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12147. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12148. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12149. */
  12150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12151. // SupportedFeatureProfilesMaxLength
  12152. /*
  12153. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12156. */
  12157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12158. // TransactionMessageAttempts
  12159. /*
  12160. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12162. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12163. */
  12164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12165. // TransactionMessageRetryInterval
  12166. /*
  12167. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12170. */
  12171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12172. // UnlockConnectorOnEVSideDisconnect
  12173. /*
  12174. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12177. */
  12178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12179. // WebSocketPingInterval
  12180. /*
  12181. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12183. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12184. */
  12185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12186. // QueueOffLineStartTransactionMessage
  12187. /*
  12188. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12191. */
  12192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12193. // AuthorizationKey
  12194. /*
  12195. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12198. */
  12199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12200. // SecurityProfile
  12201. /*
  12202. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12205. */
  12206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12207. // DefaultPrice
  12208. /*
  12209. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12210. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12212. */
  12213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12214. // CustomDisplayCostAndPrice
  12215. /*
  12216. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12219. */
  12220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12221. // CustomIdleFeeAfterStop
  12222. /*
  12223. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12224. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12225. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12226. */
  12227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12228. // ConfigurationVersion
  12229. /*
  12230. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12231. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12232. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12233. */
  12234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12235. //* Local Auth List Management Profile*/
  12236. //LocalAuthListEnabled
  12237. /*
  12238. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12239. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12241. */
  12242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12243. //LocalAuthListMaxLength
  12244. /*
  12245. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12246. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12247. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12248. */
  12249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12250. //SendLocalListMaxLength
  12251. /*
  12252. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12253. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12255. */
  12256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12257. //ReserveConnectorZeroSupported
  12258. /*
  12259. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12261. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12262. */
  12263. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12264. //* Smart Charging Profile */
  12265. //ChargeProfileMaxStackLevel
  12266. /*
  12267. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12270. */
  12271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12272. // ChargingScheduleAllowedChargingRateUnit
  12273. /*
  12274. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12275. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12276. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12277. */
  12278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12279. // ChargingScheduleMaxPeriods
  12280. /*
  12281. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12282. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12284. */
  12285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12286. // ConnectorSwitch3to1PhaseSupported
  12287. /*
  12288. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12291. */
  12292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12293. // MaxChargingProfilesInstalled
  12294. /*
  12295. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12298. */
  12299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12300. fclose(outfile);
  12301. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12302. }
  12303. void getKeyValue(char *keyReq)
  12304. {
  12305. int isEmpty = FALSE;
  12306. int isKnowKey = FALSE;
  12307. DEBUG_INFO("keyReq = %s\n", keyReq);
  12308. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12309. isEmpty = TRUE;
  12310. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12311. {
  12312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12314. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12315. {
  12316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12317. }
  12318. else
  12319. {
  12320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12321. }
  12322. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12323. isKnowKey = TRUE;
  12324. }
  12325. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12326. {
  12327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12329. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12330. {
  12331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12332. }
  12333. else
  12334. {
  12335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12336. }
  12337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12338. isKnowKey = TRUE;
  12339. }
  12340. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12341. {
  12342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12344. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12345. {
  12346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12347. }
  12348. else
  12349. {
  12350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12351. }
  12352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12353. isKnowKey = TRUE;
  12354. }
  12355. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12356. {
  12357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12359. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12360. {
  12361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12362. }
  12363. else
  12364. {
  12365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12366. }
  12367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12368. isKnowKey = TRUE;
  12369. }
  12370. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12371. {
  12372. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12374. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12375. {
  12376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12377. }
  12378. else
  12379. {
  12380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12381. }
  12382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12383. isKnowKey = TRUE;
  12384. }
  12385. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12386. {
  12387. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12389. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12390. {
  12391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12392. }
  12393. else
  12394. {
  12395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12396. }
  12397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12398. isKnowKey = TRUE;
  12399. }
  12400. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12401. {
  12402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12404. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12405. {
  12406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12407. }
  12408. else
  12409. {
  12410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12411. }
  12412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12413. isKnowKey = TRUE;
  12414. }
  12415. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12416. {
  12417. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12419. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12420. {
  12421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12422. }
  12423. else
  12424. {
  12425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12426. }
  12427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12428. isKnowKey = TRUE;
  12429. }
  12430. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12431. {
  12432. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12434. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12435. {
  12436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12437. }
  12438. else
  12439. {
  12440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12441. }
  12442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12443. isKnowKey = TRUE;
  12444. }
  12445. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12446. {
  12447. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12449. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12450. {
  12451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12452. }
  12453. else
  12454. {
  12455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12456. }
  12457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12458. isKnowKey = TRUE;
  12459. }
  12460. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12461. {
  12462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12464. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12465. {
  12466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12467. }
  12468. else
  12469. {
  12470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12471. }
  12472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12473. isKnowKey = TRUE;
  12474. }
  12475. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12476. {
  12477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12479. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12480. {
  12481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12482. }
  12483. else
  12484. {
  12485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12486. }
  12487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12488. isKnowKey = TRUE;
  12489. }
  12490. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12491. {
  12492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12494. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12495. {
  12496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12497. }
  12498. else
  12499. {
  12500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12501. }
  12502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12503. isKnowKey = TRUE;
  12504. }
  12505. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12506. {
  12507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12509. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12510. {
  12511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12512. }
  12513. else
  12514. {
  12515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12516. }
  12517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12518. isKnowKey = TRUE;
  12519. }
  12520. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12521. {
  12522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12524. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12525. {
  12526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12527. }
  12528. else
  12529. {
  12530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12531. }
  12532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12533. isKnowKey = TRUE;
  12534. }
  12535. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12536. {
  12537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12539. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12540. {
  12541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12542. }
  12543. else
  12544. {
  12545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12546. }
  12547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12548. isKnowKey = TRUE;
  12549. }
  12550. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12551. {
  12552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12554. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12555. {
  12556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12557. }
  12558. else
  12559. {
  12560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12561. }
  12562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12563. isKnowKey = TRUE;
  12564. }
  12565. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12566. {
  12567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12569. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12570. {
  12571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12572. }
  12573. else
  12574. {
  12575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12576. }
  12577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  12578. isKnowKey = TRUE;
  12579. }
  12580. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12581. {
  12582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12583. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12584. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12585. {
  12586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12587. }
  12588. else
  12589. {
  12590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12591. }
  12592. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12594. isKnowKey = TRUE;
  12595. }
  12596. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12597. {
  12598. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12600. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12601. {
  12602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12603. }
  12604. else
  12605. {
  12606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12607. }
  12608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12609. isKnowKey = TRUE;
  12610. }
  12611. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12612. {
  12613. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12615. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12616. {
  12617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12618. }
  12619. else
  12620. {
  12621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12622. }
  12623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12624. isKnowKey = TRUE;
  12625. }
  12626. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12627. {
  12628. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12630. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12631. {
  12632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12633. }
  12634. else
  12635. {
  12636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12637. }
  12638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12639. isKnowKey = TRUE;
  12640. }
  12641. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12642. {
  12643. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12645. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12646. {
  12647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12648. }
  12649. else
  12650. {
  12651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12652. }
  12653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12654. isKnowKey = TRUE;
  12655. }
  12656. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12657. {
  12658. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12660. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12661. {
  12662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12663. }
  12664. else
  12665. {
  12666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12667. }
  12668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12669. isKnowKey = TRUE;
  12670. }
  12671. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12672. {
  12673. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12675. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12676. {
  12677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12678. }
  12679. else
  12680. {
  12681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12682. }
  12683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12684. isKnowKey = TRUE;
  12685. }
  12686. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12687. {
  12688. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12689. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12690. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12691. {
  12692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12693. }
  12694. else
  12695. {
  12696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12697. }
  12698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12699. isKnowKey = TRUE;
  12700. }
  12701. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12702. {
  12703. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12705. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12706. {
  12707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12708. }
  12709. else
  12710. {
  12711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12712. }
  12713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12714. isKnowKey = TRUE;
  12715. }
  12716. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12717. {
  12718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12720. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12721. {
  12722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12723. }
  12724. else
  12725. {
  12726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12727. }
  12728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12729. isKnowKey = TRUE;
  12730. }
  12731. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12732. {
  12733. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12734. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12735. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12736. {
  12737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12738. }
  12739. else
  12740. {
  12741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12742. }
  12743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12744. isKnowKey = TRUE;
  12745. }
  12746. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12747. {
  12748. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12749. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12750. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12751. {
  12752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12753. }
  12754. else
  12755. {
  12756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12757. }
  12758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12759. isKnowKey = TRUE;
  12760. }
  12761. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12762. {
  12763. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12764. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12765. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12766. {
  12767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12768. }
  12769. else
  12770. {
  12771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12772. }
  12773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12774. isKnowKey = TRUE;
  12775. }
  12776. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12777. {
  12778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12779. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12780. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12781. {
  12782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12783. }
  12784. else
  12785. {
  12786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12787. }
  12788. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12789. isKnowKey = TRUE;
  12790. }
  12791. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12792. {
  12793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12795. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12796. {
  12797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12798. }
  12799. else
  12800. {
  12801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12802. }
  12803. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12804. isKnowKey = TRUE;
  12805. }
  12806. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12807. {
  12808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12810. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12811. {
  12812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12813. }
  12814. else
  12815. {
  12816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12817. }
  12818. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12819. isKnowKey = TRUE;
  12820. }
  12821. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12822. {
  12823. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12824. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12825. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12826. {
  12827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12828. }
  12829. else
  12830. {
  12831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12832. }
  12833. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12834. isKnowKey = TRUE;
  12835. }
  12836. /*
  12837. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12838. {
  12839. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12841. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12842. {
  12843. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12844. }
  12845. else
  12846. {
  12847. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12848. }
  12849. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12850. isKnowKey = TRUE;
  12851. }*/
  12852. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12853. {
  12854. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12856. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12857. {
  12858. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12859. }
  12860. else
  12861. {
  12862. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12863. }
  12864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12865. isKnowKey = TRUE;
  12866. }
  12867. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12868. {
  12869. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12870. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12871. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12872. {
  12873. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12874. }
  12875. else
  12876. {
  12877. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12878. }
  12879. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12880. isKnowKey = TRUE;
  12881. }
  12882. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12883. {
  12884. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12886. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12887. {
  12888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12889. }
  12890. else
  12891. {
  12892. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12893. }
  12894. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12895. isKnowKey = TRUE;
  12896. }
  12897. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12898. {
  12899. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12901. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12902. {
  12903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12904. }
  12905. else
  12906. {
  12907. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12908. }
  12909. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12910. isKnowKey = TRUE;
  12911. }
  12912. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12913. {
  12914. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12916. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12917. {
  12918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12919. }
  12920. else
  12921. {
  12922. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12923. }
  12924. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12925. isKnowKey = TRUE;
  12926. }
  12927. #if 1
  12928. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12929. {
  12930. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12931. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12932. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12933. {
  12934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12935. }
  12936. else
  12937. {
  12938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12939. }
  12940. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12941. isKnowKey = TRUE;
  12942. }
  12943. #endif
  12944. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12945. {
  12946. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12947. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12948. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12949. {
  12950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12951. }
  12952. else
  12953. {
  12954. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12955. }
  12956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12957. isKnowKey = TRUE;
  12958. }
  12959. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12960. {
  12961. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12963. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12964. {
  12965. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12966. }
  12967. else
  12968. {
  12969. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12970. }
  12971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12972. isKnowKey = TRUE;
  12973. }
  12974. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12975. {
  12976. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12978. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12979. {
  12980. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12981. }
  12982. else
  12983. {
  12984. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12985. }
  12986. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12987. isKnowKey = TRUE;
  12988. }
  12989. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12990. {
  12991. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12993. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12994. {
  12995. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12996. }
  12997. else
  12998. {
  12999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13000. }
  13001. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13002. isKnowKey = TRUE;
  13003. }
  13004. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13005. {
  13006. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13008. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13009. {
  13010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13011. }
  13012. else
  13013. {
  13014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13015. }
  13016. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13017. isKnowKey = TRUE;
  13018. }
  13019. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13020. {
  13021. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13023. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13024. {
  13025. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13026. }
  13027. else
  13028. {
  13029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13030. }
  13031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13032. isKnowKey = TRUE;
  13033. }
  13034. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13035. {
  13036. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13038. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13039. {
  13040. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13041. }
  13042. else
  13043. {
  13044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13045. }
  13046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13047. isKnowKey = TRUE;
  13048. }
  13049. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13050. {
  13051. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13053. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13054. {
  13055. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13056. }
  13057. else
  13058. {
  13059. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13060. }
  13061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13062. isKnowKey = TRUE;
  13063. }
  13064. //=========================================================
  13065. if(!isEmpty && !isKnowKey)
  13066. {
  13067. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13068. strcpy(unknownkey[UnknownKeynum], keyReq);
  13069. UnknownKeynum = UnknownKeynum + 1;
  13070. }
  13071. }
  13072. void processUnkownKey(void)
  13073. {
  13074. DEBUG_INFO("processUnkownKey...\n");
  13075. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13076. for(int index=0; index < UnknownKeynum; index++)
  13077. {
  13078. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13079. {
  13080. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13081. }
  13082. }
  13083. }
  13084. int setKeyValue(char *key, char *value)
  13085. {
  13086. int isSuccess = NotSupported;
  13087. int check_ascii=0;
  13088. char str[256]={0};
  13089. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13090. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13091. {
  13092. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13093. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13094. {
  13095. strcpy(str, (const char*)value);
  13096. for(int i = 0; str[i]; i++){
  13097. str[i] = tolower(str[i]);
  13098. }
  13099. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13100. isSuccess = ConfigurationStatus_Accepted;
  13101. }
  13102. else
  13103. {
  13104. isSuccess = ConfigurationStatus_Rejected;
  13105. }
  13106. }
  13107. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13108. {
  13109. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13110. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13111. {
  13112. strcpy(str, (const char*)value);
  13113. for(int i = 0; str[i]; i++){
  13114. str[i] = tolower(str[i]);
  13115. }
  13116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13117. isSuccess = ConfigurationStatus_Accepted;
  13118. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13119. }
  13120. else
  13121. {
  13122. isSuccess = ConfigurationStatus_Rejected;
  13123. }
  13124. }
  13125. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13126. {
  13127. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13128. {
  13129. strcpy(str, (const char*)value);
  13130. for(int i = 0; str[i]; i++)
  13131. {
  13132. str[i] = tolower(str[i]);
  13133. }
  13134. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13135. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13136. isSuccess = ConfigurationStatus_Accepted;
  13137. }
  13138. else
  13139. {
  13140. isSuccess = ConfigurationStatus_Rejected;
  13141. }
  13142. }
  13143. if(strcmp(key, "BlinkRepeat") == 0)
  13144. {
  13145. //Charger.BlinkRepeat = Integer.parseInt(value);
  13146. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13147. {
  13148. check_ascii = value[0];
  13149. if( (check_ascii < 48) || (check_ascii > 57) )
  13150. {
  13151. isSuccess = ConfigurationStatus_Rejected;
  13152. }
  13153. else
  13154. {
  13155. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13156. isSuccess = ConfigurationStatus_Accepted;
  13157. }
  13158. }
  13159. else
  13160. {
  13161. isSuccess = ConfigurationStatus_Rejected;
  13162. }
  13163. }
  13164. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13165. {
  13166. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13167. {
  13168. check_ascii = value[0];
  13169. if( (check_ascii < 48) || (check_ascii > 57) )
  13170. {
  13171. isSuccess = ConfigurationStatus_Rejected;
  13172. }
  13173. else
  13174. {
  13175. if((atoi(value) == 0) || (atoi(value) >= 10))
  13176. {
  13177. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13178. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13179. isSuccess = ConfigurationStatus_Accepted;
  13180. }
  13181. else
  13182. isSuccess = ConfigurationStatus_Rejected;
  13183. }
  13184. }
  13185. else
  13186. {
  13187. isSuccess = ConfigurationStatus_Rejected;
  13188. }
  13189. }
  13190. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13191. {
  13192. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13193. {
  13194. check_ascii = value[0];
  13195. if( (check_ascii < 48) || (check_ascii > 57) )
  13196. {
  13197. isSuccess = ConfigurationStatus_Rejected;
  13198. }
  13199. else
  13200. {
  13201. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13202. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13203. isSuccess = ConfigurationStatus_Accepted;
  13204. }
  13205. }
  13206. else
  13207. {
  13208. isSuccess = ConfigurationStatus_Rejected;
  13209. }
  13210. }
  13211. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13212. {
  13213. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13214. {
  13215. check_ascii = value[0];
  13216. if( (check_ascii < 48) || (check_ascii > 57) )
  13217. {
  13218. isSuccess = ConfigurationStatus_Rejected;
  13219. }
  13220. else
  13221. {
  13222. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13223. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13224. isSuccess = ConfigurationStatus_Accepted;
  13225. }
  13226. }
  13227. else
  13228. {
  13229. isSuccess = ConfigurationStatus_Rejected;
  13230. }
  13231. }
  13232. if(strcmp(key, "HeartbeatInterval") == 0)
  13233. {
  13234. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13235. {
  13236. check_ascii = value[0];
  13237. if( (check_ascii < 48) || (check_ascii > 57) )
  13238. {
  13239. isSuccess = ConfigurationStatus_Rejected;
  13240. }
  13241. else
  13242. {
  13243. if((atoi(value) == 0) || (atoi(value) >= 10))
  13244. {
  13245. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13246. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13247. HeartBeatWaitTime = atoi(value);
  13248. isSuccess = ConfigurationStatus_Accepted;
  13249. }
  13250. else
  13251. {
  13252. isSuccess = ConfigurationStatus_Rejected;
  13253. }
  13254. }
  13255. }
  13256. else
  13257. {
  13258. isSuccess = ConfigurationStatus_Rejected;
  13259. }
  13260. }
  13261. if(strcmp(key, "LightIntensity") == 0)
  13262. {
  13263. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13264. {
  13265. check_ascii = value[0];
  13266. if( (check_ascii < 48) || (check_ascii > 57) )
  13267. {
  13268. isSuccess = ConfigurationStatus_Rejected;
  13269. }
  13270. else
  13271. {
  13272. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13273. isSuccess = ConfigurationStatus_Accepted;
  13274. }
  13275. }
  13276. else
  13277. {
  13278. isSuccess = ConfigurationStatus_Rejected;
  13279. }
  13280. }
  13281. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13282. {
  13283. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13284. {
  13285. strcpy(str, (const char*)value);
  13286. for(int i = 0; str[i]; i++)
  13287. {
  13288. str[i] = tolower(str[i]);
  13289. }
  13290. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13291. isSuccess = ConfigurationStatus_Accepted;
  13292. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13293. }
  13294. else
  13295. {
  13296. isSuccess = ConfigurationStatus_Rejected;
  13297. }
  13298. }
  13299. if(strcmp(key, "LocalPreAuthorize") == 0)
  13300. {
  13301. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13302. {
  13303. strcpy(str, (const char*)value);
  13304. for(int i = 0; str[i]; i++)
  13305. {
  13306. str[i] = tolower(str[i]);
  13307. }
  13308. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13309. isSuccess = ConfigurationStatus_Accepted;
  13310. }
  13311. else
  13312. {
  13313. isSuccess = ConfigurationStatus_Rejected;
  13314. }
  13315. }
  13316. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13317. {
  13318. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13319. {
  13320. check_ascii = value[0];
  13321. if( (check_ascii < 48) || (check_ascii > 57) )
  13322. {
  13323. isSuccess = ConfigurationStatus_Rejected;
  13324. }
  13325. else
  13326. {
  13327. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13328. isSuccess = ConfigurationStatus_Accepted;
  13329. }
  13330. }
  13331. else
  13332. {
  13333. isSuccess = ConfigurationStatus_Rejected;
  13334. }
  13335. }
  13336. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13337. {
  13338. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13339. {
  13340. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13341. isSuccess = ConfigurationStatus_Accepted;
  13342. }
  13343. else
  13344. {
  13345. isSuccess = ConfigurationStatus_Rejected;
  13346. }
  13347. }
  13348. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13349. {
  13350. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13351. {
  13352. check_ascii = value[0];
  13353. if( (check_ascii < 48) || (check_ascii > 57) )
  13354. {
  13355. isSuccess = ConfigurationStatus_Rejected;
  13356. }
  13357. else
  13358. {
  13359. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13360. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13361. isSuccess = ConfigurationStatus_Accepted;
  13362. }
  13363. }
  13364. else
  13365. {
  13366. isSuccess = ConfigurationStatus_Rejected;
  13367. }
  13368. }
  13369. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13370. {
  13371. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13372. {
  13373. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13374. isSuccess = ConfigurationStatus_Accepted;
  13375. }
  13376. else
  13377. {
  13378. isSuccess = ConfigurationStatus_Rejected;
  13379. }
  13380. }
  13381. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13382. {
  13383. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13384. {
  13385. check_ascii = value[0];
  13386. if( (check_ascii < 48) || (check_ascii > 57) )
  13387. {
  13388. isSuccess = ConfigurationStatus_Rejected;
  13389. }
  13390. else
  13391. {
  13392. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13393. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13394. isSuccess = ConfigurationStatus_Accepted;
  13395. }
  13396. }
  13397. else
  13398. {
  13399. isSuccess = ConfigurationStatus_Rejected;
  13400. }
  13401. }
  13402. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13403. {
  13404. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13405. {
  13406. check_ascii = value[0];
  13407. if( (check_ascii < 48) || (check_ascii > 57) )
  13408. {
  13409. isSuccess = ConfigurationStatus_Rejected;
  13410. }
  13411. else
  13412. {
  13413. if((atoi(value) == 0) || (atoi(value) >= 10))
  13414. {
  13415. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13416. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13417. isSuccess = ConfigurationStatus_Accepted;
  13418. }
  13419. else
  13420. {
  13421. isSuccess = ConfigurationStatus_Rejected;
  13422. }
  13423. }
  13424. }
  13425. else
  13426. {
  13427. isSuccess = ConfigurationStatus_Rejected;
  13428. }
  13429. }
  13430. if(strcmp(key, "MinimumStatusDuration") == 0)
  13431. {
  13432. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13433. {
  13434. check_ascii = value[0];
  13435. if( (check_ascii < 48) || (check_ascii > 57) )
  13436. {
  13437. isSuccess = ConfigurationStatus_Rejected;
  13438. }
  13439. else
  13440. {
  13441. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13442. {
  13443. isSuccess = ConfigurationStatus_Rejected;
  13444. }
  13445. else
  13446. {
  13447. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13448. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13449. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13450. isSuccess = ConfigurationStatus_Accepted;
  13451. }
  13452. }
  13453. }
  13454. else
  13455. {
  13456. isSuccess = ConfigurationStatus_Rejected;
  13457. }
  13458. }
  13459. if(strcmp(key, "NumberOfConnectors") == 0)
  13460. {
  13461. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13462. {
  13463. check_ascii = value[0];
  13464. if( (check_ascii < 48) || (check_ascii > 57) )
  13465. {
  13466. isSuccess = ConfigurationStatus_Rejected;
  13467. }
  13468. else
  13469. {
  13470. //Charger.ResetRetries = Integer.parseInt(value);
  13471. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13472. isSuccess = ConfigurationStatus_Accepted;
  13473. }
  13474. }
  13475. else
  13476. {
  13477. isSuccess = ConfigurationStatus_Rejected;
  13478. }
  13479. }
  13480. if(strcmp(key, "ResetRetries") == 0)
  13481. {
  13482. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13483. {
  13484. check_ascii = value[0];
  13485. if( (check_ascii < 48) || (check_ascii > 57) )
  13486. {
  13487. isSuccess = ConfigurationStatus_Rejected;
  13488. }
  13489. else
  13490. {
  13491. //Charger.ResetRetries = Integer.parseInt(value);
  13492. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13493. isSuccess = ConfigurationStatus_Accepted;
  13494. }
  13495. }
  13496. else
  13497. {
  13498. isSuccess = ConfigurationStatus_Rejected;
  13499. }
  13500. }
  13501. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13502. {
  13503. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13504. {
  13505. strcpy(str, (const char*)value);
  13506. for(int i = 0; str[i]; i++)
  13507. {
  13508. str[i] = tolower(str[i]);
  13509. }
  13510. if(strcmp(str, "notapplicable")== 0)
  13511. {
  13512. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13513. isSuccess = ConfigurationStatus_Accepted;
  13514. }
  13515. else if(strcmp(str, "unknown")== 0)
  13516. {
  13517. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13518. isSuccess = ConfigurationStatus_Accepted;
  13519. }
  13520. else if(strcmp(str, "rst")== 0)
  13521. {
  13522. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13523. isSuccess = ConfigurationStatus_Accepted;
  13524. }
  13525. else if(strcmp(str, "rts")== 0)
  13526. {
  13527. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13528. isSuccess = ConfigurationStatus_Accepted;
  13529. }
  13530. else if(strcmp(str, "srt")== 0)
  13531. {
  13532. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13533. isSuccess = ConfigurationStatus_Accepted;
  13534. }
  13535. else if(strcmp(str, "str")== 0)
  13536. {
  13537. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13538. isSuccess = ConfigurationStatus_Accepted;
  13539. }
  13540. else if(strcmp(str, "trs")== 0)
  13541. {
  13542. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13543. isSuccess = ConfigurationStatus_Accepted;
  13544. }
  13545. else if(strcmp(str, "tsr")== 0)
  13546. {
  13547. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13548. isSuccess = ConfigurationStatus_Accepted;
  13549. }
  13550. else
  13551. {
  13552. isSuccess = ConfigurationStatus_Rejected;
  13553. }
  13554. }
  13555. else
  13556. {
  13557. isSuccess = ConfigurationStatus_Rejected;
  13558. }
  13559. }
  13560. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13561. {
  13562. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13563. {
  13564. check_ascii = value[0];
  13565. if( (check_ascii < 48) || (check_ascii > 57) )
  13566. {
  13567. isSuccess = ConfigurationStatus_Rejected;
  13568. }
  13569. else
  13570. {
  13571. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13572. isSuccess = ConfigurationStatus_Accepted;
  13573. }
  13574. }
  13575. else
  13576. {
  13577. isSuccess = ConfigurationStatus_Rejected;
  13578. }
  13579. }
  13580. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13581. {
  13582. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13583. {
  13584. strcpy(str, (const char*)value);
  13585. for(int i = 0; str[i]; i++)
  13586. {
  13587. str[i] = tolower(str[i]);
  13588. }
  13589. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13590. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13591. isSuccess = ConfigurationStatus_Accepted;
  13592. }
  13593. else
  13594. {
  13595. isSuccess = ConfigurationStatus_Rejected;
  13596. }
  13597. }
  13598. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13599. {
  13600. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13601. {
  13602. strcpy(str, (const char*)value);
  13603. for(int i = 0; str[i]; i++)
  13604. {
  13605. str[i] = tolower(str[i]);
  13606. }
  13607. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13608. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13609. isSuccess = ConfigurationStatus_Accepted;
  13610. }
  13611. else
  13612. {
  13613. isSuccess = ConfigurationStatus_Rejected;
  13614. }
  13615. }
  13616. if(strcmp(key, "StopTxnAlignedData") == 0)
  13617. {
  13618. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13619. {
  13620. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13621. isSuccess = ConfigurationStatus_Accepted;
  13622. }
  13623. else
  13624. {
  13625. isSuccess = ConfigurationStatus_Rejected;
  13626. }
  13627. }
  13628. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13629. {
  13630. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13631. {
  13632. check_ascii = value[0];
  13633. if( (check_ascii < 48) || (check_ascii > 57) )
  13634. {
  13635. isSuccess = ConfigurationStatus_Rejected;
  13636. }
  13637. else
  13638. {
  13639. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13640. isSuccess = ConfigurationStatus_Accepted;
  13641. }
  13642. }
  13643. else
  13644. {
  13645. isSuccess = ConfigurationStatus_Rejected;
  13646. }
  13647. }
  13648. if(strcmp(key, "StopTxnSampledData") == 0)
  13649. {
  13650. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13651. {
  13652. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13653. isSuccess = ConfigurationStatus_Accepted;
  13654. }
  13655. else
  13656. {
  13657. isSuccess = ConfigurationStatus_Rejected;
  13658. }
  13659. }
  13660. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13661. {
  13662. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13663. {
  13664. check_ascii = value[0];
  13665. if( (check_ascii < 48) || (check_ascii > 57) )
  13666. {
  13667. isSuccess = ConfigurationStatus_Rejected;
  13668. }
  13669. else
  13670. {
  13671. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13672. isSuccess = ConfigurationStatus_Accepted;
  13673. }
  13674. }
  13675. else
  13676. {
  13677. isSuccess = ConfigurationStatus_Rejected;
  13678. }
  13679. }
  13680. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13681. {
  13682. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13683. {
  13684. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13685. isSuccess = ConfigurationStatus_Accepted;
  13686. }
  13687. else
  13688. {
  13689. isSuccess = ConfigurationStatus_Rejected;
  13690. }
  13691. }
  13692. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13693. {
  13694. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13695. {
  13696. check_ascii = value[0];
  13697. if( (check_ascii < 48) || (check_ascii > 57) )
  13698. {
  13699. isSuccess = ConfigurationStatus_Rejected;
  13700. }
  13701. else
  13702. {
  13703. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13704. isSuccess = ConfigurationStatus_Accepted;
  13705. }
  13706. }
  13707. else
  13708. {
  13709. isSuccess = ConfigurationStatus_Rejected;
  13710. }
  13711. }
  13712. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13713. {
  13714. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13715. {
  13716. check_ascii = value[0];
  13717. if( (check_ascii < 48) || (check_ascii > 57) )
  13718. {
  13719. isSuccess = ConfigurationStatus_Rejected;
  13720. }
  13721. else
  13722. {
  13723. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13725. TransactionMessageAttemptsValue = atoi(value);
  13726. isSuccess = ConfigurationStatus_Accepted;
  13727. }
  13728. }
  13729. else
  13730. {
  13731. isSuccess = ConfigurationStatus_Rejected;
  13732. }
  13733. }
  13734. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13735. {
  13736. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13737. {
  13738. check_ascii = value[0];
  13739. if( (check_ascii < 48) || (check_ascii > 57) )
  13740. {
  13741. isSuccess = ConfigurationStatus_Rejected;
  13742. }
  13743. else
  13744. {
  13745. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13746. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13747. TransactionMessageRetryIntervalValue = atoi(value);
  13748. isSuccess = ConfigurationStatus_Accepted;
  13749. }
  13750. }
  13751. else
  13752. {
  13753. isSuccess = ConfigurationStatus_Rejected;
  13754. }
  13755. }
  13756. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13757. {
  13758. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13759. {
  13760. strcpy(str, (const char*)value);
  13761. for(int i = 0; str[i]; i++)
  13762. {
  13763. str[i] = tolower(str[i]);
  13764. }
  13765. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13766. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13767. isSuccess = ConfigurationStatus_Accepted;
  13768. }
  13769. else
  13770. {
  13771. isSuccess = ConfigurationStatus_Rejected;
  13772. }
  13773. }
  13774. if(strcmp(key, "WebSocketPingInterval") == 0)
  13775. {
  13776. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13777. {
  13778. check_ascii = value[0];
  13779. if( (check_ascii < 48) || (check_ascii > 57) )
  13780. {
  13781. isSuccess = ConfigurationStatus_Rejected;
  13782. }
  13783. else
  13784. {
  13785. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13786. isSuccess = ConfigurationStatus_Accepted;
  13787. }
  13788. }
  13789. else
  13790. {
  13791. isSuccess = ConfigurationStatus_Rejected;
  13792. }
  13793. }
  13794. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13795. {
  13796. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13797. {
  13798. strcpy(str, (const char*)value);
  13799. for(int i = 0; str[i]; i++)
  13800. {
  13801. str[i] = tolower(str[i]);
  13802. }
  13803. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13804. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13805. isSuccess = ConfigurationStatus_Accepted;
  13806. }
  13807. else
  13808. {
  13809. isSuccess = ConfigurationStatus_Rejected;
  13810. }
  13811. }
  13812. if(strcmp(key, "AuthorizationKey") == 0)
  13813. {
  13814. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13815. {
  13816. strcpy(str, (const char*)value);
  13817. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13818. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13819. isSuccess = ConfigurationStatus_Accepted;
  13820. }
  13821. else
  13822. {
  13823. isSuccess = ConfigurationStatus_Rejected;
  13824. }
  13825. }
  13826. if(strcmp(key, "SecurityProfile") == 0)
  13827. {
  13828. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13829. {
  13830. check_ascii = value[0];
  13831. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13832. {
  13833. isSuccess = ConfigurationStatus_Rejected;
  13834. }
  13835. else if(check_ascii == 0x33)
  13836. {
  13837. isSuccess = NotSupported;
  13838. }
  13839. else
  13840. {
  13841. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13842. {
  13843. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13844. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  13845. isSuccess = ConfigurationStatus_Accepted;
  13846. }
  13847. else
  13848. isSuccess = ConfigurationStatus_Rejected;
  13849. }
  13850. }
  13851. else
  13852. {
  13853. isSuccess = ConfigurationStatus_Rejected;
  13854. }
  13855. }
  13856. if(strcmp(key, "DefaultPrice") == 0)
  13857. {
  13858. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13859. {
  13860. strcpy(str, (const char*)value);
  13861. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13862. isSuccess = ConfigurationStatus_Accepted;
  13863. }
  13864. else
  13865. {
  13866. isSuccess = ConfigurationStatus_Rejected;
  13867. }
  13868. }
  13869. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13870. {
  13871. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13872. {
  13873. strcpy(str, (const char*)value);
  13874. for(int i = 0; str[i]; i++)
  13875. {
  13876. str[i] = tolower(str[i]);
  13877. }
  13878. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13879. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13880. isSuccess = ConfigurationStatus_Accepted;
  13881. }
  13882. else
  13883. {
  13884. isSuccess = ConfigurationStatus_Rejected;
  13885. }
  13886. }
  13887. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13888. {
  13889. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13890. {
  13891. strcpy(str, (const char*)value);
  13892. for(int i = 0; str[i]; i++)
  13893. {
  13894. str[i] = tolower(str[i]);
  13895. }
  13896. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13897. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13898. isSuccess = ConfigurationStatus_Accepted;
  13899. }
  13900. else
  13901. {
  13902. isSuccess = ConfigurationStatus_Rejected;
  13903. }
  13904. }
  13905. #if 0
  13906. //For OCPP Test Case
  13907. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13908. {
  13909. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13910. {
  13911. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13912. isSuccess = ConfigurationStatus_Accepted;
  13913. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13914. }
  13915. else
  13916. {
  13917. isSuccess = ConfigurationStatus_Rejected;
  13918. }
  13919. }
  13920. #endif
  13921. #if 1
  13922. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13923. {
  13924. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13925. {
  13926. strcpy(str, (const char*)value);
  13927. for(int i = 0; str[i]; i++)
  13928. {
  13929. str[i] = tolower(str[i]);
  13930. }
  13931. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13932. isSuccess = ConfigurationStatus_Accepted;
  13933. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13934. }
  13935. else
  13936. {
  13937. isSuccess = ConfigurationStatus_Rejected;
  13938. }
  13939. }
  13940. #endif
  13941. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13942. {
  13943. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13944. {
  13945. check_ascii = value[0];
  13946. if( (check_ascii < 48) || (check_ascii > 57) )
  13947. {
  13948. isSuccess = ConfigurationStatus_Rejected;
  13949. }
  13950. else
  13951. {
  13952. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13953. isSuccess = ConfigurationStatus_Accepted;
  13954. }
  13955. }
  13956. else
  13957. {
  13958. isSuccess = ConfigurationStatus_Rejected;
  13959. }
  13960. }
  13961. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13962. {
  13963. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13964. {
  13965. check_ascii = value[0];
  13966. if( (check_ascii < 48) || (check_ascii > 57) )
  13967. {
  13968. isSuccess = ConfigurationStatus_Rejected;
  13969. }
  13970. else
  13971. {
  13972. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13973. isSuccess = ConfigurationStatus_Accepted;
  13974. }
  13975. }
  13976. else
  13977. {
  13978. isSuccess = ConfigurationStatus_Rejected;
  13979. }
  13980. }
  13981. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13982. {
  13983. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13984. {
  13985. strcpy(str, (const char*)value);
  13986. for(int i = 0; str[i]; i++)
  13987. {
  13988. str[i] = tolower(str[i]);
  13989. }
  13990. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13991. isSuccess = ConfigurationStatus_Accepted;
  13992. }
  13993. else
  13994. {
  13995. isSuccess = ConfigurationStatus_Rejected;
  13996. }
  13997. }
  13998. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13999. {
  14000. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14001. {
  14002. check_ascii = value[0];
  14003. if( (check_ascii < 48) || (check_ascii > 57) )
  14004. {
  14005. isSuccess = ConfigurationStatus_Rejected;
  14006. }
  14007. else
  14008. {
  14009. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14010. isSuccess = ConfigurationStatus_Accepted;
  14011. }
  14012. }
  14013. else
  14014. {
  14015. isSuccess = ConfigurationStatus_Rejected;
  14016. }
  14017. }
  14018. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14019. {
  14020. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14021. {
  14022. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14023. isSuccess = ConfigurationStatus_Accepted;
  14024. }
  14025. else
  14026. {
  14027. isSuccess = ConfigurationStatus_Rejected;
  14028. }
  14029. }
  14030. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14031. {
  14032. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14033. {
  14034. check_ascii = value[0];
  14035. if( (check_ascii < 48) || (check_ascii > 57) )
  14036. {
  14037. isSuccess = ConfigurationStatus_Rejected;
  14038. }
  14039. else
  14040. {
  14041. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14042. isSuccess = ConfigurationStatus_Accepted;
  14043. }
  14044. }
  14045. else
  14046. {
  14047. isSuccess = ConfigurationStatus_Rejected;
  14048. }
  14049. }
  14050. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14051. {
  14052. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14053. {
  14054. strcpy(str, (const char*)value);
  14055. for(int i = 0; str[i]; i++)
  14056. {
  14057. str[i] = tolower(str[i]);
  14058. }
  14059. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14060. isSuccess = ConfigurationStatus_Accepted;
  14061. }
  14062. else
  14063. {
  14064. isSuccess = ConfigurationStatus_Rejected;
  14065. }
  14066. }
  14067. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14068. {
  14069. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14070. {
  14071. check_ascii = value[0];
  14072. if( (check_ascii < 48) || (check_ascii > 57) )
  14073. {
  14074. isSuccess = ConfigurationStatus_Rejected;
  14075. }
  14076. else
  14077. {
  14078. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14079. isSuccess = ConfigurationStatus_Accepted;
  14080. }
  14081. }
  14082. else
  14083. {
  14084. isSuccess = ConfigurationStatus_Rejected;
  14085. }
  14086. }
  14087. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14088. return isSuccess;
  14089. }
  14090. int TransactionMessageAttemptsGet(void)
  14091. {
  14092. return TransactionMessageAttemptsValue;
  14093. }
  14094. int FirstHeartBeatResponse(void)
  14095. {
  14096. return FirstHeartBeat;
  14097. }
  14098. int TransactionMessageRetryIntervalGet(void)
  14099. {
  14100. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14101. }
  14102. int ReadHttpStatus(int sock)
  14103. {
  14104. //char c;
  14105. char buff[1024]="",*ptr=buff+1;
  14106. int bytes_received, status;
  14107. DEBUG_INFO("Begin Response ..\n");
  14108. while((bytes_received = recv(sock, ptr, 1, 0))){
  14109. if(bytes_received==-1){
  14110. perror("ReadHttpStatus");
  14111. exit(1);
  14112. }
  14113. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14114. ptr++;
  14115. }
  14116. *ptr=0;
  14117. ptr=buff+1;
  14118. sscanf(ptr,"%*s %d ", &status);
  14119. DEBUG_INFO("%s\n",ptr);
  14120. DEBUG_INFO("status=%d\n",status);
  14121. DEBUG_INFO("End Response ..\n");
  14122. return (bytes_received>0)?status:0;
  14123. }
  14124. //the only filed that it parsed is 'Content-Length'
  14125. int ParseHeader(int sock)
  14126. {
  14127. //char c;
  14128. char buff[1024]="",*ptr=buff+4;
  14129. int bytes_received;
  14130. DEBUG_INFO("Begin HEADER ..\n");
  14131. while((bytes_received = recv(sock, ptr, 1, 0))){
  14132. if(bytes_received==-1){
  14133. perror("Parse Header");
  14134. exit(1);
  14135. }
  14136. if(
  14137. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14138. (ptr[-1]=='\r') && (*ptr=='\n' )
  14139. ) break;
  14140. ptr++;
  14141. }
  14142. *ptr=0;
  14143. ptr=buff+4;
  14144. //printf("%s",ptr);
  14145. if(bytes_received){
  14146. ptr=strstr(ptr,"Content-Length:");
  14147. if(ptr){
  14148. sscanf(ptr,"%*s %d",&bytes_received);
  14149. }else
  14150. bytes_received=-1; //unknown size
  14151. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14152. }
  14153. DEBUG_INFO("End HEADER ..\n");
  14154. return bytes_received ;
  14155. }
  14156. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14157. {
  14158. int result = TRUE;
  14159. char rmFileCmd[100]={0};
  14160. char FilePath[100]={0};
  14161. char ftpbuf[200];
  14162. int systemresult;
  14163. //DEBUG_INFO("filename=%s\n",filename);
  14164. //DEBUG_INFO("url=%s\n",url);
  14165. sprintf(FilePath,"/mnt/%s",filename);
  14166. system("ping 8.8.8.8 &");
  14167. if((access(FilePath,F_OK))!=-1)
  14168. {
  14169. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14170. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14171. system(rmFileCmd);
  14172. }
  14173. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14174. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14175. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14176. systemresult = system(ftpbuf);
  14177. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14178. if(systemresult != 0)
  14179. {
  14180. DEBUG_INFO("http DownLoad error!\n");
  14181. result = FALSE;
  14182. }
  14183. system("pkill ping");
  14184. return result;
  14185. }
  14186. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14187. {
  14188. int result = TRUE;
  14189. char rmFileCmd[100]={0};
  14190. char FilePath[100]={0};
  14191. char ftpbuf[200];
  14192. int systemresult;
  14193. //char temp[100];
  14194. sprintf(FilePath,"/mnt/%s",filename);
  14195. system("ping 8.8.8.8 &");
  14196. if((access(FilePath,F_OK))!=-1)
  14197. {
  14198. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14199. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14200. system(rmFileCmd);
  14201. }
  14202. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14203. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14204. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14205. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14206. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14207. systemresult = system(ftpbuf);
  14208. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14209. if(systemresult != 0)
  14210. {
  14211. printf("wget error!\n");
  14212. result = FALSE;
  14213. }
  14214. system("pkill ping");
  14215. return result;
  14216. }
  14217. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14218. {
  14219. char rmFileCmd[100]={0};
  14220. char FilePath[100]={0};
  14221. char buf[512];
  14222. int systemresult = 0;
  14223. //DEBUG_INFO("filename=%s\n",filename);
  14224. //DEBUG_INFO("url=%s\n",url);
  14225. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14226. if((access(FilePath,F_OK))!=-1)
  14227. {
  14228. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14229. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14230. system(rmFileCmd);
  14231. }
  14232. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14233. if(fp == NULL)
  14234. {
  14235. DEBUG_INFO("log is NULL\n");
  14236. return FALSE;
  14237. }
  14238. else
  14239. {
  14240. fprintf(fp, "%s\n", url);
  14241. fprintf(fp, "%s\n", filename);
  14242. fclose(fp);
  14243. }
  14244. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14245. if(phpFP == NULL)
  14246. {
  14247. DEBUG_INFO("PHP upload fail.\n");
  14248. return FALSE;
  14249. }
  14250. else
  14251. {
  14252. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14253. {
  14254. if(strstr(buf, "result") != NULL)
  14255. {
  14256. sscanf(buf, "result: %d", &systemresult);
  14257. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14258. }
  14259. }
  14260. pclose(phpFP);
  14261. }
  14262. if(systemresult != 1)
  14263. {
  14264. DEBUG_INFO("HTTP upload error!\n");
  14265. return FALSE;
  14266. }
  14267. return TRUE;
  14268. }
  14269. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14270. {
  14271. struct hostent* server;
  14272. char *IPbuffer;
  14273. char ftpbuf[200];
  14274. int systemresult;
  14275. // To retrieve host information
  14276. server = gethostbyname(location);
  14277. // To convert an Internet network
  14278. // address into ASCII string
  14279. IPbuffer = inet_ntoa(*((struct in_addr*)
  14280. server->h_addr_list[0]));
  14281. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14282. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14283. /* format : ftpput -u username -p passwd IP target source*/
  14284. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14285. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14286. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14287. systemresult = system(ftpbuf);
  14288. DEBUG_INFO("systemresult=%d\n",systemresult);
  14289. if(systemresult != 0)
  14290. {
  14291. DEBUG_INFO("ftpput error!\n");
  14292. return FALSE;
  14293. }
  14294. return TRUE;
  14295. }
  14296. int GetOcppServerURL()
  14297. {
  14298. int result = FALSE;
  14299. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14300. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14301. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14302. struct yuarel url;
  14303. char urlStr[512];
  14304. // OCPPPH only
  14305. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  14306. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14307. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  14308. {
  14309. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  14310. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14311. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14312. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  14313. if(yuarel_parse(&url, urlStr) != -1)
  14314. {
  14315. sprintf(OcppProtocol, "%s", url.scheme);
  14316. sprintf(OcppHost, "%s", url.host);
  14317. if(url.path == NULL)
  14318. OcppTempPath[0] = '\0';
  14319. else
  14320. sprintf(OcppTempPath, "%s", url.path);
  14321. if(url.port == 0)
  14322. {
  14323. if(strcmp(OcppProtocol, "wss") == 0)
  14324. OcppPort = 443;
  14325. else
  14326. OcppPort = 80;
  14327. }
  14328. else
  14329. OcppPort = url.port;
  14330. result = TRUE;
  14331. }
  14332. }
  14333. else
  14334. {
  14335. strcpy(OcppHost,"");
  14336. }
  14337. return result;
  14338. }
  14339. int GetOcppPath()
  14340. {
  14341. int result = FALSE;
  14342. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  14343. {
  14344. if(OcppTempPath == NULL)
  14345. {
  14346. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  14347. }
  14348. else
  14349. {
  14350. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  14351. }
  14352. result = TRUE;
  14353. goto End;
  14354. }
  14355. else
  14356. {
  14357. strcpy(OcppPath,"");
  14358. }
  14359. End:
  14360. return result;
  14361. }
  14362. int GetOcppPort()
  14363. {
  14364. return OcppPort;
  14365. }
  14366. int GetOcppConnStatus(void)
  14367. {
  14368. return ShmOCPP16DataPH->OcppConnStatus;
  14369. }
  14370. void SetOcppConnStatus(uint8_t status)
  14371. {
  14372. ShmOCPP16DataPH->OcppConnStatus = status;
  14373. }
  14374. int GetHeartBeatWithNOResponse(void)
  14375. {
  14376. return HeartBeatWithNOResponse;
  14377. }
  14378. void SetHeartBeatWithNOResponse(void)
  14379. {
  14380. HeartBeatWithNOResponse = 0;
  14381. }
  14382. void GetStartTransactionIdTag(int gun_index)
  14383. {
  14384. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14385. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14386. }
  14387. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14388. {
  14389. char ch;
  14390. FILE *fptr1;
  14391. int temptransactionId;
  14392. char str[100]={0};
  14393. temptransactionId = 0;
  14394. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14395. {
  14396. DEBUG_INFO("IdTag is empty.\n");
  14397. return temptransactionId;
  14398. }
  14399. /*------ Read the file ----------------*/
  14400. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  14401. if (!fptr1)
  14402. {
  14403. DEBUG_INFO("QueueTransactionId file open error.\n");
  14404. //printf(" File not found or unable to open the input file!!\n");
  14405. return temptransactionId;
  14406. }
  14407. ch=fgetc(fptr1);
  14408. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  14409. rewind(fptr1);
  14410. if(ch!=EOF)
  14411. {
  14412. // printf("%c",ch);
  14413. while (fgets(str, 100, fptr1) != NULL)
  14414. {
  14415. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14416. if(str[0]=='\0')
  14417. {
  14418. break;
  14419. }
  14420. char *revbuf[8] = {0}; // Variable store string split
  14421. int num = 0;// Quantity after string split
  14422. DEBUG_INFO("Transaction queue data= %s\n", str);
  14423. splitstring(str,",",revbuf,&num); // String split
  14424. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14425. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14426. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14427. DEBUG_INFO("------------------------------\n");
  14428. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14429. {
  14430. if(isStopTransaction)
  14431. {
  14432. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14433. {
  14434. temptransactionId = atoi(revbuf[2]);
  14435. //break;
  14436. }
  14437. }
  14438. else
  14439. {
  14440. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14441. {
  14442. temptransactionId = atoi(revbuf[2]);
  14443. //break;
  14444. }
  14445. }
  14446. }
  14447. }
  14448. }
  14449. else
  14450. DEBUG_INFO("EOF\n");
  14451. fclose(fptr1);
  14452. /*------- End of reading ---------------*/
  14453. return temptransactionId;
  14454. }
  14455. void SetTransactionIdZero(int transactionId)
  14456. {
  14457. char ch;
  14458. FILE *fptr1, *fptr2;
  14459. int temptransactionId = 0;
  14460. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  14461. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  14462. if (!fptr1)
  14463. {
  14464. //printf(" File not found or unable to open the input file!!\n");
  14465. return ;
  14466. }
  14467. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14468. if (!fptr2)
  14469. {
  14470. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14471. fclose(fptr1);
  14472. return ;
  14473. }
  14474. ch=fgetc(fptr1);
  14475. rewind(fptr1);
  14476. if(ch!=EOF)
  14477. {
  14478. // copy all contents to the temporary file except the specific line
  14479. while (fgets(str, 100, fptr1) != NULL)
  14480. {
  14481. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14482. if(str[0]=='\0')
  14483. {
  14484. break;
  14485. }
  14486. char *revbuf[8] = {0};
  14487. int num = 0;
  14488. strcpy(strtemp, str);
  14489. splitstring(str,",",revbuf,&num);
  14490. if(revbuf[2][0] != '\0')
  14491. {
  14492. temptransactionId = atoi(revbuf[2]);
  14493. if(transactionId != temptransactionId)
  14494. {
  14495. fprintf(fptr2, "%s\n", strtemp);
  14496. }
  14497. }
  14498. }
  14499. }
  14500. fclose(fptr1);
  14501. fclose(fptr2);
  14502. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  14503. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  14504. /*------ Read the file ----------------*/
  14505. }
  14506. int InternetDisconnect(void)
  14507. {
  14508. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14509. }
  14510. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14511. void storeTempStopTransaction(int gun_index)
  14512. {
  14513. char guid[37]={0};
  14514. int tempIndex = 0;
  14515. char TempStopTransaction[256];
  14516. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  14517. DEBUG_INFO("storeTempStopTransaction...\n");
  14518. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14519. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  14520. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14521. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14522. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14523. {
  14524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14525. {
  14526. tempIndex = ((gun_index==2) ? 1: 0);
  14527. }
  14528. else
  14529. {
  14530. tempIndex = gun_index;
  14531. }
  14532. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14533. {
  14534. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14535. {
  14536. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14537. }
  14538. }// END OF CHAdeMO_QUANTITY
  14539. }
  14540. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14541. {
  14542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14543. {
  14544. tempIndex = ((gun_index==2) ? 1: 0);
  14545. }
  14546. else
  14547. {
  14548. tempIndex = gun_index;
  14549. }
  14550. for (int index = 0; index < CCS_QUANTITY; index++)
  14551. {
  14552. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14553. {
  14554. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14555. }
  14556. }// END OF CCS_QUANTITY
  14557. }
  14558. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14559. {
  14560. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14561. {
  14562. tempIndex = ((gun_index==2) ? 1: 0);
  14563. }
  14564. else
  14565. {
  14566. tempIndex = gun_index;
  14567. }
  14568. for (int index = 0; index < GB_QUANTITY; index++)
  14569. {
  14570. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14571. {
  14572. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14573. }
  14574. }// END OF GB_QUANTITY
  14575. }
  14576. else if(gunType[gun_index] == GUN_TYPE_DO)
  14577. {
  14578. tempIndex = gun_index;
  14579. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14580. {
  14581. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14582. {
  14583. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14584. }
  14585. }
  14586. }
  14587. else
  14588. {
  14589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14590. {
  14591. tempIndex = 2;
  14592. }
  14593. else
  14594. {
  14595. tempIndex = gun_index;
  14596. }
  14597. for (int index = 0; index < AC_QUANTITY; index++)
  14598. {
  14599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14600. {
  14601. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14602. }
  14603. }// END OF AC_QUANTITY
  14604. }
  14605. //Stop Transaction Time
  14606. struct timeval tmnow;
  14607. struct tm *tm;
  14608. char buf[28];//, usec_buf[6];
  14609. gettimeofday(&tmnow, NULL);
  14610. time_t t;
  14611. t = time(NULL);
  14612. /*UTC time and date*/
  14613. tm = gmtime(&t);
  14614. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14615. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  14616. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  14617. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14618. random_uuid(guid);
  14619. /***********************************transactionData******************************************************/
  14620. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14622. //=================================
  14623. //1. Transaction_Begin
  14624. //=================================
  14625. //============================== Energy.Active.Import.Interval ===========================================
  14626. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14627. {
  14628. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14631. 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*/]);
  14632. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14633. 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))
  14634. {
  14635. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14636. }
  14637. else
  14638. {
  14639. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14640. }
  14641. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14642. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14643. }
  14644. //=================================
  14645. //2. Transaction_End
  14646. //=================================
  14647. //2.1====================================== Current.Import L1 ==============================================
  14648. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14649. {
  14650. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14651. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14652. {
  14653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14654. {
  14655. tempIndex = ((gun_index==2) ? 1: 0);
  14656. }
  14657. else
  14658. {
  14659. tempIndex = gun_index;
  14660. }
  14661. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14662. {
  14663. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14664. {
  14665. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14666. }
  14667. }// End of for CHAdeMO_QUANTITY
  14668. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14669. }
  14670. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14671. {
  14672. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14673. {
  14674. tempIndex = ((gun_index==2) ? 1: 0);
  14675. }
  14676. else
  14677. {
  14678. tempIndex = gun_index;
  14679. }
  14680. for (int index = 0; index < CCS_QUANTITY; index++)
  14681. {
  14682. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14683. {
  14684. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14685. }
  14686. }// End of for CCS_QUANTITY
  14687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14688. }
  14689. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14690. {
  14691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14692. {
  14693. tempIndex = ((gun_index==2) ? 1: 0);
  14694. }
  14695. else
  14696. {
  14697. tempIndex = gun_index;
  14698. }
  14699. for (int index = 0; index < GB_QUANTITY; index++)
  14700. {
  14701. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14702. {
  14703. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14704. }
  14705. }// End of for GB_QUANTITY
  14706. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14707. }
  14708. else if(gunType[gun_index] == GUN_TYPE_DO)
  14709. {
  14710. tempIndex = gun_index;
  14711. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14712. {
  14713. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14714. {
  14715. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14716. }
  14717. }
  14718. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14719. }
  14720. else
  14721. {
  14722. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14723. {
  14724. tempIndex = 2;
  14725. }
  14726. else
  14727. {
  14728. tempIndex = gun_index;
  14729. }
  14730. for (int index = 0; index < AC_QUANTITY; index++)
  14731. {
  14732. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14733. {
  14734. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14735. }
  14736. }// End of for AC_QUANTITY
  14737. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14738. }
  14739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14742. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14744. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14745. }
  14746. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14747. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14748. {
  14749. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14750. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14751. {
  14752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14753. {
  14754. tempIndex = ((gun_index==2) ? 1: 0);
  14755. }
  14756. else
  14757. {
  14758. tempIndex = gun_index;
  14759. }
  14760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14761. {
  14762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14763. {
  14764. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14765. }
  14766. }// END OF CHAdeMO_QUANTITY
  14767. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14768. }
  14769. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14770. {
  14771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14772. {
  14773. tempIndex = ((gun_index==2) ? 1: 0);
  14774. }
  14775. else
  14776. {
  14777. tempIndex = gun_index;
  14778. }
  14779. for (int index = 0; index < CCS_QUANTITY; index++)
  14780. {
  14781. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14782. {
  14783. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14784. }
  14785. }// END OF CCS_QUANTITY
  14786. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14787. }
  14788. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14789. {
  14790. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14791. {
  14792. tempIndex = ((gun_index==2) ? 1: 0);
  14793. }
  14794. else
  14795. {
  14796. tempIndex = gun_index;
  14797. }
  14798. for (int index = 0; index < GB_QUANTITY; index++)
  14799. {
  14800. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14801. {
  14802. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14803. }
  14804. }// END OF GB_QUANTITY
  14805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14806. }
  14807. else if(gunType[gun_index] == GUN_TYPE_DO)
  14808. {
  14809. tempIndex = gun_index;
  14810. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14811. {
  14812. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14813. {
  14814. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14815. }
  14816. }
  14817. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14818. }
  14819. else
  14820. {
  14821. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14822. {
  14823. tempIndex = 2;
  14824. }
  14825. else
  14826. {
  14827. tempIndex = gun_index;
  14828. }
  14829. for (int index = 0; index < AC_QUANTITY; index++)
  14830. {
  14831. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14832. {
  14833. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14834. }
  14835. }// END OF AC_QUANTITY
  14836. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14837. }
  14838. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14839. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14840. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14841. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14842. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14843. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14844. }
  14845. //2.3====================================== Power.Active.Import =========================================
  14846. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14847. {
  14848. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14849. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14850. {
  14851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14852. {
  14853. tempIndex = ((gun_index==2) ? 1: 0);
  14854. }
  14855. else
  14856. {
  14857. tempIndex = gun_index;
  14858. }
  14859. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14860. {
  14861. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14862. {
  14863. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14864. }
  14865. } // End for CHAdeMO_QUANTITY
  14866. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14867. }
  14868. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14869. {
  14870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14871. {
  14872. tempIndex = ((gun_index==2) ? 1: 0);
  14873. }
  14874. else
  14875. {
  14876. tempIndex = gun_index;
  14877. }
  14878. for (int index = 0; index < CCS_QUANTITY; index++)
  14879. {
  14880. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14881. {
  14882. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14883. }
  14884. } // END for CCS_QUANTITY
  14885. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14886. }
  14887. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14888. {
  14889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14890. {
  14891. tempIndex = ((gun_index==2) ? 1: 0);
  14892. }
  14893. else
  14894. {
  14895. tempIndex = gun_index;
  14896. }
  14897. for (int index = 0; index < GB_QUANTITY; index++)
  14898. {
  14899. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14900. {
  14901. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14902. }
  14903. }// END for GB_QUANTITY
  14904. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14905. }
  14906. else if(gunType[gun_index] == GUN_TYPE_DO)
  14907. {
  14908. tempIndex = gun_index;
  14909. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14910. {
  14911. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14912. {
  14913. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14914. }
  14915. }
  14916. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14917. }
  14918. else
  14919. {
  14920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14921. {
  14922. tempIndex = 2;
  14923. }
  14924. else
  14925. {
  14926. tempIndex = gun_index;
  14927. }
  14928. for (int index = 0; index < AC_QUANTITY; index++)
  14929. {
  14930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14931. {
  14932. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14933. }
  14934. } // END for AC_QUANTITY
  14935. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14936. }
  14937. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14938. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14939. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14940. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14941. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14942. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14943. }
  14944. //2.4====================================== Voltage L1 ====================================================
  14945. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14946. {
  14947. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14948. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14949. {
  14950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14951. {
  14952. tempIndex = ((gun_index==2) ? 1: 0);
  14953. }
  14954. else
  14955. {
  14956. tempIndex = gun_index;
  14957. }
  14958. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14959. {
  14960. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14961. {
  14962. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14963. }
  14964. } // END OF FOR CHAdeMO_QUANTITY
  14965. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14966. }
  14967. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14968. {
  14969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14970. {
  14971. tempIndex = ((gun_index==2) ? 1: 0);
  14972. }
  14973. else
  14974. {
  14975. tempIndex = gun_index;
  14976. }
  14977. for (int index = 0; index < CCS_QUANTITY; index++)
  14978. {
  14979. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14980. {
  14981. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14982. }
  14983. } // END OF FOR CCS_QUANTITY
  14984. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14985. }
  14986. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14987. {
  14988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14989. {
  14990. tempIndex = ((gun_index==2) ? 1: 0);
  14991. }
  14992. else
  14993. {
  14994. tempIndex = gun_index;
  14995. }
  14996. for (int index = 0; index < GB_QUANTITY; index++)
  14997. {
  14998. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14999. {
  15000. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15001. }
  15002. } // END OF FOR GB_QUANTITY
  15003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15004. }
  15005. else if(gunType[gun_index] == GUN_TYPE_DO)
  15006. {
  15007. tempIndex = gun_index;
  15008. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15009. {
  15010. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15011. {
  15012. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15013. }
  15014. }
  15015. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15016. }
  15017. else
  15018. {
  15019. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15020. {
  15021. tempIndex = 2;
  15022. }
  15023. else
  15024. {
  15025. tempIndex = gun_index;
  15026. }
  15027. for (int index = 0; index < AC_QUANTITY; index++)
  15028. {
  15029. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15030. {
  15031. 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
  15032. }
  15033. } // END OF FOR AC_QUANTITY
  15034. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15035. }
  15036. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15037. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15038. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15039. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15040. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15041. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15042. }
  15043. //2.5============================================== End SoC =========================================================
  15044. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15045. {
  15046. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15047. 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))
  15048. {
  15049. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15050. {
  15051. tempIndex = ((gun_index==2) ? 1: 0);
  15052. }
  15053. else
  15054. {
  15055. tempIndex = gun_index;
  15056. }
  15057. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15058. {
  15059. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15060. {
  15061. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15062. {
  15063. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15064. }
  15065. }
  15066. }
  15067. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15068. {
  15069. for (int index = 0; index < CCS_QUANTITY; index++)
  15070. {
  15071. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15072. {
  15073. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15074. }
  15075. }
  15076. }
  15077. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15078. {
  15079. for (int index = 0; index < GB_QUANTITY; index++)
  15080. {
  15081. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15082. {
  15083. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15084. }
  15085. }
  15086. }
  15087. else if(gunType[gun_index] == GUN_TYPE_DO)
  15088. {
  15089. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15090. {
  15091. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15092. {
  15093. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15094. }
  15095. }
  15096. }
  15097. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15098. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15099. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15100. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15101. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15102. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15103. } // END FOR DC CASE
  15104. }
  15105. //2.6====================================== Current.Import L2 ==============================================
  15106. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15107. {
  15108. // AC 3 phase L2 current
  15109. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15110. {
  15111. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15112. {
  15113. tempIndex = 2;
  15114. }
  15115. else
  15116. {
  15117. tempIndex = gun_index;
  15118. }
  15119. for (int index = 0; index < AC_QUANTITY; index++)
  15120. {
  15121. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15122. {
  15123. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15124. }
  15125. }// End of for AC_QUANTITY
  15126. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15127. }
  15128. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15129. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15130. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15131. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15132. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15133. }
  15134. //2.7====================================== Current.Import L3 ==============================================
  15135. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15136. {
  15137. // AC 3 phase L3 current
  15138. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15139. {
  15140. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15141. {
  15142. tempIndex = 2;
  15143. }
  15144. else
  15145. {
  15146. tempIndex = gun_index;
  15147. }
  15148. for (int index = 0; index < AC_QUANTITY; index++)
  15149. {
  15150. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15151. {
  15152. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15153. }
  15154. }// End of for AC_QUANTITY
  15155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15156. }
  15157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15158. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15160. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15161. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15162. }
  15163. //2.9====================================== Voltage L2 ====================================================
  15164. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15165. {
  15166. // AC 3 phase L2 volatge
  15167. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15168. {
  15169. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15170. {
  15171. tempIndex = 2;
  15172. }
  15173. else
  15174. {
  15175. tempIndex = gun_index;
  15176. }
  15177. for (int index = 0; index < AC_QUANTITY; index++)
  15178. {
  15179. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15180. {
  15181. 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
  15182. }
  15183. } // END OF FOR AC_QUANTITY
  15184. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15185. }
  15186. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15187. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15188. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15189. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15190. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15191. }
  15192. //2.10====================================== Voltage L3 ====================================================
  15193. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15194. {
  15195. // AC 3 phase L3 volatge
  15196. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15197. {
  15198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15199. {
  15200. tempIndex = 2;
  15201. }
  15202. else
  15203. {
  15204. tempIndex = gun_index;
  15205. }
  15206. for (int index = 0; index < AC_QUANTITY; index++)
  15207. {
  15208. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15209. {
  15210. 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
  15211. }
  15212. } // END OF FOR AC_QUANTITY
  15213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15214. }
  15215. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15216. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15217. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15220. }
  15221. //====================== Start SoC ================================
  15222. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15223. {
  15224. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15225. 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))
  15226. {
  15227. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15228. {
  15229. tempIndex = ((gun_index==2) ? 1: 0);
  15230. }
  15231. else
  15232. {
  15233. tempIndex = gun_index;
  15234. }
  15235. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15236. {
  15237. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15238. {
  15239. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15240. {
  15241. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15242. }
  15243. }
  15244. }
  15245. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15246. {
  15247. for (int index = 0; index < CCS_QUANTITY; index++)
  15248. {
  15249. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15250. {
  15251. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15252. }
  15253. }
  15254. }
  15255. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15256. {
  15257. for (int index = 0; index < GB_QUANTITY; index++)
  15258. {
  15259. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15260. {
  15261. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15262. }
  15263. }
  15264. }
  15265. else if(gunType[gun_index] == GUN_TYPE_DO)
  15266. {
  15267. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15268. {
  15269. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15270. {
  15271. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15272. }
  15273. }
  15274. }
  15275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15277. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15280. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15281. } // END FOR DC CASE
  15282. }
  15283. //======================================== Message create ==============================================
  15284. json_object *StopTransaction = json_object_new_object();
  15285. json_object *transactionDatas = json_object_new_array();
  15286. json_object *sampledValues = json_object_new_array();
  15287. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  15288. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  15289. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  15290. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  15291. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  15292. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15293. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  15294. {
  15295. json_object *transactionData = json_object_new_object();
  15296. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15297. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15298. {
  15299. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15300. {
  15301. json_object *sampledValue = json_object_new_object();
  15302. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15303. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15304. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15305. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15306. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15307. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15308. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15309. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15310. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15311. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15312. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15313. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15314. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15315. json_object_array_add(sampledValues, sampledValue);
  15316. }
  15317. }
  15318. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15319. json_object_array_add(transactionDatas, transactionData);
  15320. }
  15321. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15322. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15323. ,MESSAGE_TYPE_CALL
  15324. ,guid
  15325. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15326. json_object_put(StopTransaction);
  15327. // Check File "TempStopTransaction" Exist
  15328. if((access(TempStopTransaction,F_OK))!=-1)
  15329. {
  15330. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15331. fclose(fopen(TempStopTransaction, "w"));
  15332. }
  15333. else
  15334. {
  15335. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15336. FILE *log = fopen(TempStopTransaction, "w+");
  15337. if(log == NULL)
  15338. {
  15339. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15340. return ;
  15341. }
  15342. else
  15343. {
  15344. fclose(log);
  15345. }
  15346. }
  15347. //Add TempStopTransaction | Update TempStopTransaction
  15348. // open file for writing
  15349. FILE *outfile;
  15350. outfile = fopen (TempStopTransaction, "a");
  15351. //DEBUG_INFO("data = %s\n", queuedata);
  15352. fputs(queuedata, outfile);
  15353. fputs("\n", outfile);
  15354. fclose (outfile);
  15355. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15356. }
  15357. void checkTempStopTransaction(int gun_index)
  15358. {
  15359. FILE *fptr1;
  15360. char ch;
  15361. char str[QUEUE_MESSAGE_LENGTH]={0};
  15362. char guid[37]={0};
  15363. char tempdata[65]={0};
  15364. char connectorStr[2]={0};
  15365. char TempStopTransaction[256];
  15366. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15367. fptr1 = fopen(TempStopTransaction, "r");
  15368. //TempStopTransaction格式: 槍號,StopTransaction封包
  15369. if (!fptr1)
  15370. {
  15371. //printf(" File not found or unable to open the input file!!\n");
  15372. return ;
  15373. }
  15374. ch=fgetc(fptr1);
  15375. //printf(" Now the content of the file %s is : \n",fname);
  15376. rewind(fptr1);
  15377. if(ch!=EOF)
  15378. {
  15379. // copy all contents to the temporary file except the specific line
  15380. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15381. {
  15382. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15383. if(str[0]=='\0')
  15384. {
  15385. break;
  15386. }
  15387. //TempStopTransaction格式: 槍號,StopTransaction封包
  15388. strncpy(connectorStr, str, 1);
  15389. if(atoi(connectorStr) != (gun_index+1))
  15390. {
  15391. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15392. fclose(fptr1);
  15393. return ;
  15394. }
  15395. //random_uuid(guid);
  15396. strncpy(guid, str+6, 36); //copy guid
  15397. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15398. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15399. {
  15400. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15401. }
  15402. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15403. OCPP_insert_transaction_msg(NO, str);
  15404. memset(str,0,ARRAY_SIZE(str));
  15405. }
  15406. }
  15407. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15408. fclose(fptr1);
  15409. remove(TempStopTransaction); // remove the original file
  15410. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15411. }
  15412. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15413. {
  15414. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15415. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15416. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15417. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15418. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15419. }
  15420. int GetWebSocketPingInterval(void)
  15421. {
  15422. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15423. }
  15424. int GetServerSign(void)
  15425. {
  15426. return server_sign;
  15427. }
  15428. uint8_t GetOcppSecurityProfile()
  15429. {
  15430. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15431. }
  15432. void GetOcppChargerBoxId(uint8_t *data)
  15433. {
  15434. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  15435. }
  15436. void GetOcppSecurityPassword(uint8_t *data)
  15437. {
  15438. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15439. }
  15440. void SetOcppVersion(uint8_t *version)
  15441. {
  15442. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15443. DEBUG_INFO("ocpp version: %s\n", version);
  15444. if(strstr((char*)version, "ocpp1.6") != NULL)
  15445. {
  15446. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15447. }
  15448. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15449. {
  15450. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15451. system("pkill OcppBackend");
  15452. }
  15453. }
  15454. void SetServerSign(int value)
  15455. {
  15456. server_sign = value;
  15457. }
  15458. int GetBootNotificationInterval(void)
  15459. {
  15460. return BootNotificationInterval;
  15461. }
  15462. int GetInternetConn(void)
  15463. {
  15464. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15465. }
  15466. int GetBackendConnectionTimeout(void)
  15467. {
  15468. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15469. }
  15470. int isConnectorInitMode(int gun_index)
  15471. {
  15472. int tempIndex = 0;
  15473. int result = TRUE;
  15474. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15475. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15476. {
  15477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15478. {
  15479. tempIndex = ((gun_index==2) ? 1: 0);
  15480. }
  15481. else
  15482. {
  15483. tempIndex = gun_index;
  15484. }
  15485. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15486. {
  15487. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15488. {
  15489. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15490. } //end of the same index
  15491. }//end of for CHAdeMO_QUANTITY
  15492. }
  15493. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15494. {
  15495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15496. {
  15497. tempIndex = ((gun_index==2) ? 1: 0);
  15498. }
  15499. else
  15500. {
  15501. tempIndex = gun_index;
  15502. }
  15503. for (int index = 0; index < CCS_QUANTITY; index++)
  15504. {
  15505. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15506. {
  15507. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15508. } //end of the same index
  15509. } // end of for CCS_QUANTITY
  15510. }
  15511. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15512. {
  15513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15514. {
  15515. tempIndex = ((gun_index==2) ? 1: 0);
  15516. }
  15517. else
  15518. {
  15519. tempIndex = gun_index;
  15520. }
  15521. for (int index = 0; index < GB_QUANTITY; index++)
  15522. {
  15523. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15524. {
  15525. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15526. } //end of the same index
  15527. } // end of for GB_QUANTITY
  15528. }
  15529. else if(gunType[gun_index] == GUN_TYPE_DO)
  15530. {
  15531. tempIndex = gun_index;
  15532. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15533. {
  15534. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15535. {
  15536. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15537. } //end of the same index
  15538. }
  15539. }
  15540. else
  15541. {
  15542. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15543. {
  15544. tempIndex = 2;
  15545. }
  15546. else
  15547. {
  15548. tempIndex = gun_index;
  15549. }
  15550. for (int index = 0; index < AC_QUANTITY; index++)
  15551. {
  15552. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15553. {
  15554. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15555. }//end of the same index
  15556. }//end of for AC_QUANTITY
  15557. }
  15558. return result;
  15559. }
  15560. void refreshProcDogTimer()
  15561. {
  15562. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  15563. }
  15564. void InitialSystemValue(void)
  15565. {
  15566. int connectorIndex = 0;
  15567. //int valueASCII = 0;
  15568. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15569. gunTotalNumber=0;
  15570. SystemInitial = 0;
  15571. localversion=0;
  15572. BootNotificationInterval = 0;
  15573. authorizeRetryTimes = 0;
  15574. GunStatusInterval = 10;
  15575. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15576. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15577. //Hear Beat
  15578. HeartBeatWithNOResponse = 0;
  15579. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15580. FirstHeartBeat = 0;
  15581. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15582. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15583. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15584. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15585. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15586. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15587. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15588. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15589. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15590. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15591. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15592. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15593. memset(gunType, 0, ARRAY_SIZE(gunType));
  15594. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15595. {
  15596. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15597. {
  15598. // DO series
  15599. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15600. {
  15601. SystemInitial = SystemInitial + 1;
  15602. gunTotalNumber = gunTotalNumber + 1;
  15603. gunType[connectorIndex] = GUN_TYPE_DO;
  15604. connectorIndex = connectorIndex + 1;
  15605. }
  15606. }
  15607. else
  15608. {
  15609. // DM, DW, DS series
  15610. //check connector / socket type (index: 8, 9, 10)
  15611. for(int index=7; index <10 ; index++)
  15612. {
  15613. if(index != 8)
  15614. {
  15615. // DC Connector
  15616. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15617. {
  15618. SystemInitial = SystemInitial + 1;
  15619. gunTotalNumber = gunTotalNumber + 1;
  15620. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15621. connectorIndex = connectorIndex + 1;
  15622. }
  15623. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15624. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15625. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15626. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15627. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15628. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15629. {
  15630. SystemInitial = SystemInitial + 1;
  15631. gunTotalNumber = gunTotalNumber + 1;
  15632. gunType[connectorIndex] = GUN_TYPE_CCS;
  15633. connectorIndex = connectorIndex + 1;
  15634. }
  15635. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15636. {
  15637. SystemInitial = SystemInitial + 1;
  15638. gunTotalNumber = gunTotalNumber + 1;
  15639. gunType[connectorIndex] = GUN_TYPE_GBT;
  15640. connectorIndex = connectorIndex + 1;
  15641. }
  15642. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15643. {
  15644. SystemInitial = SystemInitial + 1;
  15645. gunTotalNumber = gunTotalNumber + 1;
  15646. gunType[connectorIndex] = GUN_TYPE_DO;
  15647. connectorIndex = connectorIndex + 1;
  15648. }
  15649. }
  15650. else
  15651. {
  15652. // AC Connector
  15653. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15654. {
  15655. SystemInitial = SystemInitial + 1;
  15656. gunTotalNumber = gunTotalNumber + 1;
  15657. gunType[connectorIndex] = GUN_TYPE_AC;
  15658. connectorIndex = connectorIndex + 1;
  15659. }
  15660. }
  15661. }
  15662. }
  15663. //DEBUG_INFO("DC ...\n");
  15664. }
  15665. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15666. {
  15667. //check connector / socket type (index: 8, 9, 10)
  15668. for(int index=7; index <10 ; index++)
  15669. {
  15670. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15671. {
  15672. SystemInitial = SystemInitial + 1;
  15673. gunTotalNumber = gunTotalNumber + 1;
  15674. gunType[connectorIndex] = GUN_TYPE_AC;
  15675. connectorIndex = connectorIndex + 1;
  15676. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15677. }
  15678. }
  15679. }
  15680. //Status && ConnectorPlugIn Setting
  15681. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15682. {
  15683. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15684. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15685. }
  15686. for (int index = 0; index < CCS_QUANTITY; index++)
  15687. {
  15688. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15689. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15690. }
  15691. for (int index = 0; index < GB_QUANTITY; index++)
  15692. {
  15693. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15694. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15695. }
  15696. for (int index = 0; index < AC_QUANTITY; index++)
  15697. {
  15698. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15699. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15700. }
  15701. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15702. {
  15703. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15704. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15705. }
  15706. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15707. {
  15708. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15709. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15710. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15711. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15712. }
  15713. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15714. clientTime.Heartbeat=time((time_t*)NULL);
  15715. sleep(1);
  15716. }
  15717. void LWS_Send(char *str)
  15718. {
  15719. //=====================================================
  15720. // Check InternetConn 0: disconnected, 1: connected
  15721. //====================================================
  15722. if(GetOcppConnStatus() == 0)
  15723. {
  15724. DEBUG_INFO("offline now !!!\n");
  15725. return;
  15726. }
  15727. // Only disable isWebsocketSendable operation initiated by charger
  15728. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15729. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15730. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15731. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15732. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15733. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15734. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15735. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15736. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15737. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15738. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15739. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15740. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15741. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15742. {
  15743. isWebsocketSendable = 0;
  15744. }
  15745. pthread_mutex_lock(&lock_send);
  15746. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15747. sprintf((char *)SendBuffer, "%s", str);
  15748. SendBufLen = strlen(str);
  15749. pthread_mutex_unlock(&lock_send);
  15750. lws_callback_on_writable(wsi_client);
  15751. //lws_service(context, 0);
  15752. //sleep(1);
  15753. }
  15754. void LWS_SendNow(char *str)
  15755. {
  15756. //=====================================================
  15757. // Check InternetConn 0: disconnected, 1: connected
  15758. //====================================================
  15759. if(GetOcppConnStatus() == 0)
  15760. {
  15761. DEBUG_INFO("offline now !!!\n");
  15762. return;
  15763. }
  15764. // Only disable isWebsocketSendable operation initiated by charger
  15765. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15766. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15767. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15768. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15769. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15770. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15771. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15772. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15773. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15774. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15775. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15776. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15777. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15778. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15779. {
  15780. isWebsocketSendable = 0;
  15781. }
  15782. pthread_mutex_lock(&lock_send);
  15783. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15784. sprintf((char *)SendBuffer, "%s", str);
  15785. SendBufLen = strlen(str);
  15786. pthread_mutex_unlock(&lock_send);
  15787. lws_callback_on_writable(wsi_client);
  15788. lws_service(context, 0);
  15789. //sleep(1);
  15790. }