MessageHandler.c 923 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988
  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 ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  43. //===============================
  44. // OCPP auth variable
  45. //===============================
  46. static int authorizeRetryTimes = 0; //number of Retry times
  47. //===============================
  48. // OCPP other variables
  49. //===============================
  50. static int HeartBeatWaitTime = 10;
  51. static int FirstHeartBeat = 0;
  52. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  53. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  54. static char CurrentChargingProfileScheduleStr[30] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  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 MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isGetDiagnosticGoing:1;
  100. unsigned char isUpdateFirmwareGoing:1;
  101. }interLock;
  102. struct ClientTime
  103. {
  104. struct timespec Heartbeat;
  105. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  106. struct timespec StartTransaction;
  107. struct timespec StopTransaction;
  108. struct timespec MeterValues[CONNECTOR_QUANTITY];
  109. struct timespec RemoteStartWait;
  110. struct timespec TcciQueryDeduct;
  111. }clientTime;
  112. typedef union
  113. {
  114. //Operations Initiated by Central System
  115. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  116. struct
  117. {
  118. //CsMsgValue[0]
  119. unsigned char StatusNotificationReq:1; //bit 0,
  120. unsigned char StatusNotificationConf:1; //bit 1,
  121. unsigned char TriggerMeterValue:1; //bit 2,
  122. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  123. unsigned char isOnCharging:1; //bit 4.
  124. unsigned char :3; //bit 5~7
  125. }bits[CONNECTOR_QUANTITY];
  126. }CpinitiateMsg;
  127. CpinitiateMsg cpinitateMsg;
  128. //GetConfiguration Array
  129. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  132. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  133. #if 0
  134. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. #endif
  153. static char * ChargePointStatusStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Preparing),
  156. MACROSTR(Charging),
  157. MACROSTR(SuspendedEVSE),
  158. MACROSTR(SuspendedEV),
  159. MACROSTR(Finishing),
  160. MACROSTR(Reserved),
  161. MACROSTR(Unavailable),
  162. MACROSTR(Faulted)
  163. };
  164. static char *RegistrationStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Pending),
  167. MACROSTR(Rejected)
  168. };
  169. static char *AvailabilityTypeStr[] = {
  170. MACROSTR(Inoperative),
  171. MACROSTR(Operative)
  172. };
  173. static char *AvailabilityStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(Scheduled)
  177. };
  178. static char *ConfigurationStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(RebootRequired),
  182. MACROSTR(NotSupported)
  183. };
  184. static char *ClearCacheStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected)
  187. };
  188. static char *ChargingProfilePurposeTypeStr[] = {
  189. MACROSTR(ChargePointMaxProfile),
  190. MACROSTR(TxDefaultProfile),
  191. MACROSTR(TxProfile)
  192. };
  193. static char *ChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected),
  196. MACROSTR(NotSupported)
  197. };
  198. static char *ClearChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Unknown)
  201. };
  202. static char *GetCompositeScheduleStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected)
  205. };
  206. static char *UpdateTypeStr[] = {
  207. MACROSTR(Differential),
  208. MACROSTR(Full)
  209. };
  210. static char *UpdateStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Failed),
  213. MACROSTR(NotSupported),
  214. MACROSTR(VersionMismatch)
  215. };
  216. static char *RemoteStartStopStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Rejected)
  219. };
  220. static char *ReservationStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Faulted),
  223. MACROSTR(Occupied),
  224. MACROSTR(Rejected),
  225. MACROSTR(Unavailable)
  226. };
  227. static char *ResetTypeStr[] = {
  228. MACROSTR(Hard),
  229. MACROSTR(Soft)
  230. };
  231. static char *ResetStatusStr[] = {
  232. MACROSTR(Accepted),
  233. MACROSTR(Rejected)
  234. };
  235. static char * DiagnosticsStatusStr[] = {
  236. MACROSTR(Idle),
  237. MACROSTR(Uploaded),
  238. MACROSTR(UploadFailed),
  239. MACROSTR(Uploading)
  240. };
  241. static char * FirmwareStatusStr[] = {
  242. MACROSTR(Downloaded),
  243. MACROSTR(DownloadFailed),
  244. MACROSTR(Downloading),
  245. MACROSTR(Idle),
  246. MACROSTR(InstallationFailed),
  247. MACROSTR(Installing),
  248. MACROSTR(Installed)
  249. };
  250. static char * MessageTriggerStr[] = {
  251. MACROSTR(BootNotification),
  252. MACROSTR(DiagnosticsStatusNotification),
  253. MACROSTR(FirmwareStatusNotification),
  254. MACROSTR(Heartbeat),
  255. MACROSTR(MeterValues),
  256. MACROSTR(StatusNotification)
  257. };
  258. static char * TriggerMessageStatusStr[] = {
  259. MACROSTR(Accepted),
  260. MACROSTR(Rejected),
  261. MACROSTR(NotImplemented)
  262. };
  263. static char * UnlockStatusStr[] = {
  264. MACROSTR(Unlocked),
  265. MACROSTR(UnlockFailed),
  266. MACROSTR(NotSupported)
  267. };
  268. #if 0
  269. static char * StopTransactionReasonStr[] = {
  270. MACROSTR(EmergencyStop),
  271. MACROSTR(EVDisconnected),
  272. MACROSTR(HardReset),
  273. MACROSTR(Local),
  274. MACROSTR(Other),
  275. MACROSTR(PowerLoss),
  276. MACROSTR(Reboot),
  277. MACROSTR(Remote),
  278. MACROSTR(SoftReset),
  279. MACROSTR(UnlockCommand),
  280. MACROSTR(DeAuthorized)
  281. };
  282. #endif
  283. static char * CancelReservationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Rejected)
  286. };
  287. static char * ReadingContextStr[] = {
  288. MACROSTR(Interruption.Begin),
  289. MACROSTR(Interruption.End),
  290. MACROSTR(Other),
  291. MACROSTR(Sample.Clock),
  292. MACROSTR(Sample.Periodic),
  293. MACROSTR(Transaction.Begin),
  294. MACROSTR(Transaction.End),
  295. MACROSTR(Trigger)
  296. };
  297. static char * ValueFormatStr[] = {
  298. MACROSTR(Raw),
  299. MACROSTR(SignedData)
  300. };
  301. static char * MeasurandStr[] = {
  302. MACROSTR(Current.Export),
  303. MACROSTR(Current.Import),
  304. MACROSTR(Current.Offered),
  305. MACROSTR(Energy.Active.Export.Register),
  306. MACROSTR(Energy.Active.Import.Register),
  307. MACROSTR(Energy.Reactive.Export.Register),
  308. MACROSTR(Energy.Reactive.Import.Register),
  309. MACROSTR(Energy.Active.Export.Interval),
  310. MACROSTR(Energy.Active.Import.Interval),
  311. MACROSTR(Energy.Reactive.Export.Interval),
  312. MACROSTR(Energy.Reactive.Import.Interval),
  313. MACROSTR(Frequency),
  314. MACROSTR(Power.Active.Export),
  315. MACROSTR(Power.Active.Import),
  316. MACROSTR(Power.Factor),
  317. MACROSTR(Power.Offered),
  318. MACROSTR(Power.Reactive.ExportMACROSTR),
  319. MACROSTR(Power.Reactive.Import),
  320. MACROSTR(RPM),
  321. MACROSTR(SoC),
  322. MACROSTR(Temperature),
  323. MACROSTR(Voltage)
  324. };
  325. static char * LocationStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char * PhaseStr[] = {
  333. MACROSTR(L1),
  334. MACROSTR(L2),
  335. MACROSTR(L3),
  336. MACROSTR(N),
  337. MACROSTR(L1-N),
  338. MACROSTR(L2-N),
  339. MACROSTR(L3-N),
  340. MACROSTR(L1-L2),
  341. MACROSTR(L2-L3),
  342. MACROSTR(L3-L1)
  343. };
  344. static char * UnitOfMeasureStr[] = {
  345. MACROSTR(Wh),
  346. MACROSTR(kWh),
  347. MACROSTR(varh),
  348. MACROSTR(kvarh),
  349. MACROSTR(W),
  350. MACROSTR(kW),
  351. MACROSTR(VA),
  352. MACROSTR(kVA),
  353. MACROSTR(var),
  354. MACROSTR(kvar),
  355. MACROSTR(A),
  356. MACROSTR(V),
  357. MACROSTR(Celsius),
  358. MACROSTR(Fahrenheit),
  359. MACROSTR(K),
  360. MACROSTR(Percent)
  361. };
  362. //=========================================
  363. // Save configuration
  364. //=========================================
  365. int runShellCmd(const char*cmd)
  366. {
  367. int result = FAIL;
  368. char buf[256];
  369. FILE *fp;
  370. fp = popen(cmd, "r");
  371. if(fp != NULL)
  372. {
  373. while(fgets(buf, sizeof(buf), fp) != NULL)
  374. {
  375. DEBUG_INFO("%s\n", buf);
  376. }
  377. result = PASS;
  378. }
  379. pclose(fp);
  380. return result;
  381. }
  382. int StoreUsrConfigData(struct SysConfigData *UsrData)
  383. {
  384. int result = PASS;
  385. int fd,wrd;
  386. unsigned int i,Chk;
  387. unsigned char *ptr, *BufTmp;
  388. int MtdBlockSize = 0x300000;
  389. Chk=0;
  390. ptr=(unsigned char *)UsrData;
  391. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  392. {
  393. memset(BufTmp,0,MtdBlockSize);
  394. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  395. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  396. Chk+=*(BufTmp+i);
  397. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  398. // Output configuration to file.
  399. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  400. if (fd < 0)
  401. {
  402. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. wrd=write(fd, BufTmp, MtdBlockSize);
  407. close(fd);
  408. if(wrd<MtdBlockSize)
  409. {
  410. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  411. free(BufTmp);
  412. return 0;
  413. }
  414. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  415. DEBUG_INFO("Erase /dev/mtd10.\n");
  416. runShellCmd("flash_erase /dev/mtd10 0 0");
  417. DEBUG_INFO("Write /dev/mtd10.\n");
  418. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  419. DEBUG_INFO("Erase /dev/mtd11.\n");
  420. runShellCmd("flash_erase /dev/mtd11 0 0");
  421. DEBUG_INFO("Write /dev/mtd11.\n");
  422. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  423. system("rm -f /mnt/EvseConfig.bin");
  424. DEBUG_INFO("EvseConfig write to flash OK\n");
  425. }
  426. else
  427. {
  428. DEBUG_ERROR("alloc BlockSize NG\r\n");
  429. result = FAIL;
  430. }
  431. if(BufTmp!=NULL)
  432. free(BufTmp);
  433. return result;
  434. }
  435. //=========================================
  436. // Sqlite3 related function
  437. //=========================================
  438. static int selectSqlCount = 0;
  439. static int callback(void *data, int argc, char **argv, char **azColName){
  440. int i;
  441. //printf("%s: ", (const char*)data);
  442. selectSqlCount = argc;
  443. for(i = 0; i<argc; i++){
  444. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  445. }
  446. //printf("\n");
  447. return 0;
  448. }
  449. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  450. //int i;
  451. //printf("%s:\n", (const char*)data);
  452. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  453. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  454. return 0;
  455. }
  456. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  457. //printf("%s:\n", (const char*)data);
  458. //idTag
  459. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  460. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  461. //parentIdTag
  462. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  463. //expir_date
  464. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  465. //status
  466. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  467. //version
  468. if(columenCount > 5)
  469. idTagQuery.listVersionInt = atoi(columnValue[5]);
  470. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  471. return 0;
  472. }
  473. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  474. {
  475. // localversion = argv[5] ? atoi(argv[5]) : 0;
  476. // printf("localversion=%d\n", localversion);
  477. return 0;
  478. }
  479. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  480. {
  481. for (int i = 0; i < n_columns; i++)
  482. {
  483. DEBUG_INFO("%s\t", col_values[i]);
  484. }
  485. DEBUG_INFO("\n");
  486. return 0;
  487. }
  488. int OCPP_cleanLocalCache()
  489. {
  490. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  491. char *errMsg = 0;
  492. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  493. if (SQLITE_OK != rc)
  494. {
  495. DEBUG_INFO("SQL error: %s\n",errMsg);
  496. return FALSE;
  497. }
  498. return TRUE;
  499. }
  500. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  501. {
  502. int isSuccess = TRUE;
  503. int ret = 0;
  504. //const char* data = "Callback function called";
  505. char sql[300];
  506. char zErrMsg[200];
  507. memset(sql, 0, 300);
  508. memset(zErrMsg, 0, 200);
  509. 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);
  510. //* Execute SQL statement */
  511. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  512. if( ret != SQLITE_OK )
  513. {
  514. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  515. isSuccess = FALSE;
  516. }
  517. return isSuccess;
  518. }
  519. void OCPP_getIdTagFromLocalCache(char idTag[])
  520. {
  521. int rc = 0;
  522. char sql[100];
  523. char zErrMsg[100];
  524. memset(sql, 0, 100);
  525. memset(zErrMsg, 0, 100);
  526. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  527. memset(&idTagQuery, 0, sizeof(idTagQuery));
  528. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  529. /* Execute SQL statement */
  530. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  531. if( rc != SQLITE_OK )
  532. {
  533. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  534. }
  535. }
  536. void OCPP_getListVerion()
  537. {
  538. int rc = 0;
  539. // const char* data = "Callback function called";
  540. char sql[100];
  541. char zErrMsg[100];
  542. memset(sql, 0, 100);
  543. memset(zErrMsg, 0, 100);
  544. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  545. /* Execute SQL statement */
  546. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  547. if( rc != SQLITE_OK )
  548. {
  549. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  550. }
  551. }
  552. void OCPP_get_TableAuthlocalAllData(void)
  553. {
  554. int rc = 0;
  555. char sql[100];
  556. char zErrMsg[100];
  557. memset(sql, 0, 100);
  558. memset(zErrMsg, 0, 100);
  559. sprintf(sql,"select * from ocpp_auth_local ");
  560. /* Execute SQL statement */
  561. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  562. if( rc != SQLITE_OK )
  563. {
  564. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  565. }
  566. //return ver;
  567. }
  568. int OCPP_cleanLocalList()
  569. {
  570. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  571. char *errMsg = 0;
  572. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  573. if (SQLITE_OK != rc)
  574. {
  575. DEBUG_INFO("%s\n",errMsg);
  576. return FALSE;
  577. }
  578. return TRUE;
  579. }
  580. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  581. {
  582. int isSuccess = FALSE;
  583. int ret = 0;
  584. //const char* data = "Callback function called";
  585. char sql[300];
  586. char zErrMsg[200];
  587. memset(sql, 0, 300);
  588. memset(zErrMsg, 0, 200);
  589. 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);
  590. //* Execute SQL statement */
  591. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. memset(sql, 0, 300);
  598. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  599. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  600. if( ret != SQLITE_OK )
  601. {
  602. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  603. return isSuccess;
  604. }
  605. isSuccess = TRUE;
  606. return isSuccess;
  607. }
  608. void OCPP_getIdTagFromLocalList(char idTag[])
  609. {
  610. int rc = 0;
  611. // const char* data = "Callback function called";
  612. char sql[100];
  613. char zErrMsg[100];
  614. memset(sql, 0, 100);
  615. memset(zErrMsg, 0, 100);
  616. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  617. memset(&idTagQuery, 0, sizeof(idTagQuery));
  618. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  619. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  620. /* Execute SQL statement */
  621. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  622. if( rc != SQLITE_OK )
  623. {
  624. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  625. }
  626. //return ver;
  627. }
  628. void OCPP_deleteIdTagFromLocalList(char idTag[])
  629. {
  630. //int ver = 0;
  631. //int isSuccess = FALSE;
  632. int rc = 0;
  633. char sql[100];
  634. char zErrMsg[100];
  635. memset(sql, 0, 100);
  636. memset(zErrMsg, 0, 100);
  637. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  638. //* Execute SQL statement */
  639. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  640. if( rc != SQLITE_OK )
  641. {
  642. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  643. }
  644. }
  645. int getCurrentYear()
  646. {
  647. int result = 0;
  648. time_t CurrentTime;
  649. struct tm *tm;
  650. CurrentTime = time(NULL);
  651. tm=localtime(&CurrentTime);
  652. result = (tm->tm_year + 1900);
  653. return result;
  654. }
  655. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  656. {
  657. int result = PASS;
  658. char* errMsg = NULL;
  659. char sqlStr[8192];
  660. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  665. }
  666. 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));
  667. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  668. {
  669. result = FAIL;
  670. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  671. }
  672. return result;
  673. }
  674. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  675. {
  676. int result = PASS;
  677. char* errMsg = NULL;
  678. char sqlStr[8192];
  679. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  680. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  681. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  682. {
  683. result = FAIL;
  684. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  685. }
  686. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  687. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  688. {
  689. result = FAIL;
  690. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  691. }
  692. return result;
  693. }
  694. int OCPP_update_deduct_info(int txId, char *creditNo)
  695. {
  696. int result = PASS;
  697. char* errMsg = NULL;
  698. char sqlStr[8192];
  699. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  700. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  701. {
  702. result = FAIL;
  703. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  704. }
  705. return result;
  706. }
  707. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  708. {
  709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  711. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  712. atoi(columnValue[1]),
  713. columnValue[2],
  714. atoi(columnValue[3])==1?"true":"false",
  715. atoi(columnValue[4])==1?"true":"false",
  716. columnValue[5],
  717. columnValue[9]);
  718. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  719. return 0;
  720. }
  721. void OCPP_query_deduct_info()
  722. {
  723. int rc = 0;
  724. char sql[100];
  725. char zErrMsg[100];
  726. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  727. /* Execute SQL statement */
  728. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  729. if( rc != SQLITE_OK )
  730. {
  731. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  732. }
  733. }
  734. void reportReaderStatus(int gun_index)
  735. {
  736. struct timeval tmnow;
  737. struct tm *tm;
  738. char buf[28];//, usec_buf[6];
  739. gettimeofday(&tmnow, NULL);
  740. time_t t;
  741. t = time(NULL);
  742. /*UTC time and date*/
  743. tm = gmtime(&t);
  744. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  745. #if 0 // remove temporally
  746. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  747. strcat(buf,".");
  748. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  749. strcat(buf,usec_buf);
  750. #endif
  751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  754. (gun_index+1),
  755. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  756. buf,
  757. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  758. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  759. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  760. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  761. }
  762. //==========================================
  763. // Check time passed since today
  764. //==========================================
  765. long long DiffTimebWithNow(struct timeb ST)
  766. {
  767. //return milli-second
  768. struct timeb ET;
  769. long long StartTime,StopTime;
  770. ftime(&ET);
  771. StartTime=(long long)ST.time;
  772. StopTime=(long long)ET.time;
  773. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  774. }
  775. int getTimePassSinceToday(uint8_t gun_index)
  776. {
  777. int result = -1;
  778. static time_t lastTime[4];
  779. time_t t;
  780. struct tm *tmStartToday;
  781. struct timeb tbStartToday;
  782. t=time(NULL);
  783. if(difftime(t, lastTime[gun_index])>0)
  784. {
  785. tmStartToday=localtime(&t);
  786. tmStartToday->tm_hour = 0;
  787. tmStartToday->tm_min = 0;
  788. tmStartToday->tm_sec = 0;
  789. tbStartToday.time = mktime(tmStartToday);
  790. tbStartToday.millitm = 0;
  791. result = DiffTimebWithNow(tbStartToday)/1000;
  792. lastTime[gun_index] = t;
  793. }
  794. return result;
  795. }
  796. void getNowDatetime(uint8_t *data)
  797. {
  798. time_t t = time(NULL);
  799. struct tm tm = *localtime(&t);
  800. 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);
  801. }
  802. int syncDateTimeRTC(uint8_t *data)
  803. {
  804. struct ParsingResult
  805. {
  806. int result;
  807. int scanedElement;
  808. int year;
  809. int month;
  810. int mday;
  811. int hour;
  812. int min;
  813. int sec;
  814. int tz_hour;
  815. int tz_min;
  816. float minSec;
  817. }result;
  818. struct tm tmOrg;
  819. struct tm *tmTarget;
  820. struct timeb tbTarget;
  821. char buf[128];
  822. memset(&result, 0x00, sizeof(struct ParsingResult));
  823. result.result = PASS;
  824. if(strstr((char*)data, ".") != NULL)
  825. {
  826. // Original data with mini second
  827. if(strstr((char*)data, "Z") != NULL)
  828. {
  829. // Original data with Z
  830. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  831. &result.year,
  832. &result.month,
  833. &result.mday,
  834. &result.hour,
  835. &result.min,
  836. &result.sec,
  837. &result.minSec);
  838. }
  839. else
  840. {
  841. // Original data without Z
  842. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  843. &result.year,
  844. &result.month,
  845. &result.mday,
  846. &result.hour,
  847. &result.min,
  848. &result.sec,
  849. &result.minSec,
  850. &result.tz_hour,
  851. &result.tz_min);
  852. }
  853. }
  854. else
  855. {
  856. // Original data without mini second
  857. if(strstr((char*)data, "Z") != NULL)
  858. {
  859. // Original data with Z
  860. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  861. &result.year,
  862. &result.month,
  863. &result.mday,
  864. &result.hour,
  865. &result.min,
  866. &result.sec);
  867. }
  868. else
  869. {
  870. // Original data without Z
  871. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  872. &result.year,
  873. &result.month,
  874. &result.mday,
  875. &result.hour,
  876. &result.min,
  877. &result.sec,
  878. &result.tz_hour,
  879. &result.tz_min);
  880. }
  881. }
  882. tmOrg.tm_year = result.year - 1900;
  883. tmOrg.tm_mon = result.month - 1;
  884. tmOrg.tm_mday = result.mday;
  885. tmOrg.tm_hour = result.hour;
  886. tmOrg.tm_min = result.min;
  887. tmOrg.tm_sec = result.sec;
  888. tmOrg.tm_gmtoff = 0;
  889. tbTarget.time = mktime(&tmOrg);
  890. tbTarget.timezone = 0;
  891. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  892. tmTarget = gmtime(&tbTarget.time);
  893. 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);
  894. //DEBUG_INFO(" org date time: %s\n", data);
  895. //DEBUG_INFO("parse date time: %s\n", buf);
  896. system(buf);
  897. system("/sbin/hwclock -w --systohc");
  898. if(result.scanedElement < 6)
  899. result.result = FAIL;
  900. return result.result;
  901. }
  902. //==========================================
  903. // GetCompositeSchedule logic related function
  904. //==========================================
  905. int DiffTimebSec(struct timeb ST, struct timeb ET)
  906. {
  907. //return milli-second
  908. unsigned int StartTime,StopTime;
  909. StartTime=(unsigned int)ST.time;
  910. StopTime=(unsigned int)ET.time;
  911. return (StopTime-StartTime);
  912. }
  913. int DiffTimebWithNowSec(struct timeb ST)
  914. {
  915. //return milli-second
  916. struct timeb ET;
  917. unsigned int StartTime,StopTime;
  918. ftime(&ET);
  919. StartTime=(unsigned int)ST.time;
  920. StopTime=(unsigned int)ET.time;
  921. return (StopTime-StartTime);
  922. }
  923. int getStartStop(uint8_t *start, uint8_t *stop)
  924. {
  925. struct ParsingResult
  926. {
  927. int result;
  928. int scanedElement;
  929. int year;
  930. int month;
  931. int mday;
  932. int hour;
  933. int min;
  934. int sec;
  935. int tz_hour;
  936. int tz_min;
  937. float minSec;
  938. };
  939. struct ParsingResult parseStart;
  940. struct ParsingResult parseStop;
  941. int result = -1;
  942. struct tm tmStart;
  943. struct timeb tbStart;
  944. struct tm tmStop;
  945. struct timeb tbStop;
  946. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  947. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  948. // Scan start & stop date time
  949. if(strstr((char*)start, ".") != NULL)
  950. {
  951. // Original data with mini second
  952. if(strstr((char*)start, "Z") != NULL)
  953. {
  954. // Original data with Z
  955. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  956. &parseStart.year,
  957. &parseStart.month,
  958. &parseStart.mday,
  959. &parseStart.hour,
  960. &parseStart.min,
  961. &parseStart.sec,
  962. &parseStart.minSec);
  963. }
  964. else
  965. {
  966. // Original data without Z
  967. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  968. &parseStart.year,
  969. &parseStart.month,
  970. &parseStart.mday,
  971. &parseStart.hour,
  972. &parseStart.min,
  973. &parseStart.sec,
  974. &parseStart.minSec,
  975. &parseStart.tz_hour,
  976. &parseStart.tz_min);
  977. }
  978. }
  979. else
  980. {
  981. // Original data without mini second
  982. if(strstr((char*)start, "Z") != NULL)
  983. {
  984. // Original data with Z
  985. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  986. &parseStart.year,
  987. &parseStart.month,
  988. &parseStart.mday,
  989. &parseStart.hour,
  990. &parseStart.min,
  991. &parseStart.sec);
  992. }
  993. else
  994. {
  995. // Original data without Z
  996. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  997. &parseStart.year,
  998. &parseStart.month,
  999. &parseStart.mday,
  1000. &parseStart.hour,
  1001. &parseStart.min,
  1002. &parseStart.sec,
  1003. &parseStart.tz_hour,
  1004. &parseStart.tz_min);
  1005. }
  1006. }
  1007. if(strstr((char*)stop, ".") != NULL)
  1008. {
  1009. // Original data with mini second
  1010. if(strstr((char*)stop, "Z") != NULL)
  1011. {
  1012. // Original data with Z
  1013. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1014. &parseStop.year,
  1015. &parseStop.month,
  1016. &parseStop.mday,
  1017. &parseStop.hour,
  1018. &parseStop.min,
  1019. &parseStop.sec,
  1020. &parseStop.minSec);
  1021. }
  1022. else
  1023. {
  1024. // Original data without Z
  1025. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1026. &parseStop.year,
  1027. &parseStop.month,
  1028. &parseStop.mday,
  1029. &parseStop.hour,
  1030. &parseStop.min,
  1031. &parseStop.sec,
  1032. &parseStop.minSec,
  1033. &parseStop.tz_hour,
  1034. &parseStop.tz_min);
  1035. }
  1036. }
  1037. else
  1038. {
  1039. // Original data without mini second
  1040. if(strstr((char*)stop, "Z") != NULL)
  1041. {
  1042. // Original data with Z
  1043. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1044. &parseStop.year,
  1045. &parseStop.month,
  1046. &parseStop.mday,
  1047. &parseStop.hour,
  1048. &parseStop.min,
  1049. &parseStop.sec);
  1050. }
  1051. else
  1052. {
  1053. // Original data without Z
  1054. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1055. &parseStop.year,
  1056. &parseStop.month,
  1057. &parseStop.mday,
  1058. &parseStop.hour,
  1059. &parseStop.min,
  1060. &parseStop.sec,
  1061. &parseStop.tz_hour,
  1062. &parseStop.tz_min);
  1063. }
  1064. }
  1065. // Calculate date time difference
  1066. if((parseStart.scanedElement >=6) &&
  1067. (parseStop.scanedElement >=6))
  1068. {
  1069. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1070. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1071. tmStart.tm_year = parseStart.year - 1900;
  1072. tmStart.tm_mon = parseStart.month - 1;
  1073. tmStart.tm_mday = parseStart.mday;
  1074. tmStart.tm_hour = parseStart.hour;
  1075. tmStart.tm_min = parseStart.min;
  1076. tmStart.tm_sec = parseStart.sec;
  1077. tmStart.tm_gmtoff = 0;
  1078. tbStart.time = mktime(&tmStart);
  1079. tbStart.timezone = 0;
  1080. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1081. tmStop.tm_year = parseStop.year - 1900;
  1082. tmStop.tm_mon = parseStop.month - 1;
  1083. tmStop.tm_mday = parseStop.mday;
  1084. tmStop.tm_hour = parseStop.hour;
  1085. tmStop.tm_min = parseStop.min;
  1086. tmStop.tm_sec = parseStop.sec;
  1087. tmStop.tm_gmtoff = 0;
  1088. tbStop.time = mktime(&tmStop);
  1089. tbStop.timezone = 0;
  1090. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1091. result = DiffTimebSec(tbStart, tbStop);
  1092. //DEBUG_INFO("getStartStop(): %d\n", result);
  1093. }
  1094. else
  1095. {
  1096. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1097. }
  1098. return result;
  1099. }
  1100. int isOvertNow(uint8_t *start)
  1101. {
  1102. int result = NO;
  1103. struct ParsingResult
  1104. {
  1105. int result;
  1106. int scanedElement;
  1107. int year;
  1108. int month;
  1109. int mday;
  1110. int hour;
  1111. int min;
  1112. int sec;
  1113. int tz_hour;
  1114. int tz_min;
  1115. float minSec;
  1116. }parsingResult;
  1117. struct tm tmStart;
  1118. struct timeb tbStart;
  1119. if(strstr((char*)start, ".") != NULL)
  1120. {
  1121. // Original data with mini second
  1122. if(strstr((char*)start, "Z") != NULL)
  1123. {
  1124. // Original data with Z
  1125. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1126. &parsingResult.year,
  1127. &parsingResult.month,
  1128. &parsingResult.mday,
  1129. &parsingResult.hour,
  1130. &parsingResult.min,
  1131. &parsingResult.sec,
  1132. &parsingResult.minSec);
  1133. }
  1134. else
  1135. {
  1136. // Original data without Z
  1137. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1138. &parsingResult.year,
  1139. &parsingResult.month,
  1140. &parsingResult.mday,
  1141. &parsingResult.hour,
  1142. &parsingResult.min,
  1143. &parsingResult.sec,
  1144. &parsingResult.minSec,
  1145. &parsingResult.tz_hour,
  1146. &parsingResult.tz_min);
  1147. }
  1148. }
  1149. else
  1150. {
  1151. // Original data without mini second
  1152. if(strstr((char*)start, "Z") != NULL)
  1153. {
  1154. // Original data with Z
  1155. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1156. &parsingResult.year,
  1157. &parsingResult.month,
  1158. &parsingResult.mday,
  1159. &parsingResult.hour,
  1160. &parsingResult.min,
  1161. &parsingResult.sec);
  1162. }
  1163. else
  1164. {
  1165. // Original data without Z
  1166. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1167. &parsingResult.year,
  1168. &parsingResult.month,
  1169. &parsingResult.mday,
  1170. &parsingResult.hour,
  1171. &parsingResult.min,
  1172. &parsingResult.sec,
  1173. &parsingResult.tz_hour,
  1174. &parsingResult.tz_min);
  1175. }
  1176. }
  1177. if(parsingResult.scanedElement >= 6)
  1178. {
  1179. tmStart.tm_year = parsingResult.year - 1900;
  1180. tmStart.tm_mon = parsingResult.month - 1;
  1181. tmStart.tm_mday = parsingResult.mday;
  1182. tmStart.tm_hour = parsingResult.hour;
  1183. tmStart.tm_min = parsingResult.min;
  1184. tmStart.tm_sec = parsingResult.sec;
  1185. tmStart.tm_gmtoff = 0;
  1186. tbStart.time = mktime(&tmStart);
  1187. tbStart.timezone = 0;
  1188. tbStart.millitm = 0;
  1189. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1190. if(DiffTimebWithNowSec(tbStart) <= 0)
  1191. result = NO;
  1192. else
  1193. result = YES;
  1194. }
  1195. else
  1196. {
  1197. DEBUG_WARN("Start date parsing error.\n");
  1198. }
  1199. return result;
  1200. }
  1201. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1202. {
  1203. struct ParsingResult
  1204. {
  1205. int result;
  1206. int scanedElement;
  1207. int year;
  1208. int month;
  1209. int mday;
  1210. int hour;
  1211. int min;
  1212. int sec;
  1213. int tz_hour;
  1214. int tz_min;
  1215. float minSec;
  1216. };
  1217. struct ParsingResult parseStart;
  1218. struct ParsingResult parseStop;
  1219. int result = -1;
  1220. struct tm tmStart;
  1221. struct timeb tbStart;
  1222. struct tm tmStop;
  1223. struct timeb tbStop;
  1224. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1225. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1226. // Scan start & stop date time
  1227. if(strstr((char*)start, ".") != NULL)
  1228. {
  1229. // Original data with mini second
  1230. if(strstr((char*)start, "Z") != NULL)
  1231. {
  1232. // Original data with Z
  1233. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1234. &parseStart.year,
  1235. &parseStart.month,
  1236. &parseStart.mday,
  1237. &parseStart.hour,
  1238. &parseStart.min,
  1239. &parseStart.sec,
  1240. &parseStart.minSec);
  1241. }
  1242. else
  1243. {
  1244. // Original data without Z
  1245. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1246. &parseStart.year,
  1247. &parseStart.month,
  1248. &parseStart.mday,
  1249. &parseStart.hour,
  1250. &parseStart.min,
  1251. &parseStart.sec,
  1252. &parseStart.minSec,
  1253. &parseStart.tz_hour,
  1254. &parseStart.tz_min);
  1255. }
  1256. }
  1257. else
  1258. {
  1259. // Original data without mini second
  1260. if(strstr((char*)start, "Z") != NULL)
  1261. {
  1262. // Original data with Z
  1263. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1264. &parseStart.year,
  1265. &parseStart.month,
  1266. &parseStart.mday,
  1267. &parseStart.hour,
  1268. &parseStart.min,
  1269. &parseStart.sec);
  1270. }
  1271. else
  1272. {
  1273. // Original data without Z
  1274. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1275. &parseStart.year,
  1276. &parseStart.month,
  1277. &parseStart.mday,
  1278. &parseStart.hour,
  1279. &parseStart.min,
  1280. &parseStart.sec,
  1281. &parseStart.tz_hour,
  1282. &parseStart.tz_min);
  1283. }
  1284. }
  1285. if(strstr((char*)stop, ".") != NULL)
  1286. {
  1287. // Original data with mini second
  1288. if(strstr((char*)stop, "Z") != NULL)
  1289. {
  1290. // Original data with Z
  1291. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1292. &parseStop.year,
  1293. &parseStop.month,
  1294. &parseStop.mday,
  1295. &parseStop.hour,
  1296. &parseStop.min,
  1297. &parseStop.sec,
  1298. &parseStop.minSec);
  1299. }
  1300. else
  1301. {
  1302. // Original data without Z
  1303. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1304. &parseStop.year,
  1305. &parseStop.month,
  1306. &parseStop.mday,
  1307. &parseStop.hour,
  1308. &parseStop.min,
  1309. &parseStop.sec,
  1310. &parseStop.minSec,
  1311. &parseStop.tz_hour,
  1312. &parseStop.tz_min);
  1313. }
  1314. }
  1315. else
  1316. {
  1317. // Original data without mini second
  1318. if(strstr((char*)stop, "Z") != NULL)
  1319. {
  1320. // Original data with Z
  1321. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1322. &parseStop.year,
  1323. &parseStop.month,
  1324. &parseStop.mday,
  1325. &parseStop.hour,
  1326. &parseStop.min,
  1327. &parseStop.sec);
  1328. }
  1329. else
  1330. {
  1331. // Original data without Z
  1332. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1333. &parseStop.year,
  1334. &parseStop.month,
  1335. &parseStop.mday,
  1336. &parseStop.hour,
  1337. &parseStop.min,
  1338. &parseStop.sec,
  1339. &parseStop.tz_hour,
  1340. &parseStop.tz_min);
  1341. }
  1342. }
  1343. // Calculate date time difference
  1344. if((parseStart.scanedElement >=6) &&
  1345. (parseStop.scanedElement >=6))
  1346. {
  1347. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1348. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1349. tmStart.tm_year = parseStart.year - 1900;
  1350. tmStart.tm_mon = parseStart.month - 1;
  1351. tmStart.tm_mday = parseStart.mday;
  1352. tmStart.tm_hour = parseStart.hour;
  1353. tmStart.tm_min = parseStart.min;
  1354. tmStart.tm_sec = parseStart.sec;
  1355. tmStart.tm_gmtoff = 0;
  1356. tbStart.time = mktime(&tmStart);
  1357. tbStart.timezone = 0;
  1358. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1359. tmStop.tm_year = parseStop.year - 1900;
  1360. tmStop.tm_mon = parseStop.month - 1;
  1361. tmStop.tm_mday = parseStop.mday;
  1362. tmStop.tm_hour = parseStop.hour;
  1363. tmStop.tm_min = parseStop.min;
  1364. tmStop.tm_sec = parseStop.sec;
  1365. tmStop.tm_gmtoff = 0;
  1366. tbStop.time = mktime(&tmStop);
  1367. tbStop.timezone = 0;
  1368. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1369. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1370. //DEBUG_INFO("getStartStop(): %d\n", result);
  1371. }
  1372. else
  1373. {
  1374. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1375. }
  1376. return result;
  1377. }
  1378. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1379. {
  1380. FILE *fp;
  1381. char profileFileName[128];
  1382. char *line = NULL;
  1383. size_t len = 0;
  1384. time_t CurrentTime;
  1385. struct tm *tmComposite;
  1386. struct StructChargingProfile maxProfile;
  1387. struct StructChargingProfile compositeProfile;
  1388. uint8_t limitMax=0;
  1389. int compositePeriodIdx = 0;
  1390. CurrentTime = time(NULL);
  1391. tmComposite=localtime(&CurrentTime);
  1392. 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);
  1393. if(isUnitA)
  1394. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1395. else
  1396. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1397. compositeProfile.ChargingSchedule.Duration = durationReq;
  1398. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1399. {
  1400. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1401. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1402. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1403. }
  1404. compositeProfile.ChargingProfileId = 0;
  1405. compositeProfile.StackLevel = 99 ;
  1406. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1407. maxProfile.ChargingProfileId = -1;
  1408. maxProfile.ChargingSchedule.Duration = -1;
  1409. system("rm -f /tmp/*.json");
  1410. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1411. // Search max profile
  1412. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1413. if((access(profileFileName, F_OK))!=-1)
  1414. {
  1415. fp = fopen(profileFileName, "r");
  1416. while(getline(&line, &len, fp) != -1)
  1417. {
  1418. json_object *obj = NULL;
  1419. obj = json_tokener_parse(line);
  1420. if(is_error(obj))
  1421. {
  1422. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1423. }
  1424. else
  1425. {
  1426. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1427. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1428. )
  1429. {
  1430. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1431. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1432. )
  1433. {
  1434. struct tm tmFrom, tmTo;
  1435. struct timeb tbFrom, tbTo;
  1436. 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) &&
  1437. (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))
  1438. {
  1439. tmFrom.tm_year -= 1900;
  1440. tmFrom.tm_mon -= 1;
  1441. tbFrom.time = mktime(&tmFrom);
  1442. tmTo.tm_year -= 1900;
  1443. tmTo.tm_mon -= 1;
  1444. tbTo.time = mktime(&tmTo);
  1445. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1446. {
  1447. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1448. {
  1449. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1450. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1451. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1452. }
  1453. if(maxProfile.ChargingProfileId == -1)
  1454. DEBUG_INFO("MaxProfile found.\n");
  1455. else
  1456. DEBUG_INFO("MaxProfile updated.\n");
  1457. // Required item
  1458. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1459. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1460. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1461. if(isUnitA)
  1462. {
  1463. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1464. 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++)
  1465. {
  1466. 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"));
  1467. 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?
  1468. 3:
  1469. 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")));
  1470. 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")));
  1471. }
  1472. }
  1473. else
  1474. {
  1475. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1476. 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++)
  1477. {
  1478. 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"));
  1479. 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?
  1480. 3:
  1481. 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")));
  1482. 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));
  1483. }
  1484. }
  1485. // Optional item
  1486. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1487. {
  1488. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1489. }
  1490. else
  1491. {
  1492. sprintf((char*)maxProfile.ValidFrom, " ");
  1493. }
  1494. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1495. {
  1496. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1497. }
  1498. else
  1499. {
  1500. sprintf((char*)maxProfile.ValidTo, " ");
  1501. }
  1502. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1503. {
  1504. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1505. }
  1506. else
  1507. {
  1508. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1509. }
  1510. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1511. {
  1512. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1513. }
  1514. else
  1515. {
  1516. maxProfile.TransactionId = -1;
  1517. }
  1518. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1519. {
  1520. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1521. }
  1522. else
  1523. {
  1524. maxProfile.ChargingSchedule.Duration = 86400;
  1525. }
  1526. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1527. {
  1528. 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")));
  1529. }
  1530. else
  1531. {
  1532. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1533. }
  1534. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1535. {
  1536. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1537. }
  1538. else
  1539. {
  1540. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. else
  1546. {
  1547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1548. {
  1549. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1552. }
  1553. if(maxProfile.ChargingProfileId == -1)
  1554. DEBUG_INFO("MaxProfile found.\n");
  1555. else
  1556. DEBUG_INFO("MaxProfile updated.\n");
  1557. // Required item
  1558. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1559. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1560. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1561. if(isUnitA)
  1562. {
  1563. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1564. 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++)
  1565. {
  1566. 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"));
  1567. 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?
  1568. 3:
  1569. 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")));
  1570. 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")));
  1571. }
  1572. }
  1573. else
  1574. {
  1575. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1576. 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++)
  1577. {
  1578. 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"));
  1579. 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?
  1580. 3:
  1581. 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")));
  1582. 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));
  1583. }
  1584. }
  1585. // Optional item
  1586. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1587. {
  1588. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1589. }
  1590. else
  1591. {
  1592. sprintf((char*)maxProfile.ValidFrom, " ");
  1593. }
  1594. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1595. {
  1596. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1597. }
  1598. else
  1599. {
  1600. sprintf((char*)maxProfile.ValidTo, " ");
  1601. }
  1602. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1603. {
  1604. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1605. }
  1606. else
  1607. {
  1608. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1609. }
  1610. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1611. {
  1612. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1613. }
  1614. else
  1615. {
  1616. maxProfile.TransactionId = -1;
  1617. }
  1618. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1619. {
  1620. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1621. }
  1622. else
  1623. {
  1624. maxProfile.ChargingSchedule.Duration = 86400;
  1625. }
  1626. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1627. {
  1628. 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")));
  1629. }
  1630. else
  1631. {
  1632. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1633. }
  1634. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1635. {
  1636. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1637. }
  1638. else
  1639. {
  1640. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1641. }
  1642. }
  1643. }
  1644. }
  1645. json_object_put(obj);
  1646. }
  1647. fclose(fp);
  1648. /*
  1649. if(maxProfile.ChargingProfileId !=-1)
  1650. {
  1651. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1652. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1653. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1654. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1655. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1656. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1657. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1658. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1659. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1660. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1661. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1662. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1663. {
  1664. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1665. {
  1666. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1667. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1668. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1669. }
  1670. }
  1671. }
  1672. else
  1673. DEBUG_INFO("MaxProfile not found.\n");
  1674. DEBUG_INFO("------------------------------------\n");*/
  1675. }
  1676. if(maxProfile.ChargingProfileId != -1)
  1677. {
  1678. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1679. {
  1680. if(maxProfile.ChargingSchedule.Duration != -1)
  1681. {
  1682. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1683. 0:
  1684. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1685. }
  1686. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1687. {
  1688. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1689. {
  1690. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1691. 0:
  1692. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1693. if(idxPeriod > 0)
  1694. {
  1695. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1696. {
  1697. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1698. }
  1699. }
  1700. }
  1701. }
  1702. }
  1703. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1704. {
  1705. if(maxProfile.ChargingSchedule.Duration != -1)
  1706. {
  1707. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1708. }
  1709. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1710. {
  1711. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1712. {
  1713. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1714. if(idxPeriod > 0)
  1715. {
  1716. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1717. {
  1718. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1719. }
  1720. }
  1721. }
  1722. }
  1723. }
  1724. else
  1725. {
  1726. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1727. {
  1728. if(maxProfile.ChargingSchedule.Duration != -1)
  1729. {
  1730. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1731. 0:
  1732. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1733. }
  1734. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1735. {
  1736. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1737. {
  1738. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1739. 0:
  1740. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1741. if(idxPeriod > 0)
  1742. {
  1743. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1744. {
  1745. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1746. }
  1747. }
  1748. }
  1749. }
  1750. }
  1751. else
  1752. {
  1753. if(maxProfile.ChargingSchedule.Duration != -1)
  1754. {
  1755. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1756. 0:
  1757. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1758. }
  1759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1760. {
  1761. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1762. {
  1763. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1764. 0:
  1765. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1766. if(idxPeriod > 0)
  1767. {
  1768. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1769. {
  1770. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1771. }
  1772. }
  1773. }
  1774. }
  1775. }
  1776. }
  1777. /*
  1778. DEBUG_INFO("MaxProfile after align.\n");
  1779. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1780. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1781. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1782. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1783. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1784. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1785. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1786. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1787. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1788. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1789. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1790. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1791. {
  1792. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1793. {
  1794. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1795. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1796. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1797. }
  1798. }
  1799. DEBUG_INFO("------------------------------------\n");*/
  1800. }
  1801. // Find each profile period quantity
  1802. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1803. {
  1804. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1805. limitMax = idx+1;
  1806. }
  1807. if(maxProfile.ChargingProfileId != -1)
  1808. {
  1809. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1810. {
  1811. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1812. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1813. (maxProfile.ChargingSchedule.Duration > 0))
  1814. {
  1815. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1816. {
  1817. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1818. compositePeriodIdx++;
  1819. }
  1820. else
  1821. {
  1822. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1823. }
  1824. }
  1825. }
  1826. }
  1827. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1828. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1829. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1830. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1831. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1832. {
  1833. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1834. {
  1835. compositeProfile.ChargingProfileId = 1;
  1836. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1837. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1838. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1839. }
  1840. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1841. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1842. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1843. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1844. }
  1845. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1846. if(line)
  1847. free(line);
  1848. }
  1849. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1850. {
  1851. FILE *fp;
  1852. char profileFileName[128];
  1853. char *line = NULL;
  1854. size_t len = 0;
  1855. time_t CurrentTime;
  1856. struct tm *tmComposite;
  1857. struct StructChargingProfile maxProfile;
  1858. struct StructChargingProfile defaultTxProfile;
  1859. struct StructChargingProfile txProfile;
  1860. struct StructChargingProfile compositeProfile;
  1861. struct StructChargingSchedulePeriod tmpPeriod;
  1862. uint8_t limitMax=0;
  1863. uint8_t limitDef=0;
  1864. uint8_t limitTx=0;
  1865. int compositePeriodIdx = 0;
  1866. CurrentTime = time(NULL);
  1867. tmComposite=localtime(&CurrentTime);
  1868. 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);
  1869. if(isUnitA)
  1870. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1871. else
  1872. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1873. compositeProfile.ChargingSchedule.Duration = durationReq;
  1874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1875. {
  1876. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1877. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1878. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1879. }
  1880. compositeProfile.ChargingProfileId = 0;
  1881. compositeProfile.StackLevel = 99 ;
  1882. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1883. maxProfile.ChargingProfileId = -1;
  1884. defaultTxProfile.ChargingProfileId = -1;
  1885. txProfile.ChargingProfileId = -1;
  1886. maxProfile.ChargingSchedule.Duration = -1;
  1887. defaultTxProfile.ChargingSchedule.Duration = -1;
  1888. txProfile.ChargingSchedule.Duration = -1;
  1889. system("rm -f /tmp/*.json");
  1890. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1891. /*
  1892. * Search valid charging profile
  1893. */
  1894. //DEBUG_INFO("====================================\n");
  1895. // Search tx profile
  1896. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1897. if((access(profileFileName, F_OK))!=-1)
  1898. {
  1899. fp = fopen(profileFileName, "r");
  1900. while(getline(&line, &len, fp) != -1)
  1901. {
  1902. json_object *obj = NULL;
  1903. obj = json_tokener_parse(line);
  1904. if(is_error(obj))
  1905. {
  1906. DEBUG_ERROR("Parse txProfile from file error.\n");
  1907. }
  1908. else
  1909. {
  1910. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1911. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1912. )
  1913. {
  1914. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1915. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1916. )
  1917. {
  1918. struct tm tmFrom, tmTo;
  1919. struct timeb tbFrom, tbTo;
  1920. 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) &&
  1921. (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))
  1922. {
  1923. tmFrom.tm_year -= 1900;
  1924. tmFrom.tm_mon -= 1;
  1925. tbFrom.time = mktime(&tmFrom);
  1926. tmTo.tm_year -= 1900;
  1927. tmTo.tm_mon -= 1;
  1928. tbTo.time = mktime(&tmTo);
  1929. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1930. {
  1931. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1932. {
  1933. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1934. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1935. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1936. }
  1937. if(txProfile.ChargingProfileId == -1)
  1938. DEBUG_INFO("TxProfile found.\n");
  1939. else
  1940. DEBUG_INFO("TxProfile updated.\n");
  1941. // Required item
  1942. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1943. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1944. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1945. if(isUnitA)
  1946. {
  1947. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1948. 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++)
  1949. {
  1950. 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"));
  1951. 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?
  1952. 3:
  1953. 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")));
  1954. 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")));
  1955. }
  1956. }
  1957. else
  1958. {
  1959. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1960. 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++)
  1961. {
  1962. 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"));
  1963. 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?
  1964. 3:
  1965. 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")));
  1966. 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));
  1967. }
  1968. }
  1969. // Optional item
  1970. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1971. {
  1972. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1973. }
  1974. else
  1975. {
  1976. sprintf((char*)txProfile.ValidFrom, " ");
  1977. }
  1978. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1979. {
  1980. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1981. }
  1982. else
  1983. {
  1984. sprintf((char*)txProfile.ValidTo, " ");
  1985. }
  1986. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1987. {
  1988. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1989. }
  1990. else
  1991. {
  1992. sprintf((char*)txProfile.RecurrencyKind, " ");
  1993. }
  1994. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1995. {
  1996. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1997. }
  1998. else
  1999. {
  2000. txProfile.TransactionId = -1;
  2001. }
  2002. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2003. {
  2004. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2005. }
  2006. else
  2007. {
  2008. txProfile.ChargingSchedule.Duration = 86400;
  2009. }
  2010. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2011. {
  2012. 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")));
  2013. }
  2014. else
  2015. {
  2016. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2017. }
  2018. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2019. {
  2020. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2021. }
  2022. else
  2023. {
  2024. txProfile.ChargingSchedule.MinChargingRate = -1;
  2025. }
  2026. }
  2027. }
  2028. }
  2029. else
  2030. {
  2031. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2032. {
  2033. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2034. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2035. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2036. }
  2037. if(txProfile.ChargingProfileId == -1)
  2038. DEBUG_INFO("TxProfile found.\n");
  2039. else
  2040. DEBUG_INFO("TxProfile updated.\n");
  2041. // Required item
  2042. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2043. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2044. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2045. if(isUnitA)
  2046. {
  2047. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2048. 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++)
  2049. {
  2050. 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"));
  2051. 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?
  2052. 3:
  2053. 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")));
  2054. 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")));
  2055. }
  2056. }
  2057. else
  2058. {
  2059. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2060. 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++)
  2061. {
  2062. 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"));
  2063. 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?
  2064. 3:
  2065. 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")));
  2066. 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));
  2067. }
  2068. }
  2069. // Optional item
  2070. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2071. {
  2072. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2073. }
  2074. else
  2075. {
  2076. sprintf((char*)txProfile.ValidFrom, " ");
  2077. }
  2078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2079. {
  2080. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2081. }
  2082. else
  2083. {
  2084. sprintf((char*)txProfile.ValidTo, " ");
  2085. }
  2086. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2087. {
  2088. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2089. }
  2090. else
  2091. {
  2092. sprintf((char*)txProfile.RecurrencyKind, " ");
  2093. }
  2094. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2095. {
  2096. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2097. }
  2098. else
  2099. {
  2100. txProfile.TransactionId = -1;
  2101. }
  2102. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2103. {
  2104. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2105. }
  2106. else
  2107. {
  2108. txProfile.ChargingSchedule.Duration = 86400;
  2109. }
  2110. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2111. {
  2112. 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")));
  2113. }
  2114. else
  2115. {
  2116. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2117. }
  2118. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2119. {
  2120. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2121. }
  2122. else
  2123. {
  2124. txProfile.ChargingSchedule.MinChargingRate = -1;
  2125. }
  2126. }
  2127. }
  2128. }
  2129. json_object_put(obj);
  2130. }
  2131. fclose(fp);
  2132. /*
  2133. if(txProfile.ChargingProfileId != -1)
  2134. {
  2135. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2136. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2137. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2138. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2139. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2140. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2141. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2142. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2143. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2144. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2145. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2146. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2147. {
  2148. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2149. {
  2150. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2151. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2152. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2153. }
  2154. }
  2155. }
  2156. else
  2157. DEBUG_INFO("TxProfile not found.\n");*/
  2158. }
  2159. // Search default tx profile
  2160. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2161. if((access(profileFileName, F_OK))==-1)
  2162. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2163. if((access(profileFileName, F_OK))!=-1)
  2164. {
  2165. fp = fopen(profileFileName, "r");
  2166. while(getline(&line, &len, fp) != -1)
  2167. {
  2168. json_object *obj = NULL;
  2169. obj = json_tokener_parse(line);
  2170. if(is_error(obj))
  2171. {
  2172. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2173. }
  2174. else
  2175. {
  2176. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2177. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2178. )
  2179. {
  2180. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2181. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2182. )
  2183. {
  2184. struct tm tmFrom, tmTo;
  2185. struct timeb tbFrom, tbTo;
  2186. 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) &&
  2187. (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))
  2188. {
  2189. tmFrom.tm_year -= 1900;
  2190. tmFrom.tm_mon -= 1;
  2191. tbFrom.time = mktime(&tmFrom);
  2192. tmTo.tm_year -= 1900;
  2193. tmTo.tm_mon -= 1;
  2194. tbTo.time = mktime(&tmTo);
  2195. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2196. {
  2197. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2198. {
  2199. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2200. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2201. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2202. }
  2203. if(defaultTxProfile.ChargingProfileId == -1)
  2204. DEBUG_INFO("TxDefaultProfile found.\n");
  2205. else
  2206. DEBUG_INFO("TxDefaultProfile updated.\n");
  2207. // Required item
  2208. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2209. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2210. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2211. if(isUnitA)
  2212. {
  2213. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2214. 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++)
  2215. {
  2216. 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"));
  2217. 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?
  2218. 3:
  2219. 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")));
  2220. 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")));
  2221. }
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2226. 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++)
  2227. {
  2228. 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"));
  2229. 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?
  2230. 3:
  2231. 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")));
  2232. 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));
  2233. }
  2234. }
  2235. // Optional item
  2236. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2237. {
  2238. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2239. }
  2240. else
  2241. {
  2242. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2243. }
  2244. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2245. {
  2246. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2247. }
  2248. else
  2249. {
  2250. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2251. }
  2252. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2253. {
  2254. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2255. }
  2256. else
  2257. {
  2258. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2259. }
  2260. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2261. {
  2262. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2263. }
  2264. else
  2265. {
  2266. defaultTxProfile.TransactionId = -1;
  2267. }
  2268. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2269. {
  2270. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2271. }
  2272. else
  2273. {
  2274. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2275. }
  2276. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2277. {
  2278. 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")));
  2279. }
  2280. else
  2281. {
  2282. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2283. }
  2284. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2285. {
  2286. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2287. }
  2288. else
  2289. {
  2290. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2291. }
  2292. }
  2293. }
  2294. }
  2295. else
  2296. {
  2297. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2298. {
  2299. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2300. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2302. }
  2303. if(defaultTxProfile.ChargingProfileId == -1)
  2304. DEBUG_INFO("TxDefaultProfile found.\n");
  2305. else
  2306. DEBUG_INFO("TxDefaultProfile updated.\n");
  2307. // Required item
  2308. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2309. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2310. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2311. if(isUnitA)
  2312. {
  2313. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2314. 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++)
  2315. {
  2316. 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"));
  2317. 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?
  2318. 3:
  2319. 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")));
  2320. 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")));
  2321. }
  2322. }
  2323. else
  2324. {
  2325. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2326. 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++)
  2327. {
  2328. 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"));
  2329. 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?
  2330. 3:
  2331. 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")));
  2332. 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));
  2333. }
  2334. }
  2335. // Optional item
  2336. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2337. {
  2338. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2339. }
  2340. else
  2341. {
  2342. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2343. }
  2344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2345. {
  2346. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2347. }
  2348. else
  2349. {
  2350. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2351. }
  2352. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2353. {
  2354. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2355. }
  2356. else
  2357. {
  2358. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2359. }
  2360. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2361. {
  2362. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2363. }
  2364. else
  2365. {
  2366. defaultTxProfile.TransactionId = -1;
  2367. }
  2368. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2369. {
  2370. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2371. }
  2372. else
  2373. {
  2374. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2375. }
  2376. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2377. {
  2378. 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")));
  2379. }
  2380. else
  2381. {
  2382. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2383. }
  2384. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2385. {
  2386. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2387. }
  2388. else
  2389. {
  2390. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2391. }
  2392. }
  2393. }
  2394. }
  2395. json_object_put(obj);
  2396. }
  2397. fclose(fp);
  2398. /*
  2399. if(defaultTxProfile.ChargingProfileId != -1)
  2400. {
  2401. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2402. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2403. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2404. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2405. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2406. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2407. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2408. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2409. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2410. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2411. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2412. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2413. {
  2414. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2415. {
  2416. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2417. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2418. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2419. }
  2420. }
  2421. }
  2422. else
  2423. DEBUG_INFO("TxDefaultProfile not found.\n");
  2424. DEBUG_INFO("------------------------------------\n");*/
  2425. }
  2426. // Search max profile
  2427. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2428. if((access(profileFileName, F_OK))!=-1)
  2429. {
  2430. fp = fopen(profileFileName, "r");
  2431. while(getline(&line, &len, fp) != -1)
  2432. {
  2433. json_object *obj = NULL;
  2434. obj = json_tokener_parse(line);
  2435. if(is_error(obj))
  2436. {
  2437. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2438. }
  2439. else
  2440. {
  2441. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2442. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2443. )
  2444. {
  2445. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2446. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2447. )
  2448. {
  2449. struct tm tmFrom, tmTo;
  2450. struct timeb tbFrom, tbTo;
  2451. 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) &&
  2452. (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))
  2453. {
  2454. tmFrom.tm_year -= 1900;
  2455. tmFrom.tm_mon -= 1;
  2456. tbFrom.time = mktime(&tmFrom);
  2457. tmTo.tm_year -= 1900;
  2458. tmTo.tm_mon -= 1;
  2459. tbTo.time = mktime(&tmTo);
  2460. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2461. {
  2462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2463. {
  2464. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2465. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2467. }
  2468. if(maxProfile.ChargingProfileId == -1)
  2469. DEBUG_INFO("MaxProfile found.\n");
  2470. else
  2471. DEBUG_INFO("MaxProfile updated.\n");
  2472. // Required item
  2473. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2474. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2475. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2476. if(isUnitA)
  2477. {
  2478. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2479. 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++)
  2480. {
  2481. 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"));
  2482. 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?
  2483. 3:
  2484. 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")));
  2485. 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")));
  2486. }
  2487. }
  2488. else
  2489. {
  2490. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2491. 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++)
  2492. {
  2493. 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"));
  2494. 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?
  2495. 3:
  2496. 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")));
  2497. 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));
  2498. }
  2499. }
  2500. // Optional item
  2501. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2502. {
  2503. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2504. }
  2505. else
  2506. {
  2507. sprintf((char*)maxProfile.ValidFrom, " ");
  2508. }
  2509. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2510. {
  2511. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2512. }
  2513. else
  2514. {
  2515. sprintf((char*)maxProfile.ValidTo, " ");
  2516. }
  2517. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2518. {
  2519. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2520. }
  2521. else
  2522. {
  2523. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2524. }
  2525. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2526. {
  2527. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2528. }
  2529. else
  2530. {
  2531. maxProfile.TransactionId = -1;
  2532. }
  2533. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2534. {
  2535. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2536. }
  2537. else
  2538. {
  2539. maxProfile.ChargingSchedule.Duration = 86400;
  2540. }
  2541. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2542. {
  2543. 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")));
  2544. }
  2545. else
  2546. {
  2547. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2548. }
  2549. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2550. {
  2551. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2552. }
  2553. else
  2554. {
  2555. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2556. }
  2557. }
  2558. }
  2559. }
  2560. else
  2561. {
  2562. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2563. {
  2564. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2565. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2566. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2567. }
  2568. if(maxProfile.ChargingProfileId == -1)
  2569. DEBUG_INFO("MaxProfile found.\n");
  2570. else
  2571. DEBUG_INFO("MaxProfile updated.\n");
  2572. // Required item
  2573. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2574. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2575. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2576. if(isUnitA)
  2577. {
  2578. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2579. 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++)
  2580. {
  2581. 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"));
  2582. 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?
  2583. 3:
  2584. 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")));
  2585. 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")));
  2586. }
  2587. }
  2588. else
  2589. {
  2590. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2591. 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++)
  2592. {
  2593. 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"));
  2594. 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?
  2595. 3:
  2596. 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")));
  2597. 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));
  2598. }
  2599. }
  2600. // Optional item
  2601. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2602. {
  2603. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2604. }
  2605. else
  2606. {
  2607. sprintf((char*)maxProfile.ValidFrom, " ");
  2608. }
  2609. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2610. {
  2611. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2612. }
  2613. else
  2614. {
  2615. sprintf((char*)maxProfile.ValidTo, " ");
  2616. }
  2617. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2618. {
  2619. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2620. }
  2621. else
  2622. {
  2623. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2624. }
  2625. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2626. {
  2627. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2628. }
  2629. else
  2630. {
  2631. maxProfile.TransactionId = -1;
  2632. }
  2633. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2634. {
  2635. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2636. }
  2637. else
  2638. {
  2639. maxProfile.ChargingSchedule.Duration = 86400;
  2640. }
  2641. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2642. {
  2643. 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")));
  2644. }
  2645. else
  2646. {
  2647. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2648. }
  2649. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2650. {
  2651. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2652. }
  2653. else
  2654. {
  2655. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2656. }
  2657. }
  2658. }
  2659. }
  2660. json_object_put(obj);
  2661. }
  2662. fclose(fp);
  2663. /*
  2664. if(maxProfile.ChargingProfileId !=-1)
  2665. {
  2666. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2667. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2668. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2669. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2670. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2671. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2672. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2673. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2674. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2675. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2676. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2678. {
  2679. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2680. {
  2681. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2682. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2683. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2684. }
  2685. }
  2686. }
  2687. else
  2688. DEBUG_INFO("MaxProfile not found.\n");
  2689. DEBUG_INFO("------------------------------------\n");*/
  2690. }
  2691. /*
  2692. * Align found profile start schedule & periods
  2693. */
  2694. //DEBUG_INFO("====================================\n");
  2695. /*
  2696. // For local test usage, force modify found profile start schedule info
  2697. 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);
  2698. 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);
  2699. 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);
  2700. */
  2701. if(txProfile.ChargingProfileId != -1)
  2702. {
  2703. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2704. {
  2705. if(txProfile.ChargingSchedule.Duration != -1)
  2706. {
  2707. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2708. 0:
  2709. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2710. }
  2711. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2712. {
  2713. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2714. {
  2715. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2716. 0:
  2717. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2718. if(idxPeriod > 0)
  2719. {
  2720. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2721. {
  2722. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2723. }
  2724. }
  2725. }
  2726. }
  2727. }
  2728. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2729. {
  2730. if(txProfile.ChargingSchedule.Duration != -1)
  2731. {
  2732. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2733. 0:
  2734. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2735. }
  2736. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2737. {
  2738. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2739. {
  2740. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2741. 0:
  2742. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2743. if(idxPeriod > 0)
  2744. {
  2745. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2746. {
  2747. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2748. }
  2749. }
  2750. }
  2751. }
  2752. }
  2753. else
  2754. {
  2755. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2756. {
  2757. if(txProfile.ChargingSchedule.Duration != -1)
  2758. {
  2759. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2760. 0:
  2761. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2762. }
  2763. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2764. {
  2765. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2766. {
  2767. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2768. 0:
  2769. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2770. if(idxPeriod > 0)
  2771. {
  2772. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2773. {
  2774. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2775. }
  2776. }
  2777. }
  2778. }
  2779. }
  2780. else
  2781. {
  2782. if(txProfile.ChargingSchedule.Duration != -1)
  2783. {
  2784. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2785. 0:
  2786. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2787. }
  2788. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2789. {
  2790. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2791. {
  2792. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2793. 0:
  2794. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2795. if(idxPeriod > 0)
  2796. {
  2797. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2798. {
  2799. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2800. }
  2801. }
  2802. }
  2803. }
  2804. }
  2805. }
  2806. /*
  2807. DEBUG_INFO("txProfile after align.\n");
  2808. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2809. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2810. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2811. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2812. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2813. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2814. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2815. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2816. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2817. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2818. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2819. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2820. {
  2821. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2822. {
  2823. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2824. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2825. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2826. }
  2827. }*/
  2828. }
  2829. if(defaultTxProfile.ChargingProfileId != -1)
  2830. {
  2831. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2832. {
  2833. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2834. {
  2835. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2836. 0:
  2837. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2838. }
  2839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2840. {
  2841. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2842. {
  2843. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2844. 0:
  2845. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2846. if(idxPeriod > 0)
  2847. {
  2848. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2849. {
  2850. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2857. {
  2858. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2859. {
  2860. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2861. 0:
  2862. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2863. }
  2864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2865. {
  2866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2867. {
  2868. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2869. 0:
  2870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2871. if(idxPeriod > 0)
  2872. {
  2873. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2874. {
  2875. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. else
  2882. {
  2883. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2884. {
  2885. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2886. {
  2887. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2888. 0:
  2889. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2890. }
  2891. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2892. {
  2893. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2894. {
  2895. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2896. 0:
  2897. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2898. if(idxPeriod > 0)
  2899. {
  2900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2901. {
  2902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2903. }
  2904. }
  2905. }
  2906. }
  2907. }
  2908. else
  2909. {
  2910. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2911. {
  2912. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2913. 0:
  2914. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2915. }
  2916. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2917. {
  2918. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2919. {
  2920. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2921. 0:
  2922. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2923. if(idxPeriod > 0)
  2924. {
  2925. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2926. {
  2927. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2928. }
  2929. }
  2930. }
  2931. }
  2932. }
  2933. }
  2934. /*
  2935. DEBUG_INFO("defaultTxProfile after align.\n");
  2936. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2937. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2938. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2939. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2940. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2941. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2942. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2943. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2944. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2945. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2946. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2947. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2948. {
  2949. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2950. {
  2951. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2952. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2953. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2954. }
  2955. }
  2956. DEBUG_INFO("------------------------------------\n");*/
  2957. }
  2958. if(maxProfile.ChargingProfileId != -1)
  2959. {
  2960. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2961. {
  2962. if(maxProfile.ChargingSchedule.Duration != -1)
  2963. {
  2964. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2965. 0:
  2966. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2967. }
  2968. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2969. {
  2970. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2971. {
  2972. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2973. 0:
  2974. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2975. if(idxPeriod > 0)
  2976. {
  2977. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2978. {
  2979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2980. }
  2981. }
  2982. }
  2983. }
  2984. }
  2985. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2986. {
  2987. if(maxProfile.ChargingSchedule.Duration != -1)
  2988. {
  2989. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2990. 0:
  2991. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2992. }
  2993. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2994. {
  2995. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2996. {
  2997. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2998. 0:
  2999. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3000. if(idxPeriod > 0)
  3001. {
  3002. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3003. {
  3004. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3005. }
  3006. }
  3007. }
  3008. }
  3009. }
  3010. else
  3011. {
  3012. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3013. {
  3014. if(maxProfile.ChargingSchedule.Duration != -1)
  3015. {
  3016. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3017. 0:
  3018. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3019. }
  3020. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3021. {
  3022. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3023. {
  3024. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3025. 0:
  3026. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3027. if(idxPeriod > 0)
  3028. {
  3029. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3030. {
  3031. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. else
  3038. {
  3039. if(maxProfile.ChargingSchedule.Duration != -1)
  3040. {
  3041. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3042. 0:
  3043. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3044. }
  3045. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3046. {
  3047. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3048. {
  3049. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3050. 0:
  3051. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3052. if(idxPeriod > 0)
  3053. {
  3054. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3055. {
  3056. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3057. }
  3058. }
  3059. }
  3060. }
  3061. }
  3062. }
  3063. /*
  3064. DEBUG_INFO("MaxProfile after align.\n");
  3065. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3066. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3067. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3068. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3069. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3070. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3071. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3072. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3073. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3074. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3075. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3076. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3077. {
  3078. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3079. {
  3080. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3081. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3082. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3083. }
  3084. }
  3085. DEBUG_INFO("------------------------------------\n");*/
  3086. }
  3087. /*
  3088. * Merge to conposite schedule
  3089. */
  3090. //DEBUG_INFO("====================================\n");
  3091. // Find each profile period quantity
  3092. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3093. {
  3094. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3095. limitMax = idx+1;
  3096. }
  3097. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3098. {
  3099. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3100. limitDef = idx+1;
  3101. }
  3102. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3103. {
  3104. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3105. limitTx = idx+1;
  3106. }
  3107. // TxProfile found, composite schedule based on it
  3108. if(txProfile.ChargingProfileId != -1)
  3109. {
  3110. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3111. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3112. {
  3113. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3114. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3115. (txProfile.ChargingSchedule.Duration > 0))
  3116. {
  3117. if(maxProfile.ChargingProfileId != -1)
  3118. {
  3119. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3120. {
  3121. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3122. {
  3123. if((maxProfile.ChargingSchedule.Duration > 0))
  3124. {
  3125. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3126. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3127. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3128. }
  3129. else
  3130. {
  3131. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3132. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3133. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3134. }
  3135. }
  3136. if(idxMaxPeriod == (limitMax-1))
  3137. {
  3138. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3139. {
  3140. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3141. {
  3142. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3143. compositePeriodIdx++;
  3144. }
  3145. else
  3146. {
  3147. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3148. }
  3149. }
  3150. }
  3151. }
  3152. }
  3153. else
  3154. {
  3155. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3156. {
  3157. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3158. compositePeriodIdx++;
  3159. }
  3160. else
  3161. {
  3162. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3163. }
  3164. }
  3165. }
  3166. if(idxTxPeriod == (limitTx-1))
  3167. {
  3168. if(defaultTxProfile.ChargingProfileId != -1)
  3169. {
  3170. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3171. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3172. {
  3173. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3174. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3175. (defaultTxProfile.ChargingSchedule.Duration>0))
  3176. {
  3177. if(maxProfile.ChargingProfileId != -1)
  3178. {
  3179. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3180. {
  3181. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3182. {
  3183. if((maxProfile.ChargingSchedule.Duration > 0))
  3184. {
  3185. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3186. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3187. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3188. }
  3189. else
  3190. {
  3191. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3192. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3193. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3194. }
  3195. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3196. {
  3197. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3198. {
  3199. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3200. compositePeriodIdx++;
  3201. }
  3202. else
  3203. {
  3204. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3205. }
  3206. }
  3207. // Delete duplicate period
  3208. if(compositePeriodIdx > 1)
  3209. {
  3210. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3211. {
  3212. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3213. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3214. compositePeriodIdx -= 1;
  3215. }
  3216. }
  3217. }
  3218. else
  3219. {
  3220. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3221. {
  3222. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3223. compositePeriodIdx++;
  3224. }
  3225. else
  3226. {
  3227. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3228. }
  3229. break;
  3230. }
  3231. }
  3232. }
  3233. else
  3234. {
  3235. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3236. {
  3237. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3238. compositePeriodIdx++;
  3239. }
  3240. else
  3241. {
  3242. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3243. }
  3244. }
  3245. }
  3246. }
  3247. }
  3248. }
  3249. }
  3250. }
  3251. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3252. else if(defaultTxProfile.ChargingProfileId != -1)
  3253. {
  3254. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3255. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3256. {
  3257. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3258. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3259. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3260. {
  3261. if(maxProfile.ChargingProfileId != -1)
  3262. {
  3263. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3264. {
  3265. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3266. {
  3267. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3268. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3269. if((maxProfile.ChargingSchedule.Duration > 0))
  3270. {
  3271. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3272. }
  3273. else
  3274. {
  3275. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3276. }
  3277. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3278. {
  3279. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3280. {
  3281. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3282. compositePeriodIdx++;
  3283. }
  3284. else
  3285. {
  3286. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3287. }
  3288. }
  3289. // Delete duplicate period
  3290. if(compositePeriodIdx > 1)
  3291. {
  3292. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3293. {
  3294. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3295. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3296. compositePeriodIdx -= 1;
  3297. }
  3298. }
  3299. }
  3300. else
  3301. {
  3302. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3303. {
  3304. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3305. compositePeriodIdx++;
  3306. }
  3307. else
  3308. {
  3309. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3310. }
  3311. break;
  3312. }
  3313. }
  3314. }
  3315. else
  3316. {
  3317. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3318. {
  3319. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3320. compositePeriodIdx++;
  3321. }
  3322. else
  3323. {
  3324. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3325. }
  3326. }
  3327. }
  3328. }
  3329. }
  3330. // Fill other period by MaxProfile
  3331. if(maxProfile.ChargingProfileId != -1)
  3332. {
  3333. if(compositePeriodIdx==0)
  3334. {
  3335. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3336. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3337. {
  3338. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3339. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3340. (maxProfile.ChargingSchedule.Duration > 0))
  3341. {
  3342. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3343. {
  3344. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3345. compositePeriodIdx++;
  3346. }
  3347. else
  3348. {
  3349. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3350. }
  3351. }
  3352. }
  3353. }
  3354. else
  3355. {
  3356. int lastCompositePeriodIdx = compositePeriodIdx;
  3357. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3358. {
  3359. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3360. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3361. (maxProfile.ChargingSchedule.Duration > 0))
  3362. {
  3363. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3364. {
  3365. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3366. {
  3367. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3368. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3369. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3370. }
  3371. else
  3372. {
  3373. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3374. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3375. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3376. }
  3377. }
  3378. if(tmpPeriod.Limit != -1)
  3379. {
  3380. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3381. {
  3382. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3383. {
  3384. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3385. compositePeriodIdx++;
  3386. }
  3387. else
  3388. {
  3389. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3390. }
  3391. }
  3392. // Delete duplicate period
  3393. if(compositePeriodIdx > 1)
  3394. {
  3395. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3396. {
  3397. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3398. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3399. compositePeriodIdx -= 1;
  3400. }
  3401. }
  3402. }
  3403. }
  3404. }
  3405. }
  3406. }
  3407. compositeProfile.ChargingSchedule.Duration = durationReq;
  3408. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3409. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3410. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3411. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3412. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3413. {
  3414. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3415. {
  3416. compositeProfile.ChargingProfileId = 1;
  3417. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3418. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3419. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3420. }
  3421. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3422. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3423. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3424. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3425. }
  3426. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3427. if(line)
  3428. free(line);
  3429. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3430. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3431. }
  3432. //==========================================
  3433. // Init all share memory
  3434. //==========================================
  3435. int InitShareMemory()
  3436. {
  3437. int result = PASS;
  3438. int MeterSMId;
  3439. //creat ShmSysConfigAndInfo
  3440. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3441. {
  3442. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3443. result = FAIL;
  3444. }
  3445. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3446. {
  3447. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3448. result = FAIL;
  3449. }
  3450. else
  3451. {}
  3452. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3453. {
  3454. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3455. result = FAIL;
  3456. }
  3457. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3458. {
  3459. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3460. result = FAIL;
  3461. }
  3462. else
  3463. {}
  3464. //creat ShmPsuData
  3465. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3466. {
  3467. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3468. result = FAIL;
  3469. }
  3470. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3471. {
  3472. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3473. result = FAIL;
  3474. }
  3475. else
  3476. {}
  3477. //link ShmOCPP16Data
  3478. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3479. {
  3480. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3481. result = FAIL;
  3482. }
  3483. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3484. {
  3485. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3486. result = FAIL;
  3487. }
  3488. else
  3489. {}
  3490. //creat ShmOCPP16DataPH
  3491. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3492. {
  3493. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3494. result = FAIL;
  3495. }
  3496. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3497. {
  3498. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3499. result = FAIL;
  3500. }
  3501. else
  3502. {}
  3503. /****************************** For Initial Settings************************************************/
  3504. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3505. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3506. // allocate Configuration memory address
  3507. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3508. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3509. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3510. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3511. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3512. //offline MeterValue Interval
  3513. TempMeterValueInterval = 0;
  3514. return result;
  3515. }
  3516. int ProcessShareMemory()
  3517. {
  3518. int result = PASS;
  3519. if(InitShareMemory() == FAIL)
  3520. {
  3521. DEBUG_ERROR("InitShareMemory NG\n");
  3522. if(ShmStatusCodeData!=NULL)
  3523. {
  3524. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3525. }
  3526. result = FAIL;
  3527. }
  3528. // Model name parsing
  3529. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3530. {
  3531. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3532. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3533. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3534. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3535. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3536. ) // 'D' means DC
  3537. {
  3538. // DO series
  3539. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3540. {
  3541. SystemInitial += 1;
  3542. gunTotalNumber += 1;
  3543. gunType[gun_index] = GUN_TYPE_DO;
  3544. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3545. {
  3546. case Gun_Type_Chademo:
  3547. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3548. break;
  3549. case Gun_Type_CCS_2:
  3550. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3551. break;
  3552. case Gun_Type_GB:
  3553. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3554. break;
  3555. case Gun_Type_AC:
  3556. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3557. break;
  3558. default:
  3559. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3560. break;
  3561. }
  3562. }
  3563. }
  3564. else
  3565. {
  3566. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3567. {
  3568. SystemInitial += 1;
  3569. gunTotalNumber += 1;
  3570. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3571. {
  3572. case Gun_Type_Chademo:
  3573. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3574. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3575. break;
  3576. case Gun_Type_CCS_2:
  3577. gunType[gun_index] = GUN_TYPE_CCS;
  3578. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3579. break;
  3580. case Gun_Type_GB:
  3581. gunType[gun_index] = GUN_TYPE_GBT;
  3582. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3583. break;
  3584. case Gun_Type_AC:
  3585. gunType[gun_index] = GUN_TYPE_AC;
  3586. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3587. break;
  3588. default:
  3589. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3590. break;
  3591. }
  3592. }
  3593. }
  3594. }
  3595. else
  3596. {
  3597. DEBUG_ERROR("Model name parsing fail.\n");
  3598. result = FAIL;
  3599. }
  3600. if(result != PASS)sleep(5);
  3601. return result;
  3602. }
  3603. void checkRemoteStart(uint8_t connectorIdInt)
  3604. {
  3605. uint8_t tempIndex;
  3606. int result = PASS;
  3607. char cmdBuf[512];
  3608. //check Transaction active
  3609. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3610. {
  3611. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3612. {
  3613. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3614. }
  3615. else
  3616. {
  3617. tempIndex = connectorIdInt -1;
  3618. }
  3619. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3620. {
  3621. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3622. {
  3623. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3624. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3625. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3626. {
  3627. //Reserved
  3628. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3629. }
  3630. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3631. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3632. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3633. {
  3634. //Reserved
  3635. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3636. result = FAIL;
  3637. goto end;
  3638. }
  3639. else
  3640. {
  3641. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3642. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3643. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3644. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3645. {
  3646. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3647. result = FAIL;
  3648. goto end;
  3649. }
  3650. }//END FOR ELSE
  3651. }
  3652. }// END FOR CHAdeMO_QUANTITY
  3653. }
  3654. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3655. {
  3656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3657. {
  3658. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3659. }
  3660. else
  3661. {
  3662. tempIndex = connectorIdInt -1;
  3663. }
  3664. for (int index = 0; index < CCS_QUANTITY; index++)
  3665. {
  3666. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3667. {
  3668. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3669. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3670. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3671. {
  3672. //Reserved
  3673. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3674. }
  3675. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3676. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3677. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3678. {
  3679. //Reserved
  3680. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3681. result = FAIL;
  3682. goto end;
  3683. }
  3684. else
  3685. {
  3686. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3687. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3688. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3689. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3690. {
  3691. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3692. result = FAIL;
  3693. goto end;
  3694. }
  3695. }// END FOR ELSE
  3696. }
  3697. }// END FOR CCS_QUANTITY
  3698. }
  3699. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3700. {
  3701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3702. {
  3703. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3704. }
  3705. else
  3706. {
  3707. tempIndex = connectorIdInt -1;
  3708. }
  3709. for (int index = 0; index < GB_QUANTITY; index++)
  3710. {
  3711. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3712. {
  3713. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3714. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3715. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3716. {
  3717. //Reserved
  3718. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3719. }
  3720. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3721. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3722. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3723. {
  3724. //Reserved
  3725. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3726. result = FAIL;
  3727. goto end;
  3728. }
  3729. else
  3730. {
  3731. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3732. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3733. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3734. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3735. {
  3736. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3737. result = FAIL;
  3738. goto end;
  3739. }
  3740. }// END FOR ELSE
  3741. }
  3742. } // END FOR GB_QUANTITY
  3743. }
  3744. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3745. {
  3746. tempIndex = connectorIdInt -1;
  3747. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3748. {
  3749. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3750. {
  3751. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3752. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3753. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3754. {
  3755. //Reserved
  3756. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3757. }
  3758. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3759. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3760. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3761. {
  3762. //Reserved
  3763. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3764. result = FAIL;
  3765. goto end;
  3766. }
  3767. else
  3768. {
  3769. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3770. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3771. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3772. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3773. {
  3774. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3775. result = FAIL;
  3776. goto end;
  3777. }
  3778. }// END FOR ELSE
  3779. }
  3780. } // END FOR GB_QUANTITY
  3781. }
  3782. else
  3783. {
  3784. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3785. {
  3786. tempIndex = 2;
  3787. }
  3788. else
  3789. {
  3790. tempIndex = connectorIdInt -1;
  3791. }
  3792. for (int index = 0; index < AC_QUANTITY; index++)
  3793. {
  3794. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3795. {
  3796. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3797. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3798. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3799. {
  3800. //Reserved
  3801. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3802. }
  3803. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3804. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3805. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3806. {
  3807. //Reserved
  3808. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3809. result = FAIL;
  3810. goto end;
  3811. }
  3812. else
  3813. {
  3814. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3815. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3816. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3817. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3818. {
  3819. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3820. result = FAIL;
  3821. goto end;
  3822. }
  3823. }//END FOR ELSE
  3824. }
  3825. }// END FOR AC_QUANTITY
  3826. }
  3827. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3828. {
  3829. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3830. {
  3831. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3832. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3833. {
  3834. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3835. system(cmdBuf);
  3836. }
  3837. }
  3838. else
  3839. {
  3840. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3841. result = FAIL;
  3842. }
  3843. }
  3844. end:
  3845. if(result == PASS)
  3846. {
  3847. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3848. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3849. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3850. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3852. }
  3853. }
  3854. void CheckSystemValue(void)
  3855. {
  3856. char filenmae[100]={0};
  3857. char str[100]={0};
  3858. int tempIndex = 0;
  3859. //===============================
  3860. // send Heartbeat
  3861. //===============================
  3862. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3863. {
  3864. //parameter for test
  3865. sendHeartbeatRequest(0);
  3866. //==============================================
  3867. // Reset Waiting Time
  3868. //==============================================
  3869. HeartBeatWithNOResponse += 2;
  3870. }
  3871. //===============================
  3872. // Credit deduct report
  3873. //===============================
  3874. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3875. {
  3876. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3877. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3878. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3879. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3880. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3881. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3882. }
  3883. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3884. {
  3885. OCPP_query_deduct_info();
  3886. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3887. }
  3888. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3889. {
  3890. // ClockAlign MeterValue
  3891. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3892. {
  3893. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3894. {
  3895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3896. {
  3897. tempIndex = ((gun_index==2) ? 1: 0);
  3898. }
  3899. else
  3900. {
  3901. tempIndex = gun_index;
  3902. }
  3903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3904. {
  3905. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3906. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3907. {
  3908. reqClockAlignMeter[gun_index] = 1;
  3909. }
  3910. }// End for CHAdeMO
  3911. }
  3912. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3913. {
  3914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3915. {
  3916. tempIndex = ((gun_index==2) ? 1: 0);
  3917. }
  3918. else
  3919. {
  3920. tempIndex = gun_index;
  3921. }
  3922. for (int index = 0; index < CCS_QUANTITY; index++)
  3923. {
  3924. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3925. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3926. {
  3927. reqClockAlignMeter[gun_index] = 1;
  3928. }
  3929. } // End for CCS
  3930. }
  3931. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3932. {
  3933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3934. {
  3935. tempIndex = ((gun_index==2) ? 1: 0);
  3936. }
  3937. else
  3938. {
  3939. tempIndex = gun_index;
  3940. }
  3941. for (int index = 0; index < GB_QUANTITY; index++)
  3942. {
  3943. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3944. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3945. {
  3946. reqClockAlignMeter[gun_index] = 1;
  3947. }
  3948. }// End for GB
  3949. }
  3950. else if(gunType[gun_index] == GUN_TYPE_DO)
  3951. {
  3952. tempIndex = gun_index;
  3953. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3954. {
  3955. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3956. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3957. {
  3958. reqClockAlignMeter[gun_index] = 1;
  3959. }
  3960. }
  3961. }
  3962. else
  3963. {
  3964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3965. {
  3966. tempIndex = 2;
  3967. }
  3968. else
  3969. {
  3970. tempIndex = gun_index;
  3971. }
  3972. for (int index = 0; index < AC_QUANTITY; index++)
  3973. {
  3974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3975. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3976. {
  3977. reqClockAlignMeter[gun_index] = 1;
  3978. }
  3979. }//End for AC
  3980. }
  3981. }
  3982. }
  3983. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3984. {
  3985. //==========================================
  3986. // Check remote start without connector id
  3987. //==========================================
  3988. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3989. {
  3990. int connectorIdInt = -1;
  3991. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3992. {
  3993. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3994. {
  3995. connectorIdInt = (gun_index+1);
  3996. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3997. checkRemoteStart(connectorIdInt);
  3998. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3999. break;
  4000. }
  4001. }
  4002. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4003. {
  4004. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4005. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4006. }
  4007. }
  4008. //==========================================
  4009. // csu trigger DataTransferReq
  4010. //==========================================
  4011. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4012. {
  4013. sendDataTransferRequest(gun_index);
  4014. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4015. }
  4016. //===============================
  4017. // CSU Trigger Authorize Request
  4018. //===============================
  4019. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4020. {
  4021. sendAuthorizeRequest(0);
  4022. authorizeRetryTimes = authorizeRetryTimes + 1;
  4023. if(authorizeRetryTimes < 3)
  4024. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4025. }
  4026. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4027. {
  4028. authorizeRetryTimes = 0;
  4029. SetOcppConnStatus(FALSE);
  4030. server_sign = FALSE;
  4031. }
  4032. 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))
  4033. {
  4034. sendAuthorizeRequest(0);
  4035. }
  4036. //==============================================
  4037. // Charger start transaction
  4038. //==============================================
  4039. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4040. {
  4041. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4042. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4043. sendStartTransactionRequest(gun_index);
  4044. refreshStartTimer(&clientTime.StartTransaction);
  4045. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4046. //storeTempStopTransaction(gun_index);
  4047. }
  4048. //==============================================
  4049. // Charger stop transaction
  4050. //==============================================
  4051. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4052. {
  4053. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4054. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4055. sendStopTransactionRequest(gun_index);
  4056. refreshStartTimer(&clientTime.StopTransaction);
  4057. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4058. }
  4059. //==============================================
  4060. // Charger status report
  4061. //==============================================
  4062. //--- Check Mode Change ---//
  4063. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4064. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4065. {
  4066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4067. {
  4068. tempIndex = ((gun_index==2) ? 1: 0);
  4069. }
  4070. else
  4071. {
  4072. tempIndex = gun_index;
  4073. }
  4074. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4075. {
  4076. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4077. {
  4078. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4079. {
  4080. // Sent unplug message for California pricing logic
  4081. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4082. {
  4083. uint8_t ts[20];
  4084. getNowDatetime(ts);
  4085. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4086. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4087. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4088. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4089. }
  4090. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4091. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4092. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4093. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4094. {
  4095. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4096. if((access(filenmae,F_OK))!=-1)
  4097. {
  4098. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4099. sprintf(str,"rm -f %s",filenmae);
  4100. system(str);
  4101. }
  4102. }
  4103. }
  4104. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4105. #if 1 // for TempStopTransaction
  4106. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4107. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4108. {
  4109. checkTempStopTransaction(gun_index);
  4110. }
  4111. #endif
  4112. }
  4113. }
  4114. }
  4115. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4116. {
  4117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4118. {
  4119. tempIndex = ((gun_index==2) ? 1: 0);
  4120. }
  4121. else
  4122. {
  4123. tempIndex = gun_index;
  4124. }
  4125. for (int index = 0; index < CCS_QUANTITY; index++)
  4126. {
  4127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4128. {
  4129. 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]*/ )
  4130. {
  4131. // Sent unplug message for California pricing logic
  4132. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4133. {
  4134. uint8_t ts[20];
  4135. getNowDatetime(ts);
  4136. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4137. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4138. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4139. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4140. }
  4141. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4142. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4143. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4144. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4145. {
  4146. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4147. if((access(filenmae,F_OK))!=-1)
  4148. {
  4149. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4150. sprintf(str,"rm -f %s",filenmae);
  4151. system(str);
  4152. }
  4153. }
  4154. }
  4155. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4156. #if 1 // for TempStopTransaction
  4157. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4158. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4159. {
  4160. checkTempStopTransaction(gun_index);
  4161. }
  4162. #endif
  4163. }
  4164. }
  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. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4181. {
  4182. // Sent unplug message for California pricing logic
  4183. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4184. {
  4185. uint8_t ts[20];
  4186. getNowDatetime(ts);
  4187. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4188. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4189. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4190. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4191. }
  4192. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4193. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4194. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4195. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4196. {
  4197. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4198. if((access(filenmae,F_OK))!=-1)
  4199. {
  4200. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4201. sprintf(str,"rm -f %s",filenmae);
  4202. system(str);
  4203. }
  4204. }
  4205. }
  4206. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4207. #if 1 // for TempStopTransaction
  4208. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4209. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4210. {
  4211. checkTempStopTransaction(gun_index);
  4212. }
  4213. #endif
  4214. }
  4215. }
  4216. }
  4217. else if(gunType[gun_index] == GUN_TYPE_DO)
  4218. {
  4219. tempIndex = gun_index;
  4220. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4221. {
  4222. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4223. {
  4224. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4225. {
  4226. // Sent unplug message for California pricing logic
  4227. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4228. {
  4229. uint8_t ts[20];
  4230. getNowDatetime(ts);
  4231. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4232. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4233. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4234. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4235. }
  4236. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4237. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4238. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4239. 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_IDLE))) // complete
  4240. {
  4241. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4242. if((access(filenmae,F_OK))!=-1)
  4243. {
  4244. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4245. sprintf(str,"rm -f %s",filenmae);
  4246. system(str);
  4247. }
  4248. }
  4249. }
  4250. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4251. #if 1 // for TempStopTransaction
  4252. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4253. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4254. {
  4255. checkTempStopTransaction(gun_index);
  4256. }
  4257. #endif
  4258. }
  4259. }
  4260. }
  4261. else
  4262. {
  4263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4264. {
  4265. tempIndex = 2;
  4266. }
  4267. else
  4268. {
  4269. tempIndex = gun_index;
  4270. }
  4271. for (int index = 0; index < AC_QUANTITY; index++)
  4272. {
  4273. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4274. {
  4275. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4276. {
  4277. // Sent unplug message for California pricing logic
  4278. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4279. {
  4280. uint8_t ts[20];
  4281. getNowDatetime(ts);
  4282. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4283. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4284. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4285. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4286. }
  4287. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4288. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4289. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4290. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4291. {
  4292. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4293. if((access(filenmae,F_OK))!=-1)
  4294. {
  4295. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4296. sprintf(str,"rm -f %s",filenmae);
  4297. system(str);
  4298. }
  4299. }
  4300. }
  4301. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4302. #if 1 // for TempStopTransaction
  4303. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4304. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4305. {
  4306. checkTempStopTransaction(gun_index);
  4307. }
  4308. #endif
  4309. }
  4310. }// END
  4311. }
  4312. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4313. (
  4314. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4315. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4316. )
  4317. )
  4318. {
  4319. if(SystemInitial > 0)
  4320. SystemInitial -= 1;
  4321. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4322. sendStatusNotificationRequest(gun_index);
  4323. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4324. }
  4325. //==============================================
  4326. // TCCI reader status report
  4327. //==============================================
  4328. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4329. {
  4330. reportReaderStatus(gun_index);
  4331. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4332. }
  4333. //==============================================
  4334. // CSU Trigger Smart Charging Profile
  4335. //==============================================
  4336. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4337. {
  4338. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4339. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4340. }
  4341. //==============================================
  4342. // Meter report
  4343. //==============================================
  4344. // Trigger MeterValue
  4345. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4346. {
  4347. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4348. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4349. }
  4350. // Clock-aligned Meter value
  4351. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4352. {
  4353. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4354. reqClockAlignMeter[gun_index] = 0;
  4355. }
  4356. // Sample period MeterValue
  4357. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4358. {
  4359. //check Transaction active
  4360. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4361. {
  4362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4363. {
  4364. tempIndex = ((gun_index==2) ? 1: 0);
  4365. }
  4366. else
  4367. {
  4368. tempIndex = gun_index;
  4369. }
  4370. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4371. {
  4372. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4373. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4374. {
  4375. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4376. {
  4377. reqSampleMeter[gun_index] = 1;
  4378. }
  4379. }
  4380. }// End for CHAdeMO
  4381. }
  4382. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4383. {
  4384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4385. {
  4386. tempIndex = ((gun_index==2) ? 1: 0);
  4387. }
  4388. else
  4389. {
  4390. tempIndex = gun_index;
  4391. }
  4392. for (int index = 0; index < CCS_QUANTITY; index++)
  4393. {
  4394. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4395. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4396. {
  4397. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4398. {
  4399. reqSampleMeter[gun_index] = 1;
  4400. }
  4401. }
  4402. } // End for CCS
  4403. }
  4404. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4405. {
  4406. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4407. {
  4408. tempIndex = ((gun_index==2) ? 1: 0);
  4409. }
  4410. else
  4411. {
  4412. tempIndex = gun_index;
  4413. }
  4414. for (int index = 0; index < GB_QUANTITY; index++)
  4415. {
  4416. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4417. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4418. {
  4419. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4420. {
  4421. reqSampleMeter[gun_index] = 1;
  4422. }
  4423. }
  4424. }// End for GB
  4425. }
  4426. else if(gunType[gun_index] == GUN_TYPE_DO)
  4427. {
  4428. tempIndex = gun_index;
  4429. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4430. {
  4431. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4432. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4433. {
  4434. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4435. {
  4436. reqSampleMeter[gun_index] = 1;
  4437. }
  4438. }
  4439. }
  4440. }
  4441. else
  4442. {
  4443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4444. {
  4445. tempIndex = 2;
  4446. }
  4447. else
  4448. {
  4449. tempIndex = gun_index;
  4450. }
  4451. for (int index = 0; index < AC_QUANTITY; index++)
  4452. {
  4453. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4454. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4455. {
  4456. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4457. {
  4458. reqSampleMeter[gun_index] = 1;
  4459. }
  4460. }
  4461. }//End for AC
  4462. }
  4463. if(reqSampleMeter[gun_index] == 1)
  4464. {
  4465. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4466. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4467. //storeTempStopTransaction(gun_index);
  4468. reqSampleMeter[gun_index] = 0;
  4469. }
  4470. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4471. }
  4472. //==============================================
  4473. // Check Connector reserved
  4474. //==============================================
  4475. //===============================
  4476. // Check if Reserve is expired
  4477. //===============================
  4478. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4479. {
  4480. double diff_t;
  4481. struct tm tp;
  4482. // current time
  4483. time_t t = time(NULL);
  4484. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4485. tp.tm_isdst = -1;
  4486. time_t utc = mktime(&tp);
  4487. diff_t = difftime(utc, t);
  4488. if(diff_t <= 0)
  4489. {
  4490. DEBUG_INFO("reserve expired.\n");
  4491. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4492. }
  4493. }//END OF Check if Reserve is expired
  4494. //==========================================
  4495. // csu trigger FirmwareStatusNotificationReq
  4496. //==========================================
  4497. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4498. {
  4499. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4500. }
  4501. //==========================================
  4502. // csu trigger DiagnosticsStatusNotificationReq
  4503. //==========================================
  4504. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4505. {
  4506. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4507. }
  4508. //==========================================
  4509. // csu trigger CancelReservationConf
  4510. //==========================================
  4511. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4512. {
  4513. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4514. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4515. }
  4516. //==========================================
  4517. // csu trigger ChangeAvailabilityConf
  4518. //==========================================
  4519. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4520. {
  4521. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4522. }
  4523. //==========================================
  4524. // csu trigger UnlockConnectorConf
  4525. //==========================================
  4526. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4527. {
  4528. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4529. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4530. }
  4531. //==========================================
  4532. // csu trigger ReserveNowConf
  4533. //==========================================
  4534. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4535. {
  4536. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4537. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4538. }
  4539. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4540. {
  4541. sendSignCertificateRequest();
  4542. }
  4543. }
  4544. }
  4545. //==========================================
  4546. // send request routine
  4547. //==========================================
  4548. int sendAuthorizeRequest(int gun_index)
  4549. {
  4550. mtrace();
  4551. int result = FAIL;
  4552. char message[100]={0};
  4553. char guid[37];
  4554. char tempdata[65]={0};
  4555. DEBUG_INFO("sendAuthorizeRequest...\n");
  4556. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4557. //Local Authorize
  4558. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4559. {
  4560. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4561. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4562. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4563. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4564. result = PASS;
  4565. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4566. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4567. authorizeRetryTimes = 0;
  4568. return result;
  4569. }
  4570. 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))||
  4571. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4572. {
  4573. // Query from cache
  4574. DEBUG_INFO("Authorize from cache.\n");
  4575. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4576. // Query from list
  4577. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4578. {
  4579. DEBUG_INFO("Authorize from list.\n");
  4580. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4581. }
  4582. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4583. {
  4584. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4585. {
  4586. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4587. }
  4588. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4589. {
  4590. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4591. }
  4592. if(!GetOcppConnStatus())
  4593. {
  4594. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4595. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4596. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4597. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4598. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4599. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4600. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4601. authorizeRetryTimes = 0;
  4602. return result;
  4603. }
  4604. }
  4605. else
  4606. {
  4607. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4608. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4609. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4610. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4611. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4612. else
  4613. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4614. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4615. result = PASS;
  4616. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4617. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4618. authorizeRetryTimes = 0;
  4619. return result;
  4620. }
  4621. }
  4622. //initialize struct Authorize
  4623. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4624. //get data from shared memory
  4625. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4626. random_uuid(guid);
  4627. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4628. LWS_Send(message);
  4629. sprintf(tempdata, "Authorize,%d", gun_index);
  4630. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4631. {
  4632. result = PASS;
  4633. DEBUG_INFO("Authorize mapItem pass\n");
  4634. }
  4635. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4636. return result;
  4637. }
  4638. int sendBootNotificationRequest(void)
  4639. {
  4640. mtrace();
  4641. int result = FAIL;
  4642. char message[500]={0}, payload[700]={0};
  4643. char guid[37]={0};
  4644. char tempdata[65]={0};
  4645. // Fill BootNotification fields
  4646. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4647. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4648. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4649. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4650. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4651. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4652. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4653. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4654. ShmOCPP16DataPH->ChargeBoxId
  4655. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4656. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4657. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4658. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4659. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4660. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4661. random_uuid(guid);
  4662. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4663. LWS_Send(message);
  4664. sprintf(tempdata, "BootNotification,0");
  4665. 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*/)
  4666. {
  4667. result = PASS;
  4668. }
  4669. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4670. strcpy(queuedata,message);
  4671. return result;
  4672. }
  4673. int sendDataTransferRequest(int gun_index)
  4674. {
  4675. mtrace();
  4676. char message[1000]={0};
  4677. char guid[37]={0};
  4678. char tempdata[65]={0};
  4679. int result = FAIL;
  4680. random_uuid(guid);
  4681. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4682. MESSAGE_TYPE_CALL,
  4683. guid,
  4684. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4685. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4686. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4687. LWS_Send(message);
  4688. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4689. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4690. {
  4691. result = PASS;
  4692. DEBUG_INFO("DataTransfer mapItem pass\n");
  4693. }
  4694. return result;
  4695. }
  4696. int sendDiagnosticsStatusNotificationRequest(char *status)
  4697. {
  4698. mtrace();
  4699. int result = FAIL;
  4700. char message[110]={0};
  4701. char guid[37]={0};
  4702. char tempdata[65]={0};
  4703. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4704. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4705. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4706. random_uuid(guid);
  4707. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4708. LWS_SendNow(message);
  4709. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4710. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4711. {
  4712. result = PASS;
  4713. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4714. }
  4715. //#ifdef SystemLogMessage
  4716. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4717. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4718. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4719. //#endif
  4720. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4721. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4722. //record status
  4723. if(strcmp(status,"Idle")==0)
  4724. {
  4725. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4726. }
  4727. else if(strcmp(status,"Uploaded")==0)
  4728. {
  4729. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4730. }
  4731. else if(strcmp(status,"UploadFailed")==0)
  4732. {
  4733. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4734. }
  4735. else if(strcmp(status,"Uploading")==0)
  4736. {
  4737. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4738. }
  4739. return result;
  4740. }
  4741. int sendFirmwareStatusNotificationRequest(char *status)
  4742. {
  4743. mtrace();
  4744. int result = FAIL;
  4745. char message[110]={0};
  4746. char guid[37]={0};
  4747. char tempdata[65]={0};
  4748. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4749. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4750. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4751. random_uuid(guid);
  4752. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4753. LWS_SendNow(message);
  4754. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4755. 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*/)
  4756. {
  4757. result = PASS;
  4758. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4759. }
  4760. //#ifdef SystemLogMessage
  4761. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4762. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4763. //#endif
  4764. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4765. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4766. //record status
  4767. if(strcmp(status,"Downloaded")==0)
  4768. {
  4769. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4770. }
  4771. else if(strcmp(status,"DownloadFailed")==0)
  4772. {
  4773. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4774. }
  4775. else if(strcmp(status,"Downloading")==0)
  4776. {
  4777. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4778. }
  4779. else if(strcmp(status,"Idle")==0)
  4780. {
  4781. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4782. }
  4783. else if(strcmp(status,"InstallationFailed")==0)
  4784. {
  4785. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4786. }
  4787. else if(strcmp(status,"Installing")==0)
  4788. {
  4789. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4790. }
  4791. else if(strcmp(status,"Installed")==0)
  4792. {
  4793. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4794. }
  4795. return result;
  4796. }
  4797. int sendHeartbeatRequest(int gun_index)
  4798. {
  4799. mtrace();
  4800. int result = FAIL;
  4801. char message[80]={0};
  4802. char guid[37]={0};
  4803. char tempdata[65]={0};
  4804. random_uuid(guid);
  4805. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4806. , MESSAGE_TYPE_CALL
  4807. , guid );
  4808. LWS_Send(message);
  4809. sprintf(tempdata, "Heartbeat,%d", 0);
  4810. 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*/)
  4811. {
  4812. result = PASS;
  4813. }
  4814. return result;
  4815. }
  4816. int sendStartTransactionRequest(int gun_index)
  4817. {
  4818. mtrace();
  4819. int result = FAIL;
  4820. char message[250]={0};
  4821. char guid[37]={0};
  4822. struct timeval tmnow;
  4823. struct tm *tm;
  4824. char buf[28];//, usec_buf[6];
  4825. char tempdata[65]={0};
  4826. int tempIndex = 0;
  4827. DEBUG_INFO("sendStartTransactionRequest...\n");
  4828. gettimeofday(&tmnow, NULL);
  4829. time_t t;
  4830. t = time(NULL);
  4831. /*UTC time and date*/
  4832. tm = gmtime(&t);
  4833. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4834. #if 0 // remove temporally
  4835. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4836. strcat(buf,".");
  4837. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4838. strcat(buf,usec_buf);
  4839. #endif
  4840. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4841. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4842. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4843. // clear StartTransaction Response
  4844. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4845. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4846. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4847. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4848. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4849. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4850. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4851. {
  4852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4853. {
  4854. tempIndex = ((gun_index==2) ? 1: 0);
  4855. }
  4856. else
  4857. {
  4858. tempIndex = gun_index;
  4859. }
  4860. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4861. {
  4862. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4863. {
  4864. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4865. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4866. }
  4867. }
  4868. }
  4869. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4870. {
  4871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4872. {
  4873. tempIndex = ((gun_index==2) ? 1: 0);
  4874. }
  4875. else
  4876. {
  4877. tempIndex = gun_index;
  4878. }
  4879. for (int index = 0; index < CCS_QUANTITY; index++)
  4880. {
  4881. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4882. {
  4883. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4884. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4885. }
  4886. }
  4887. }
  4888. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4889. {
  4890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4891. {
  4892. tempIndex = ((gun_index==2) ? 1: 0);
  4893. }
  4894. else
  4895. {
  4896. tempIndex = gun_index;
  4897. }
  4898. for (int index = 0; index < GB_QUANTITY; index++)
  4899. {
  4900. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4901. {
  4902. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4903. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4904. }
  4905. }
  4906. }
  4907. else if(gunType[gun_index] == GUN_TYPE_DO)
  4908. {
  4909. tempIndex = gun_index;
  4910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4911. {
  4912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4913. {
  4914. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4915. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4916. }
  4917. }
  4918. }
  4919. else
  4920. {
  4921. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4922. {
  4923. tempIndex = 2;
  4924. }
  4925. else
  4926. {
  4927. tempIndex = gun_index;
  4928. }
  4929. for (int index = 0; index < AC_QUANTITY; index++)
  4930. {
  4931. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4932. {
  4933. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4934. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4935. }
  4936. }
  4937. }
  4938. random_uuid(guid);
  4939. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4940. {
  4941. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4942. , gun_index +1
  4943. , MESSAGE_TYPE_CALL
  4944. , guid
  4945. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4946. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4947. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4948. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4949. }
  4950. else
  4951. {
  4952. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4953. , gun_index +1
  4954. , MESSAGE_TYPE_CALL
  4955. , guid
  4956. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4957. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4958. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4959. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4960. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4961. }
  4962. #if 1
  4963. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4964. 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*/)
  4965. {
  4966. result = PASS;
  4967. }
  4968. #endif
  4969. strcpy(queuedata, message);
  4970. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4971. OCPP_insert_transaction_msg(YES, queuedata);
  4972. return result;
  4973. }
  4974. int sendStatusNotificationRequest(int gun_index)
  4975. {
  4976. mtrace();
  4977. int result = FAIL;
  4978. char message[600]={0};
  4979. char guid[37];
  4980. int currentStatus = 0;
  4981. struct timeval tmnow;
  4982. struct tm *tm;
  4983. char buf[28];//, usec_buf[6];
  4984. char tempdata[65]={0};
  4985. int tempIndex = 0;
  4986. uint8_t isStateChanged = TRUE;
  4987. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4988. gettimeofday(&tmnow, NULL);
  4989. time_t t;
  4990. t = time(NULL);
  4991. /*UTC time and date*/
  4992. tm = gmtime(&t);
  4993. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4994. #if 0 // remove temporally
  4995. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4996. strcat(buf,".");
  4997. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4998. strcat(buf,usec_buf);
  4999. #endif
  5000. //printf("%s",buf);
  5001. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5002. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5003. // it's option
  5004. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5005. /*
  5006. enum _SYSTEM_STATUS
  5007. {
  5008. S_BOOTING = 0,
  5009. S_IDLE, = 1
  5010. S_AUTHORIZING, =2
  5011. S_REASSIGN_CHECK, =3
  5012. S_REASSIGN, =4
  5013. S_PRECHARGE, =5
  5014. S_PREPARING_FOR_EV, =6
  5015. S_PREPARING_FOR_EVSE, =7
  5016. S_CHARGING, =8
  5017. S_TERMINATING, =9
  5018. S_COMPLETE, =10
  5019. S_ALARM, =11
  5020. S_FAULT =12
  5021. }
  5022. */
  5023. //check Transaction active
  5024. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5025. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5026. {
  5027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5028. {
  5029. tempIndex = ((gun_index==2) ? 1: 0);
  5030. }
  5031. else
  5032. {
  5033. tempIndex = gun_index;
  5034. }
  5035. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5036. {
  5037. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5038. {
  5039. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5040. {
  5041. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5042. {
  5043. currentStatus = Preparing; //OCPP Status: Preparing
  5044. }
  5045. else
  5046. {
  5047. currentStatus = Available; //OCPP Status: Available
  5048. }
  5049. }
  5050. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5051. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5052. ) //S_PRECHARGE
  5053. {
  5054. currentStatus = Preparing; //OCPP Status: Preparing
  5055. }
  5056. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5057. {
  5058. currentStatus = Charging; //OCPP Status: Charging
  5059. }
  5060. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5061. {
  5062. currentStatus = Finishing; //OCPP Status: Finishing
  5063. }
  5064. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5065. {
  5066. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5067. }
  5068. 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
  5069. {
  5070. currentStatus = Unavailable; //OCPP Status: Unavailable
  5071. }
  5072. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5073. {
  5074. currentStatus = Faulted; //OCPP Status: Faulted
  5075. }
  5076. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5077. {
  5078. currentStatus = Reserved; //OCPP Status: Reserved
  5079. }
  5080. } //end of the same index
  5081. }//end of for CHAdeMO_QUANTITY
  5082. }
  5083. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5084. {
  5085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5086. {
  5087. tempIndex = ((gun_index==2) ? 1: 0);
  5088. }
  5089. else
  5090. {
  5091. tempIndex = gun_index;
  5092. }
  5093. for (int index = 0; index < CCS_QUANTITY; index++)
  5094. {
  5095. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5096. {
  5097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5098. {
  5099. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5100. {
  5101. currentStatus = Preparing; //OCPP Status: Preparing
  5102. }
  5103. else
  5104. {
  5105. currentStatus = Available; //OCPP Status: Available
  5106. }
  5107. }
  5108. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5109. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5110. ) //S_PRECHARGE
  5111. {
  5112. currentStatus = Preparing; //OCPP Status: Preparing
  5113. }
  5114. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5115. {
  5116. currentStatus = Charging; //OCPP Status: Charging
  5117. }
  5118. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5119. {
  5120. currentStatus = Finishing; //OCPP Status: Finishing
  5121. }
  5122. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5123. {
  5124. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5125. }
  5126. 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
  5127. {
  5128. currentStatus = Unavailable; //OCPP Status : Unavailable
  5129. }
  5130. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5131. {
  5132. currentStatus = Faulted; //OCPP Status: Faulted
  5133. }
  5134. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5135. {
  5136. currentStatus = Reserved; //OCPP Status: Reserved
  5137. }
  5138. } //end of the same index
  5139. } // end of for CCS_QUANTITY
  5140. }
  5141. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5142. {
  5143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5144. {
  5145. tempIndex = ((gun_index==2) ? 1: 0);
  5146. }
  5147. else
  5148. {
  5149. tempIndex = gun_index;
  5150. }
  5151. for (int index = 0; index < GB_QUANTITY; index++)
  5152. {
  5153. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5154. {
  5155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5156. {
  5157. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5158. {
  5159. currentStatus = Preparing; //OCPP Status: Preparing
  5160. }
  5161. else
  5162. {
  5163. currentStatus = Available; //OCPP Status: Available
  5164. }
  5165. }
  5166. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5167. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5168. ) //S_PRECHARGE
  5169. {
  5170. currentStatus = Preparing; //OCPP Status: Preparing
  5171. }
  5172. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5173. {
  5174. currentStatus = Charging; //OCPP Status: Charging
  5175. }
  5176. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5177. {
  5178. currentStatus = Finishing; //OCPP Status: Finishing
  5179. }
  5180. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5181. {
  5182. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5183. }
  5184. 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
  5185. {
  5186. currentStatus = Unavailable; //OCPP Status: Unavailable
  5187. }
  5188. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5189. {
  5190. currentStatus = Faulted; //OCPP Status: Faulted
  5191. }
  5192. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5193. {
  5194. currentStatus = Reserved; //OCPP Status: Reserved
  5195. }
  5196. } //end of the same index
  5197. } // end of for GB_QUANTITY
  5198. }
  5199. else if(gunType[gun_index] == GUN_TYPE_DO)
  5200. {
  5201. tempIndex = gun_index;
  5202. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5203. {
  5204. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5205. {
  5206. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5207. {
  5208. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5209. {
  5210. currentStatus = Preparing; //OCPP Status: Preparing
  5211. }
  5212. else
  5213. {
  5214. currentStatus = Available; //OCPP Status: Available
  5215. }
  5216. }
  5217. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5218. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5219. ) //S_PRECHARGE
  5220. {
  5221. currentStatus = Preparing; //OCPP Status: Preparing
  5222. }
  5223. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5224. {
  5225. currentStatus = Charging; //OCPP Status: Charging
  5226. }
  5227. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5228. {
  5229. currentStatus = Finishing; //OCPP Status: Finishing
  5230. }
  5231. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5232. {
  5233. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5234. }
  5235. 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
  5236. {
  5237. currentStatus = Unavailable; //OCPP Status: Unavailable
  5238. }
  5239. 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
  5240. {
  5241. currentStatus = Faulted; //OCPP Status: Faulted
  5242. }
  5243. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5244. {
  5245. currentStatus = Reserved; //OCPP Status: Reserved
  5246. }
  5247. } //end of the same index
  5248. }
  5249. }
  5250. else
  5251. {
  5252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5253. {
  5254. tempIndex = 2;
  5255. }
  5256. else
  5257. {
  5258. tempIndex = gun_index;
  5259. }
  5260. for (int index = 0; index < AC_QUANTITY; index++)
  5261. {
  5262. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5263. {
  5264. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5265. {
  5266. 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))
  5267. {
  5268. currentStatus = Preparing; //OCPP Status: Preparing
  5269. }
  5270. else
  5271. {
  5272. currentStatus = Available; //OCPP Status: Available
  5273. }
  5274. }
  5275. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5276. {
  5277. currentStatus = Preparing; //OCPP Status: Preparing
  5278. }
  5279. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5280. {
  5281. currentStatus = Charging; //OCPP Status: Charging
  5282. }
  5283. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5284. {
  5285. currentStatus = Finishing; //OCPP Status: Finishing
  5286. }
  5287. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5288. {
  5289. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5290. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5291. else
  5292. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5293. }
  5294. 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
  5295. {
  5296. currentStatus = Unavailable; //OCPP Status: Unavailable
  5297. }
  5298. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5299. {
  5300. currentStatus = Faulted; //OCPP Status: Faulted
  5301. }
  5302. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5303. {
  5304. currentStatus = Reserved; //OCPP Status: Reserved
  5305. }
  5306. }//end of the same index
  5307. }//end of for AC_QUANTITY
  5308. }
  5309. //it's option
  5310. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5311. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5312. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5313. {
  5314. isStateChanged = FALSE;
  5315. }
  5316. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5317. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5318. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5319. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5320. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5321. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5322. random_uuid(guid);
  5323. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5324. , MESSAGE_TYPE_CALL
  5325. , guid
  5326. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5327. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5328. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5329. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5330. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5331. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5332. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5333. if((server_sign == TRUE) && isStateChanged)
  5334. {
  5335. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5336. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5337. LWS_Send(message);
  5338. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5339. 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*/)
  5340. {
  5341. //DEBUG_ERROR("statusNotification mapitem pass");
  5342. result = PASS;
  5343. }
  5344. }
  5345. else
  5346. {
  5347. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5348. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5349. result = PASS;
  5350. }
  5351. return result;
  5352. }
  5353. int sendStopTransactionRequest(int gun_index)
  5354. {
  5355. mtrace();
  5356. int result = FAIL;
  5357. //char message[1500]={0};
  5358. char guid[37]={0};
  5359. char tempdata[65]={0};
  5360. int tempIndex = 0;
  5361. char TempStopTransaction[256];
  5362. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5363. //int idx_sample=0;
  5364. DEBUG_INFO("sendStopTransactionRequest \n");
  5365. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5366. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5367. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5368. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5369. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5370. {
  5371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5372. {
  5373. tempIndex = ((gun_index==2) ? 1: 0);
  5374. }
  5375. else
  5376. {
  5377. tempIndex = gun_index;
  5378. }
  5379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5380. {
  5381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5382. {
  5383. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5384. }
  5385. }// END OF CHAdeMO_QUANTITY
  5386. }
  5387. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5388. {
  5389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5390. {
  5391. tempIndex = ((gun_index==2) ? 1: 0);
  5392. }
  5393. else
  5394. {
  5395. tempIndex = gun_index;
  5396. }
  5397. for (int index = 0; index < CCS_QUANTITY; index++)
  5398. {
  5399. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5400. {
  5401. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5402. }
  5403. }// END OF CCS_QUANTITY
  5404. }
  5405. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5406. {
  5407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5408. {
  5409. tempIndex = ((gun_index==2) ? 1: 0);
  5410. }
  5411. else
  5412. {
  5413. tempIndex = gun_index;
  5414. }
  5415. for (int index = 0; index < GB_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5418. {
  5419. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5420. }
  5421. }// END OF GB_QUANTITY
  5422. }
  5423. else if(gunType[gun_index] == GUN_TYPE_DO)
  5424. {
  5425. tempIndex = gun_index;
  5426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5427. {
  5428. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5429. {
  5430. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5431. }
  5432. }// END OF GB_QUANTITY
  5433. }
  5434. else
  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. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5449. }
  5450. }// END OF AC_QUANTITY
  5451. }
  5452. //====================================== Stop Transaction Time =====================================================
  5453. struct timeval tmnow;
  5454. struct tm *tm;
  5455. char buf[28];//, usec_buf[6];
  5456. gettimeofday(&tmnow, NULL);
  5457. time_t t;
  5458. t = time(NULL);
  5459. /*UTC time and date*/
  5460. tm = gmtime(&t);
  5461. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5462. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5463. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5464. random_uuid(guid);
  5465. /***********************************transactionData******************************************************/
  5466. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5467. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5468. //=================================
  5469. // Transaction_Begin
  5470. //=================================
  5471. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5472. {
  5473. //============================================ Energy.Active.Import.Interval ================================
  5474. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5476. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5477. 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*/]);
  5478. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5479. 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))
  5480. {
  5481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5482. }
  5483. else
  5484. {
  5485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5486. }
  5487. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5489. }
  5490. //=================================
  5491. // Transaction_End
  5492. //=================================
  5493. // ================================= Current.Import L1 ===============================================
  5494. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5495. {
  5496. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5497. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5498. {
  5499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5500. {
  5501. tempIndex = ((gun_index==2) ? 1: 0);
  5502. }
  5503. else
  5504. {
  5505. tempIndex = gun_index;
  5506. }
  5507. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5508. {
  5509. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5510. {
  5511. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5512. }
  5513. }// End of for CHAdeMO_QUANTITY
  5514. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5515. }
  5516. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5517. {
  5518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5519. {
  5520. tempIndex = ((gun_index==2) ? 1: 0);
  5521. }
  5522. else
  5523. {
  5524. tempIndex = gun_index;
  5525. }
  5526. for (int index = 0; index < CCS_QUANTITY; index++)
  5527. {
  5528. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5529. {
  5530. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5531. }
  5532. }// End of for CCS_QUANTITY
  5533. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5534. }
  5535. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5536. {
  5537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5538. {
  5539. tempIndex = ((gun_index==2) ? 1: 0);
  5540. }
  5541. else
  5542. {
  5543. tempIndex = gun_index;
  5544. }
  5545. for (int index = 0; index < GB_QUANTITY; index++)
  5546. {
  5547. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5548. {
  5549. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5550. }
  5551. }// End of for GB_QUANTITY
  5552. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5553. }
  5554. else if(gunType[gun_index] == GUN_TYPE_DO)
  5555. {
  5556. tempIndex = gun_index;
  5557. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5558. {
  5559. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5560. {
  5561. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5562. }
  5563. }
  5564. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5565. }
  5566. else
  5567. {
  5568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5569. {
  5570. tempIndex = 2;
  5571. }
  5572. else
  5573. {
  5574. tempIndex = gun_index;
  5575. }
  5576. for (int index = 0; index < AC_QUANTITY; index++)
  5577. {
  5578. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5579. {
  5580. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5581. }
  5582. }// End of for AC_QUANTITY
  5583. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5584. }
  5585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5586. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5587. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5588. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5589. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5590. }
  5591. // ================================= Energy.Active.Import.Interval ==============================================
  5592. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5593. {
  5594. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5595. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5596. {
  5597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5598. {
  5599. tempIndex = ((gun_index==2) ? 1: 0);
  5600. }
  5601. else
  5602. {
  5603. tempIndex = gun_index;
  5604. }
  5605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5606. {
  5607. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5608. {
  5609. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5610. }
  5611. }// END OF CHAdeMO_QUANTITY
  5612. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5613. }
  5614. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5615. {
  5616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5617. {
  5618. tempIndex = ((gun_index==2) ? 1: 0);
  5619. }
  5620. else
  5621. {
  5622. tempIndex = gun_index;
  5623. }
  5624. for (int index = 0; index < CCS_QUANTITY; index++)
  5625. {
  5626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5627. {
  5628. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5629. }
  5630. }// END OF CCS_QUANTITY
  5631. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5632. }
  5633. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5634. {
  5635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5636. {
  5637. tempIndex = ((gun_index==2) ? 1: 0);
  5638. }
  5639. else
  5640. {
  5641. tempIndex = gun_index;
  5642. }
  5643. for (int index = 0; index < GB_QUANTITY; index++)
  5644. {
  5645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5646. {
  5647. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5648. }
  5649. }// END OF GB_QUANTITY
  5650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5651. }
  5652. else if(gunType[gun_index] == GUN_TYPE_DO)
  5653. {
  5654. tempIndex = gun_index;
  5655. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5656. {
  5657. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5658. {
  5659. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5660. }
  5661. }
  5662. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5663. }
  5664. else
  5665. {
  5666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5667. {
  5668. tempIndex = 2;
  5669. }
  5670. else
  5671. {
  5672. tempIndex = gun_index;
  5673. }
  5674. for (int index = 0; index < AC_QUANTITY; index++)
  5675. {
  5676. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5677. {
  5678. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5679. }
  5680. }// END OF AC_QUANTITY
  5681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5682. }
  5683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5685. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5688. }
  5689. //=================================== Power.Active.Import ==================================================
  5690. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5691. {
  5692. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5693. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5694. {
  5695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5696. {
  5697. tempIndex = ((gun_index==2) ? 1: 0);
  5698. }
  5699. else
  5700. {
  5701. tempIndex = gun_index;
  5702. }
  5703. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5704. {
  5705. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5706. {
  5707. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5708. }
  5709. } // End for CHAdeMO_QUANTITY
  5710. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5711. }
  5712. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5713. {
  5714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5715. {
  5716. tempIndex = ((gun_index==2) ? 1: 0);
  5717. }
  5718. else
  5719. {
  5720. tempIndex = gun_index;
  5721. }
  5722. for (int index = 0; index < CCS_QUANTITY; index++)
  5723. {
  5724. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5725. {
  5726. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5727. }
  5728. } // END for CCS_QUANTITY
  5729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5730. }
  5731. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5732. {
  5733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5734. {
  5735. tempIndex = ((gun_index==2) ? 1: 0);
  5736. }
  5737. else
  5738. {
  5739. tempIndex = gun_index;
  5740. }
  5741. for (int index = 0; index < GB_QUANTITY; index++)
  5742. {
  5743. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5744. {
  5745. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5746. }
  5747. }// END for GB_QUANTITY
  5748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5749. }
  5750. else if(gunType[gun_index] == GUN_TYPE_DO)
  5751. {
  5752. tempIndex = gun_index;
  5753. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5754. {
  5755. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5756. {
  5757. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5758. }
  5759. }
  5760. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5761. }
  5762. else
  5763. {
  5764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5765. {
  5766. tempIndex = 2;
  5767. }
  5768. else
  5769. {
  5770. tempIndex = gun_index;
  5771. }
  5772. for (int index = 0; index < AC_QUANTITY; index++)
  5773. {
  5774. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5775. {
  5776. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5777. }
  5778. } // END for AC_QUANTITY
  5779. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5780. }
  5781. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5784. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5786. }
  5787. //============================ Voltage L1 ====================================
  5788. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5789. {
  5790. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5791. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5792. {
  5793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5794. {
  5795. tempIndex = ((gun_index==2) ? 1: 0);
  5796. }
  5797. else
  5798. {
  5799. tempIndex = gun_index;
  5800. }
  5801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5802. {
  5803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5804. {
  5805. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5806. }
  5807. } // END OF FOR CHAdeMO_QUANTITY
  5808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5809. }
  5810. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5811. {
  5812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5813. {
  5814. tempIndex = ((gun_index==2) ? 1: 0);
  5815. }
  5816. else
  5817. {
  5818. tempIndex = gun_index;
  5819. }
  5820. for (int index = 0; index < CCS_QUANTITY; index++)
  5821. {
  5822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5823. {
  5824. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5825. }
  5826. } // END OF FOR CCS_QUANTITY
  5827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5828. }
  5829. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5830. {
  5831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5832. {
  5833. tempIndex = ((gun_index==2) ? 1: 0);
  5834. }
  5835. else
  5836. {
  5837. tempIndex = gun_index;
  5838. }
  5839. for (int index = 0; index < GB_QUANTITY; index++)
  5840. {
  5841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5842. {
  5843. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5844. }
  5845. } // END OF FOR GB_QUANTITY
  5846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5847. }
  5848. else if(gunType[gun_index] == GUN_TYPE_DO)
  5849. {
  5850. tempIndex = gun_index;
  5851. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5852. {
  5853. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5854. {
  5855. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5856. }
  5857. }
  5858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5859. }
  5860. else
  5861. {
  5862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5863. {
  5864. tempIndex = 2;
  5865. }
  5866. else
  5867. {
  5868. tempIndex = gun_index;
  5869. }
  5870. for (int index = 0; index < AC_QUANTITY; index++)
  5871. {
  5872. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5873. {
  5874. 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
  5875. }
  5876. } // END OF FOR AC_QUANTITY
  5877. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5878. }
  5879. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5880. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5881. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5882. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5883. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5884. }
  5885. //====================== End SoC ================================
  5886. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5887. {
  5888. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5889. 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))
  5890. {
  5891. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5892. {
  5893. tempIndex = ((gun_index==2) ? 1: 0);
  5894. }
  5895. else
  5896. {
  5897. tempIndex = gun_index;
  5898. }
  5899. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5900. {
  5901. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5902. {
  5903. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5904. {
  5905. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5906. }
  5907. }
  5908. }
  5909. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5910. {
  5911. for (int index = 0; index < CCS_QUANTITY; index++)
  5912. {
  5913. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5914. {
  5915. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5916. }
  5917. }
  5918. }
  5919. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5920. {
  5921. for (int index = 0; index < GB_QUANTITY; index++)
  5922. {
  5923. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5924. {
  5925. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5926. }
  5927. }
  5928. }
  5929. else if(gunType[gun_index] == GUN_TYPE_DO)
  5930. {
  5931. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5932. {
  5933. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5934. {
  5935. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5936. }
  5937. }
  5938. }
  5939. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5941. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5942. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5944. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5945. } // END FOR DC CASE
  5946. }
  5947. // ================================= Current.Import L2 ===============================================
  5948. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5949. {
  5950. // AC 3 phse L2 current
  5951. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5952. {
  5953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5954. {
  5955. tempIndex = 2;
  5956. }
  5957. else
  5958. {
  5959. tempIndex = gun_index;
  5960. }
  5961. for (int index = 0; index < AC_QUANTITY; index++)
  5962. {
  5963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5964. {
  5965. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5966. }
  5967. }// End of for AC_QUANTITY
  5968. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5969. }
  5970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5973. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5974. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5975. }
  5976. // ================================= Current.Import L3 ===============================================
  5977. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5978. {
  5979. // AC 3 phse L3 current
  5980. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5981. {
  5982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5983. {
  5984. tempIndex = 2;
  5985. }
  5986. else
  5987. {
  5988. tempIndex = gun_index;
  5989. }
  5990. for (int index = 0; index < AC_QUANTITY; index++)
  5991. {
  5992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5993. {
  5994. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5995. }
  5996. }// End of for AC_QUANTITY
  5997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5998. }
  5999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6004. }
  6005. //============================ Voltage L2 ====================================
  6006. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6007. {
  6008. // AC 3 phse L2 voltage
  6009. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6010. {
  6011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6012. {
  6013. tempIndex = 2;
  6014. }
  6015. else
  6016. {
  6017. tempIndex = gun_index;
  6018. }
  6019. for (int index = 0; index < AC_QUANTITY; index++)
  6020. {
  6021. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6022. {
  6023. 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
  6024. }
  6025. } // END OF FOR AC_QUANTITY
  6026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6027. }
  6028. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6029. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6030. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6031. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6032. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6033. }
  6034. //============================ Voltage L3 ====================================
  6035. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6036. {
  6037. // AC 3 phse L3 voltage
  6038. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6039. {
  6040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6041. {
  6042. tempIndex = 2;
  6043. }
  6044. else
  6045. {
  6046. tempIndex = gun_index;
  6047. }
  6048. for (int index = 0; index < AC_QUANTITY; index++)
  6049. {
  6050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6051. {
  6052. 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
  6053. }
  6054. } // END OF FOR AC_QUANTITY
  6055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6056. }
  6057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6062. }
  6063. //====================== Start SoC ================================
  6064. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6065. {
  6066. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6067. 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))
  6068. {
  6069. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6070. {
  6071. tempIndex = ((gun_index==2) ? 1: 0);
  6072. }
  6073. else
  6074. {
  6075. tempIndex = gun_index;
  6076. }
  6077. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6078. {
  6079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6080. {
  6081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6082. {
  6083. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6084. }
  6085. }
  6086. }
  6087. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6088. {
  6089. for (int index = 0; index < CCS_QUANTITY; index++)
  6090. {
  6091. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6092. {
  6093. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6094. }
  6095. }
  6096. }
  6097. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6098. {
  6099. for (int index = 0; index < GB_QUANTITY; index++)
  6100. {
  6101. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6102. {
  6103. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6104. }
  6105. }
  6106. }
  6107. else if(gunType[gun_index] == GUN_TYPE_DO)
  6108. {
  6109. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6110. {
  6111. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6112. {
  6113. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6114. }
  6115. }
  6116. }
  6117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6122. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6123. } // END FOR DC CASE
  6124. }
  6125. //================================================ Message create ====================================================
  6126. json_object *StopTransaction = json_object_new_object();
  6127. json_object *transactionDatas = json_object_new_array();
  6128. json_object *sampledValues = json_object_new_array();
  6129. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6130. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6131. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6132. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6133. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6134. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6135. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6136. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6137. {
  6138. json_object *transactionData = json_object_new_object();
  6139. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6140. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6141. {
  6142. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6143. {
  6144. json_object *sampledValue = json_object_new_object();
  6145. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6146. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6147. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6148. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6149. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6150. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6151. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6152. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6153. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6154. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6155. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6156. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6157. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6158. json_object_array_add(sampledValues, sampledValue);
  6159. }
  6160. }
  6161. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6162. json_object_array_add(transactionDatas, transactionData);
  6163. }
  6164. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6165. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6166. ,MESSAGE_TYPE_CALL
  6167. ,guid
  6168. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6169. json_object_put(StopTransaction);
  6170. #if 1 // for TempStopTransaction
  6171. //Delete TempStopTransaction
  6172. if((access(TempStopTransaction,F_OK))!=-1)
  6173. {
  6174. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6175. }
  6176. #endif
  6177. #if 1
  6178. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6179. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6180. {
  6181. result = PASS;
  6182. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6183. }
  6184. #endif
  6185. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6186. OCPP_insert_transaction_msg(NO, queuedata);
  6187. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6188. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6189. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6190. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6191. {
  6192. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6193. }
  6194. //for test
  6195. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6196. return result;
  6197. }
  6198. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6199. {
  6200. mtrace();
  6201. int result = FAIL;
  6202. char guid[37]={0};
  6203. char tempdata[65]={0};
  6204. int tempIndex = 0;
  6205. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6206. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6207. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6208. //set value
  6209. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6210. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6211. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6212. -1);
  6213. random_uuid(guid);
  6214. //UTC Date time
  6215. struct timeval tmnow;
  6216. struct tm *tm;
  6217. char buf[28];//, usec_buf[6];
  6218. gettimeofday(&tmnow, NULL);
  6219. time_t t;
  6220. t = time(NULL);
  6221. /*UTC time and date*/
  6222. tm = gmtime(&t);
  6223. if(dataType == ReadingContext_Sample_Clock)
  6224. {
  6225. struct tm *tmTarget;
  6226. struct timeb tbTarget;
  6227. tbTarget.time = mktime(tm);
  6228. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6229. tmTarget = gmtime(&tbTarget.time);
  6230. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6231. }
  6232. else
  6233. {
  6234. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6235. }
  6236. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6237. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6238. //********************************(1)Current.Import L1************************************************/
  6239. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6240. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6241. (dataType == ReadingContext_Trigger))
  6242. {
  6243. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6244. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6245. {
  6246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6247. {
  6248. tempIndex = ((gun_index==2) ? 1: 0);
  6249. }
  6250. else
  6251. {
  6252. tempIndex = gun_index;
  6253. }
  6254. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6255. {
  6256. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6257. {
  6258. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6259. }
  6260. }
  6261. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6262. }
  6263. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6264. {
  6265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6266. {
  6267. tempIndex = ((gun_index==2) ? 1: 0);
  6268. }
  6269. else
  6270. {
  6271. tempIndex = gun_index;
  6272. }
  6273. for (int index = 0; index < CCS_QUANTITY; index++)
  6274. {
  6275. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6276. {
  6277. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6278. }
  6279. }
  6280. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6281. }
  6282. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6283. {
  6284. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6285. {
  6286. tempIndex = ((gun_index==2) ? 1: 0);
  6287. }
  6288. else
  6289. {
  6290. tempIndex = gun_index;
  6291. }
  6292. for (int index = 0; index < GB_QUANTITY; index++)
  6293. {
  6294. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6295. {
  6296. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6297. }
  6298. }
  6299. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6300. }
  6301. else if(gunType[gun_index] == GUN_TYPE_DO)
  6302. {
  6303. tempIndex = gun_index;
  6304. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6305. {
  6306. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6307. {
  6308. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6309. }
  6310. }
  6311. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6312. }
  6313. else
  6314. {
  6315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6316. {
  6317. tempIndex = 2;
  6318. }
  6319. else
  6320. {
  6321. tempIndex = gun_index;
  6322. }
  6323. for (int index = 0; index < AC_QUANTITY; index++)
  6324. {
  6325. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6326. {
  6327. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6328. }
  6329. }
  6330. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6331. }
  6332. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6333. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6334. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6335. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6336. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6337. }
  6338. //********************************(2)Energy.Active.Import.Register ************************************************/
  6339. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6340. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6341. (dataType == ReadingContext_Trigger))
  6342. {
  6343. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6344. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6345. {
  6346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6347. {
  6348. tempIndex = ((gun_index==2) ? 1: 0);
  6349. }
  6350. else
  6351. {
  6352. tempIndex = gun_index;
  6353. }
  6354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6355. {
  6356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6357. {
  6358. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6359. }
  6360. }
  6361. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6362. }
  6363. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6364. {
  6365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6366. {
  6367. tempIndex = ((gun_index==2) ? 1: 0);
  6368. }
  6369. else
  6370. {
  6371. tempIndex = gun_index;
  6372. }
  6373. for (int index = 0; index < CCS_QUANTITY; index++)
  6374. {
  6375. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6376. {
  6377. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6378. }
  6379. }
  6380. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6381. }
  6382. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6383. {
  6384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6385. {
  6386. tempIndex = ((gun_index==2) ? 1: 0);
  6387. }
  6388. else
  6389. {
  6390. tempIndex = gun_index;
  6391. }
  6392. for (int index = 0; index < GB_QUANTITY; index++)
  6393. {
  6394. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6395. {
  6396. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6397. }
  6398. }
  6399. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6400. }
  6401. else if(gunType[gun_index] == GUN_TYPE_DO)
  6402. {
  6403. tempIndex = gun_index;
  6404. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6405. {
  6406. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6407. {
  6408. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6409. }
  6410. }
  6411. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6412. }
  6413. else
  6414. {
  6415. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6416. {
  6417. tempIndex = 2;
  6418. }
  6419. else
  6420. {
  6421. tempIndex = gun_index;
  6422. }
  6423. for (int index = 0; index < AC_QUANTITY; index++)
  6424. {
  6425. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6426. {
  6427. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6428. }
  6429. }
  6430. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6431. }
  6432. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6433. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6434. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6435. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6436. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6437. }
  6438. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6439. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6440. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6441. (dataType == ReadingContext_Trigger))
  6442. {
  6443. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6444. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6445. {
  6446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6447. {
  6448. tempIndex = ((gun_index==2) ? 1: 0);
  6449. }
  6450. else
  6451. {
  6452. tempIndex = gun_index;
  6453. }
  6454. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6455. {
  6456. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6457. {
  6458. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6459. }
  6460. } // END OF FOR CHAdeMO_QUANTITY
  6461. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6462. }
  6463. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6464. {
  6465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6466. {
  6467. tempIndex = ((gun_index==2) ? 1: 0);
  6468. }
  6469. else
  6470. {
  6471. tempIndex = gun_index;
  6472. }
  6473. for (int index = 0; index < CCS_QUANTITY; index++)
  6474. {
  6475. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6476. {
  6477. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6478. }
  6479. } // END OF CCS_QUANTITY
  6480. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6481. }
  6482. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6483. {
  6484. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6485. {
  6486. tempIndex = ((gun_index==2) ? 1: 0);
  6487. }
  6488. else
  6489. {
  6490. tempIndex = gun_index;
  6491. }
  6492. for (int index = 0; index < GB_QUANTITY; index++)
  6493. {
  6494. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6495. {
  6496. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6497. }
  6498. } // END OF GB_QUANTITY
  6499. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6500. }
  6501. else if(gunType[gun_index] == GUN_TYPE_DO)
  6502. {
  6503. tempIndex = gun_index;
  6504. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6505. {
  6506. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6507. {
  6508. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6509. }
  6510. }
  6511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6512. }
  6513. else
  6514. {
  6515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6516. {
  6517. tempIndex = 2;
  6518. }
  6519. else
  6520. {
  6521. tempIndex = gun_index;
  6522. }
  6523. for (int index = 0; index < AC_QUANTITY; index++)
  6524. {
  6525. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6526. {
  6527. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6528. }
  6529. }
  6530. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6531. }
  6532. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6533. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6534. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6535. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6536. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6537. }
  6538. //********************************(4)Power.Active.Import************************************************/
  6539. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6540. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6541. (dataType == ReadingContext_Trigger))
  6542. {
  6543. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6544. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6545. {
  6546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6547. {
  6548. tempIndex = ((gun_index==2) ? 1: 0);
  6549. }
  6550. else
  6551. {
  6552. tempIndex = gun_index;
  6553. }
  6554. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6555. {
  6556. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6557. {
  6558. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6559. }
  6560. } // END OF FOR
  6561. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6562. }
  6563. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6564. {
  6565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6566. {
  6567. tempIndex = ((gun_index==2) ? 1: 0);
  6568. }
  6569. else
  6570. {
  6571. tempIndex = gun_index;
  6572. }
  6573. for (int index = 0; index < CCS_QUANTITY; index++)
  6574. {
  6575. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6576. {
  6577. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6578. }
  6579. }
  6580. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6581. }
  6582. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6583. {
  6584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6585. {
  6586. tempIndex = ((gun_index==2) ? 1: 0);
  6587. }
  6588. else
  6589. {
  6590. tempIndex = gun_index;
  6591. }
  6592. for (int index = 0; index < GB_QUANTITY; index++)
  6593. {
  6594. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6595. {
  6596. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6597. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6598. }
  6599. }
  6600. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6601. }
  6602. else if(gunType[gun_index] == GUN_TYPE_DO)
  6603. {
  6604. tempIndex = gun_index;
  6605. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6606. {
  6607. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6608. {
  6609. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6610. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6611. }
  6612. }
  6613. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6614. }
  6615. else
  6616. {
  6617. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6618. {
  6619. tempIndex = 2;
  6620. }
  6621. else
  6622. {
  6623. tempIndex = gun_index;
  6624. }
  6625. for (int index = 0; index < AC_QUANTITY; index++)
  6626. {
  6627. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6628. {
  6629. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6630. }
  6631. }
  6632. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6633. }
  6634. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6635. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6636. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6637. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6638. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6639. }
  6640. //***********************************************(5)VOLTAGE L1******************************************************/
  6641. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6642. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6643. (dataType == ReadingContext_Trigger))
  6644. {
  6645. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6646. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6647. {
  6648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6649. {
  6650. tempIndex = ((gun_index==2) ? 1: 0);
  6651. }
  6652. else
  6653. {
  6654. tempIndex = gun_index;
  6655. }
  6656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6657. {
  6658. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6659. {
  6660. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6661. }
  6662. }
  6663. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6664. }
  6665. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6666. {
  6667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6668. {
  6669. tempIndex = ((gun_index==2) ? 1: 0);
  6670. }
  6671. else
  6672. {
  6673. tempIndex = gun_index;
  6674. }
  6675. for (int index = 0; index < CCS_QUANTITY; index++)
  6676. {
  6677. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6678. {
  6679. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6680. }
  6681. }
  6682. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6683. }
  6684. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6685. {
  6686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6687. {
  6688. tempIndex = ((gun_index==2) ? 1: 0);
  6689. }
  6690. else
  6691. {
  6692. tempIndex = gun_index;
  6693. }
  6694. for (int index = 0; index < GB_QUANTITY; index++)
  6695. {
  6696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6697. {
  6698. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6699. }
  6700. }
  6701. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6702. }
  6703. else if(gunType[gun_index] == GUN_TYPE_DO)
  6704. {
  6705. tempIndex = gun_index;
  6706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6707. {
  6708. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6709. {
  6710. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6711. }
  6712. }
  6713. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6714. }
  6715. else
  6716. {
  6717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6718. {
  6719. tempIndex = 2;
  6720. }
  6721. else
  6722. {
  6723. tempIndex = gun_index;
  6724. }
  6725. for (int index = 0; index < AC_QUANTITY; index++)
  6726. {
  6727. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6728. {
  6729. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6730. }
  6731. }
  6732. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6733. }
  6734. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6735. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6736. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6737. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6738. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6739. }
  6740. //***********************************************(6)SOC******************************************************/
  6741. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6742. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6743. (dataType == ReadingContext_Trigger))
  6744. {
  6745. 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))
  6746. {
  6747. //idx_sample=5;
  6748. //sampledValue = NULL;
  6749. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6750. {
  6751. tempIndex = ((gun_index==2) ? 1: 0);
  6752. }
  6753. else
  6754. {
  6755. tempIndex = gun_index;
  6756. }
  6757. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6758. {
  6759. //tempIndex = ((gun_index==2) ? 1: 0);
  6760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6761. {
  6762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6763. {
  6764. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6765. }
  6766. }
  6767. }
  6768. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6769. {
  6770. //tempIndex = ((gun_index==2) ? 1: 0);
  6771. for (int index = 0; index < CCS_QUANTITY; index++)
  6772. {
  6773. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6774. {
  6775. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6776. }
  6777. }
  6778. }
  6779. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6780. {
  6781. //tempIndex = ((gun_index==2) ? 1: 0);
  6782. for (int index = 0; index < GB_QUANTITY; index++)
  6783. {
  6784. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6785. {
  6786. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6787. }
  6788. }
  6789. }
  6790. else if(gunType[gun_index] == GUN_TYPE_DO)
  6791. {
  6792. //tempIndex = ((gun_index==2) ? 1: 0);
  6793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6794. {
  6795. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6796. {
  6797. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6798. }
  6799. }
  6800. }
  6801. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6802. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6803. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6804. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6805. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6806. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6807. }
  6808. }
  6809. //********************************(7)Current.Import L2************************************************/
  6810. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6811. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6812. (dataType == ReadingContext_Trigger))
  6813. {
  6814. // Only for AC 3 phase
  6815. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6816. {
  6817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6818. {
  6819. tempIndex = 2;
  6820. }
  6821. else
  6822. {
  6823. tempIndex = gun_index;
  6824. }
  6825. for (int index = 0; index < AC_QUANTITY; index++)
  6826. {
  6827. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6828. {
  6829. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6830. }
  6831. }
  6832. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6833. }
  6834. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6835. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6836. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6837. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6838. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6839. }
  6840. //********************************(8)Current.Import L3************************************************/
  6841. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6842. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6843. (dataType == ReadingContext_Trigger))
  6844. {
  6845. // Only for AC 3 phase
  6846. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6847. {
  6848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6849. {
  6850. tempIndex = 2;
  6851. }
  6852. else
  6853. {
  6854. tempIndex = gun_index;
  6855. }
  6856. for (int index = 0; index < AC_QUANTITY; index++)
  6857. {
  6858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6859. {
  6860. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6861. }
  6862. }
  6863. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6864. }
  6865. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6866. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6867. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6868. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6869. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6870. }
  6871. //***********************************************(9)VOLTAGE L2******************************************************/
  6872. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6873. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6874. (dataType == ReadingContext_Trigger))
  6875. {
  6876. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6877. {
  6878. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6879. {
  6880. tempIndex = 2;
  6881. }
  6882. else
  6883. {
  6884. tempIndex = gun_index;
  6885. }
  6886. for (int index = 0; index < AC_QUANTITY; index++)
  6887. {
  6888. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6889. {
  6890. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6891. }
  6892. }
  6893. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6894. }
  6895. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6896. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6897. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6898. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6899. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6900. }
  6901. //***********************************************(10)VOLTAGE L3******************************************************/
  6902. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6903. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6904. (dataType == ReadingContext_Trigger))
  6905. {
  6906. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6907. {
  6908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6909. {
  6910. tempIndex = 2;
  6911. }
  6912. else
  6913. {
  6914. tempIndex = gun_index;
  6915. }
  6916. for (int index = 0; index < AC_QUANTITY; index++)
  6917. {
  6918. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6919. {
  6920. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6921. }
  6922. }
  6923. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6924. }
  6925. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6926. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6927. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6928. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6929. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6930. }
  6931. //***********************************************(11)Current.Offered******************************************************/
  6932. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6933. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6934. (dataType == ReadingContext_Trigger))
  6935. {
  6936. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6937. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6938. {
  6939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6940. {
  6941. tempIndex = ((gun_index==2) ? 1: 0);
  6942. }
  6943. else
  6944. {
  6945. tempIndex = gun_index;
  6946. }
  6947. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6948. {
  6949. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6950. {
  6951. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6952. }
  6953. } // END OF FOR CHAdeMO_QUANTITY
  6954. }
  6955. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6956. {
  6957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6958. {
  6959. tempIndex = ((gun_index==2) ? 1: 0);
  6960. }
  6961. else
  6962. {
  6963. tempIndex = gun_index;
  6964. }
  6965. for (int index = 0; index < CCS_QUANTITY; index++)
  6966. {
  6967. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6968. {
  6969. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6970. }
  6971. } // END OF CCS_QUANTITY
  6972. }
  6973. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6974. {
  6975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6976. {
  6977. tempIndex = ((gun_index==2) ? 1: 0);
  6978. }
  6979. else
  6980. {
  6981. tempIndex = gun_index;
  6982. }
  6983. for (int index = 0; index < GB_QUANTITY; index++)
  6984. {
  6985. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6986. {
  6987. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6988. }
  6989. } // END OF GB_QUANTITY
  6990. }
  6991. else if(gunType[gun_index] == GUN_TYPE_DO)
  6992. {
  6993. tempIndex = gun_index;
  6994. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6995. {
  6996. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6997. {
  6998. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6999. }
  7000. }
  7001. }
  7002. else
  7003. {
  7004. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7005. {
  7006. tempIndex = 2;
  7007. }
  7008. else
  7009. {
  7010. tempIndex = gun_index;
  7011. }
  7012. for (int index = 0; index < AC_QUANTITY; index++)
  7013. {
  7014. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7015. {
  7016. uint16_t currentOffer;
  7017. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7018. {
  7019. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7020. }
  7021. else
  7022. {
  7023. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7024. }
  7025. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7026. }
  7027. }
  7028. }
  7029. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7030. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7031. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7032. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7033. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7034. }
  7035. //***********************************************(12)Power.Offered******************************************************/
  7036. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7037. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7038. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7039. {
  7040. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7041. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7042. {
  7043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7044. {
  7045. tempIndex = ((gun_index==2) ? 1: 0);
  7046. }
  7047. else
  7048. {
  7049. tempIndex = gun_index;
  7050. }
  7051. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7052. {
  7053. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7054. {
  7055. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7056. }
  7057. } // END OF FOR CHAdeMO_QUANTITY
  7058. }
  7059. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7060. {
  7061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7062. {
  7063. tempIndex = ((gun_index==2) ? 1: 0);
  7064. }
  7065. else
  7066. {
  7067. tempIndex = gun_index;
  7068. }
  7069. for (int index = 0; index < CCS_QUANTITY; index++)
  7070. {
  7071. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7072. {
  7073. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7074. }
  7075. } // END OF CCS_QUANTITY
  7076. }
  7077. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7078. {
  7079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7080. {
  7081. tempIndex = ((gun_index==2) ? 1: 0);
  7082. }
  7083. else
  7084. {
  7085. tempIndex = gun_index;
  7086. }
  7087. for (int index = 0; index < GB_QUANTITY; index++)
  7088. {
  7089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7090. {
  7091. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7092. }
  7093. } // END OF GB_QUANTITY
  7094. }
  7095. else if(gunType[gun_index] == GUN_TYPE_DO)
  7096. {
  7097. tempIndex = gun_index;
  7098. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7099. {
  7100. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7101. {
  7102. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7103. }
  7104. }
  7105. }
  7106. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7107. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7108. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7109. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7110. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7111. }
  7112. // Message create ====================================================================================================
  7113. if(TRUE)
  7114. {
  7115. json_object *MeterValueReq = json_object_new_object();
  7116. json_object *MeterValues = json_object_new_array();
  7117. json_object *sampledValues = json_object_new_array();
  7118. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7119. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7120. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7121. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7122. {
  7123. json_object *MeterValue = json_object_new_object();
  7124. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7125. {
  7126. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7127. {
  7128. json_object *sampledValue = json_object_new_object();
  7129. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7130. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7131. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7132. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7133. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7134. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7135. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7136. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7137. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7138. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7139. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7140. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7141. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7142. json_object_array_add(sampledValues, sampledValue);
  7143. }
  7144. }
  7145. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7146. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7147. json_object_array_add(MeterValues, MeterValue);
  7148. }
  7149. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7150. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7151. ,gun_index + 1
  7152. ,MESSAGE_TYPE_CALL
  7153. ,guid
  7154. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7155. json_object_put(MeterValueReq);
  7156. }
  7157. // Put request guid to hash map
  7158. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7159. 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*/)
  7160. {
  7161. result = PASS;
  7162. //DEBUG_INFO("MeterValues mapitem pass\n");
  7163. }
  7164. if((dataType != ReadingContext_Trigger) &&
  7165. (dataType != ReadingContext_Sample_Clock) &&
  7166. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7167. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7168. else
  7169. {
  7170. if(FirstHeartBeat)
  7171. LWS_Send(queuedata +2);
  7172. }
  7173. return result;
  7174. }
  7175. int sendLogStatusNotificationRequest(char *status)
  7176. {
  7177. mtrace();
  7178. int result = PASS;
  7179. char message[4096]={0};
  7180. char guid[37]={0};
  7181. char tempdata[128]={0};
  7182. json_object *LogStatusNotification = json_object_new_object();
  7183. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7184. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7185. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7186. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7187. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7188. random_uuid(guid);
  7189. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7190. json_object_put(LogStatusNotification);
  7191. LWS_Send(message);
  7192. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7193. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7194. {
  7195. result = PASS;
  7196. }
  7197. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7198. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7199. return result;
  7200. }
  7201. int sendSecurityEventNotificationRequest()
  7202. {
  7203. mtrace();
  7204. int result = PASS;
  7205. char message[4096]={0};
  7206. char guid[37]={0};
  7207. char tempdata[128]={0};
  7208. json_object *SecurityEventNotification = json_object_new_object();
  7209. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7210. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7211. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7212. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7213. random_uuid(guid);
  7214. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7215. json_object_put(SecurityEventNotification);
  7216. LWS_Send(message);
  7217. sprintf(tempdata, "SecurityEventNotification,0");
  7218. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7219. {
  7220. result = PASS;
  7221. }
  7222. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7223. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7224. return result;
  7225. }
  7226. int sendSignCertificateRequest()
  7227. {
  7228. mtrace();
  7229. int result = PASS;
  7230. char message[4096]={0};
  7231. char guid[37]={0};
  7232. char tempdata[128]={0};
  7233. json_object *SignCertificate = json_object_new_object();
  7234. DEBUG_INFO("sendSignCertificateRequest...\n");
  7235. // Read csr file content
  7236. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7237. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7238. char *line = NULL;
  7239. size_t len = 0;
  7240. while(getline(&line, &len, fp) != -1)
  7241. {
  7242. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7243. {
  7244. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7245. }
  7246. }
  7247. fclose(fp);
  7248. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7249. random_uuid(guid);
  7250. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7251. json_object_put(SignCertificate);
  7252. LWS_Send(message);
  7253. sprintf(tempdata, "SignCertificate,0");
  7254. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7255. {
  7256. result = PASS;
  7257. }
  7258. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7259. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7260. return result;
  7261. }
  7262. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7263. {
  7264. mtrace();
  7265. int result = PASS;
  7266. char message[110]={0};
  7267. char guid[37]={0};
  7268. char tempdata[65]={0};
  7269. json_object *FirmwareStatusNotification = json_object_new_object();
  7270. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7271. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7272. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7273. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7274. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7275. random_uuid(guid);
  7276. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7277. json_object_put(FirmwareStatusNotification);
  7278. LWS_Send(message);
  7279. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7280. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7281. {
  7282. result = PASS;
  7283. }
  7284. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7285. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7286. return result;
  7287. }
  7288. //==========================================
  7289. // send confirm routine
  7290. //==========================================
  7291. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7292. {
  7293. mtrace();
  7294. int result = FAIL;
  7295. char message[100]={0};
  7296. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7297. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7298. LWS_Send(message);
  7299. result = TRUE;
  7300. return result;
  7301. }
  7302. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7303. {
  7304. mtrace();
  7305. int result = FAIL;
  7306. char message[100]={0};
  7307. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7308. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7309. LWS_Send(message);
  7310. result = TRUE;
  7311. return result;
  7312. }
  7313. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7314. {
  7315. mtrace();
  7316. int result = FAIL;
  7317. char message[100]={0};
  7318. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7319. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7320. LWS_Send(message);
  7321. result = TRUE;
  7322. return result;
  7323. }
  7324. int sendClearCacheConfirmation(char *uuid,char *payload)
  7325. {
  7326. mtrace();
  7327. int result = FAIL;
  7328. char message[500]={0};
  7329. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7330. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7331. LWS_Send(message);
  7332. return result;
  7333. }
  7334. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7335. {
  7336. mtrace();
  7337. int result = FAIL;
  7338. char message[500]={0};
  7339. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7340. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7341. LWS_Send(message);
  7342. return result;
  7343. }
  7344. int sendDataTransferConfirmation(char *uuid,char *payload)
  7345. {
  7346. mtrace();
  7347. char statusStr[20]={0};
  7348. char dataStr[10]={0};
  7349. char sstr[20]={0};
  7350. int c = 0;
  7351. char *loc;
  7352. int result = FAIL;
  7353. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7354. /**********************status**************************/
  7355. loc = strstr(payload, "status");
  7356. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7357. c = 0;
  7358. while (loc[3+strlen("status")+c] != '\"')
  7359. {
  7360. sstr[c] = loc[3+strlen("status")+c];
  7361. c++;
  7362. }
  7363. sstr[c] = '\0';
  7364. strcpy(statusStr, sstr);
  7365. /**********************data**************************/
  7366. loc = strstr(payload, "data");
  7367. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7368. c = 0;
  7369. while (loc[3+strlen("data")+c] != '\"')
  7370. {
  7371. sstr[c] = loc[3+strlen("data")+c];
  7372. c++;
  7373. }
  7374. sstr[c] = '\0';
  7375. strcpy(dataStr, sstr);
  7376. return result;
  7377. }
  7378. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7379. {
  7380. mtrace();
  7381. int result = FAIL;
  7382. char message[1000]={0};
  7383. int CompositeScheduleIndex = 0;
  7384. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7385. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7386. if(nPeriod == 0)
  7387. {
  7388. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7389. {
  7390. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7391. ,MESSAGE_TYPE_CALLRESULT
  7392. ,uuid
  7393. ,payload
  7394. ,connectorIdInt);
  7395. }
  7396. else
  7397. {
  7398. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7399. ,MESSAGE_TYPE_CALLRESULT
  7400. ,uuid
  7401. ,payload
  7402. ,connectorIdInt
  7403. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7404. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7405. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7406. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7407. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7408. }
  7409. }
  7410. else
  7411. {
  7412. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7413. ,MESSAGE_TYPE_CALLRESULT
  7414. ,uuid
  7415. ,payload
  7416. ,connectorIdInt
  7417. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7418. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7419. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7420. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7421. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7422. {
  7423. if (idx_sample == 0)
  7424. {
  7425. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7426. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7427. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7428. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7429. }
  7430. else
  7431. {
  7432. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7433. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7434. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7435. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7436. }
  7437. }
  7438. sprintf(message + strlen(message), "]}}]");
  7439. }
  7440. LWS_Send(message);
  7441. result = TRUE;
  7442. return result;
  7443. }
  7444. int sendGetConfigurationConfirmation(char *uuid)
  7445. {
  7446. mtrace();
  7447. int result = FAIL;
  7448. int MaxKeySupported = 0;
  7449. int sentConfigurationNumber= 0;
  7450. int sentunConfigurationNumber= 0;
  7451. char message[1024*10]={0};
  7452. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7453. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7454. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7455. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7456. ,MESSAGE_TYPE_CALLRESULT
  7457. ,uuid );
  7458. //configuration key
  7459. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7460. {
  7461. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7462. {
  7463. if (sentConfigurationNumber == 0)
  7464. {
  7465. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7466. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7467. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7468. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7469. }
  7470. else
  7471. {
  7472. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7473. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7474. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7475. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7476. }
  7477. sentConfigurationNumber = sentConfigurationNumber + 1;
  7478. }
  7479. }
  7480. sprintf(message + strlen(message), "]");
  7481. if(UnknownKeynum != 0)
  7482. {
  7483. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7484. //unkown key
  7485. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7486. {
  7487. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7488. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7489. if(sentunConfigurationNumber == 0)
  7490. {
  7491. sprintf(message + strlen(message), "\"%s\""
  7492. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7493. }
  7494. else
  7495. {
  7496. sprintf(message + strlen(message), ",\"%s\""
  7497. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7498. }
  7499. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7500. }
  7501. sprintf(message + strlen(message), "]");
  7502. }
  7503. sprintf(message + strlen(message), "}]");
  7504. LWS_Send(message);
  7505. return result;
  7506. }
  7507. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7508. {
  7509. mtrace();
  7510. int result = FAIL;
  7511. char message[400]={0};
  7512. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7513. if(strcmp(payload,"")==0)
  7514. {
  7515. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7516. }
  7517. else
  7518. {
  7519. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7520. }
  7521. LWS_Send(message);
  7522. result = TRUE;
  7523. return result;
  7524. }
  7525. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7526. {
  7527. mtrace();
  7528. int result = FAIL;
  7529. char message[80]={0};
  7530. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7531. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7532. LWS_Send(message);
  7533. result = TRUE;
  7534. return result;
  7535. }
  7536. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7537. {
  7538. mtrace();
  7539. int result = FAIL;
  7540. char message[80]={0};
  7541. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7542. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7543. LWS_Send(message);
  7544. result = TRUE;
  7545. return result;
  7546. }
  7547. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7548. {
  7549. mtrace();
  7550. int result = FAIL;
  7551. char message[80]={0};
  7552. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7553. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7554. LWS_Send(message);
  7555. result = TRUE;
  7556. return result;
  7557. }
  7558. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7559. {
  7560. mtrace();
  7561. int result = FAIL;
  7562. char message[80]={0};
  7563. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7564. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7565. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7566. LWS_Send(message);
  7567. result = TRUE;
  7568. return result;
  7569. }
  7570. int sendResetConfirmation(char *uuid,char *payload)
  7571. {
  7572. mtrace();
  7573. int result = FAIL;
  7574. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7575. char message[80]={0};
  7576. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7577. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7578. LWS_Send(message);
  7579. result = TRUE;
  7580. return result;
  7581. }
  7582. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7583. {
  7584. mtrace();
  7585. int result = FAIL;
  7586. char message[500]={0};
  7587. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7588. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7589. LWS_Send(message);
  7590. result = TRUE;
  7591. return result;
  7592. }
  7593. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7594. {
  7595. mtrace();
  7596. int result = FAIL;
  7597. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7598. char message[80]={0};
  7599. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7600. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7601. LWS_Send(message);
  7602. result = TRUE;
  7603. return result;
  7604. }
  7605. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7606. {
  7607. mtrace();
  7608. int result = FAIL;
  7609. char message[80]={0};
  7610. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7611. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7612. LWS_Send(message);
  7613. result = TRUE;
  7614. return result;
  7615. }
  7616. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7617. {
  7618. mtrace();
  7619. int result = FAIL;
  7620. char message[80]={0};
  7621. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7622. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7623. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7624. LWS_Send(message);
  7625. result = TRUE;
  7626. return result;
  7627. }
  7628. int sendUpdateFirmwareConfirmation(char *uuid)
  7629. {
  7630. mtrace();
  7631. int result = FAIL;
  7632. char message[60]={0};
  7633. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7634. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7635. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7636. LWS_Send(message);
  7637. result = TRUE;
  7638. return result;
  7639. }
  7640. int sendCertificateSignedConfirmation(char *uuid)
  7641. {
  7642. mtrace();
  7643. int result = PASS;
  7644. char message[4096]={0};
  7645. json_object *CertificateSigned = json_object_new_object();
  7646. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7647. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7648. sprintf(message,"[%d,\"%s\",%s]"
  7649. ,MESSAGE_TYPE_CALLRESULT
  7650. ,uuid
  7651. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7652. json_object_put(CertificateSigned);
  7653. LWS_Send(message);
  7654. return result;
  7655. }
  7656. int sendDeleteCertificateConfirmation(char *uuid)
  7657. {
  7658. mtrace();
  7659. int result = PASS;
  7660. char message[4096]={0};
  7661. json_object *DeleteCertificate = json_object_new_object();
  7662. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7663. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7664. sprintf(message,"[%d,\"%s\",%s]"
  7665. ,MESSAGE_TYPE_CALLRESULT
  7666. ,uuid
  7667. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7668. json_object_put(DeleteCertificate);
  7669. LWS_Send(message);
  7670. return result;
  7671. }
  7672. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7673. {
  7674. mtrace();
  7675. int result = PASS;
  7676. char message[4096]={0};
  7677. json_object *ExtendedTriggerMessage = json_object_new_object();
  7678. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7679. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7680. sprintf(message,"[%d,\"%s\",%s]"
  7681. ,MESSAGE_TYPE_CALLRESULT
  7682. ,uuid
  7683. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7684. json_object_put(ExtendedTriggerMessage);
  7685. LWS_Send(message);
  7686. return result;
  7687. }
  7688. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7689. {
  7690. mtrace();
  7691. int result = PASS;
  7692. char message[4096]={0};
  7693. json_object *GetInstalledCertificateIds = json_object_new_object();
  7694. json_object *certificateHashDataDatas = json_object_new_array();
  7695. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7696. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7697. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7698. {
  7699. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7700. {
  7701. json_object *certificateHashData = json_object_new_object();
  7702. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7703. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7704. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7705. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7706. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7707. }
  7708. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7709. }
  7710. else
  7711. {
  7712. json_object_put(certificateHashDataDatas);
  7713. }
  7714. sprintf(message,"[%d,\"%s\",%s]"
  7715. ,MESSAGE_TYPE_CALLRESULT
  7716. ,uuid
  7717. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7718. json_object_put(GetInstalledCertificateIds);
  7719. LWS_Send(message);
  7720. return result;
  7721. }
  7722. int sendGetLogConfirmation(char *uuid)
  7723. {
  7724. mtrace();
  7725. int result = PASS;
  7726. char message[4096]={0};
  7727. json_object *GetLog = json_object_new_object();
  7728. DEBUG_INFO("sendGetLogConfirmation...\n");
  7729. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7730. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7731. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7732. sprintf(message,"[%d,\"%s\",%s]"
  7733. ,MESSAGE_TYPE_CALLRESULT
  7734. ,uuid
  7735. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7736. json_object_put(GetLog);
  7737. LWS_Send(message);
  7738. return result;
  7739. }
  7740. int sendInstallCertificateConfirmation(char *uuid)
  7741. {
  7742. mtrace();
  7743. int result = PASS;
  7744. char message[4096]={0};
  7745. json_object *InstallCertificate = json_object_new_object();
  7746. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7747. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7748. sprintf(message,"[%d,\"%s\",%s]"
  7749. ,MESSAGE_TYPE_CALLRESULT
  7750. ,uuid
  7751. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7752. json_object_put(InstallCertificate);
  7753. LWS_Send(message);
  7754. return result;
  7755. }
  7756. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7757. {
  7758. mtrace();
  7759. int result = PASS;
  7760. char message[4096]={0};
  7761. json_object *SignedUpdateFirmware = json_object_new_object();
  7762. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7763. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7764. sprintf(message,"[%d,\"%s\",%s]"
  7765. ,MESSAGE_TYPE_CALLRESULT
  7766. ,uuid
  7767. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7768. json_object_put(SignedUpdateFirmware);
  7769. LWS_Send(message);
  7770. return result;
  7771. }
  7772. int sendUnknownConfirmation(char *uuid)
  7773. {
  7774. mtrace();
  7775. int result = PASS;
  7776. char message[256]={0};
  7777. DEBUG_INFO("sendUnknownConfirmation...\n");
  7778. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7779. LWS_Send(message);
  7780. return result;
  7781. }
  7782. //==========================================
  7783. // Handle server request routine Start
  7784. //==========================================
  7785. int handleCancelReservationRequest(char *uuid, char *payload)
  7786. {
  7787. mtrace();
  7788. int result = FAIL;
  7789. int gunNO = 0;
  7790. int reservationIdInt = -1;
  7791. char comfirmstr[20];
  7792. DEBUG_INFO("handleCancelReservationRequest...\n");
  7793. json_object *CancelReservation;
  7794. CancelReservation = json_tokener_parse(payload);
  7795. if(!is_error(CancelReservation))
  7796. {
  7797. // Required data
  7798. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7799. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7800. }
  7801. json_object_put(CancelReservation);
  7802. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7803. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7804. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7805. if(reservationIdInt != -1)
  7806. {
  7807. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7808. //check Transaction active
  7809. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7810. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7811. {
  7812. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7813. {
  7814. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7815. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7816. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7817. {
  7818. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7819. }
  7820. else
  7821. {
  7822. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7823. }
  7824. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7825. goto end;
  7826. }
  7827. }
  7828. for (int index = 0; index < CCS_QUANTITY; index++)
  7829. {
  7830. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7831. {
  7832. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7833. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7834. if(gunType[2] == GUN_TYPE_CCS)
  7835. {
  7836. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7837. }
  7838. else
  7839. {
  7840. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7841. }
  7842. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7843. goto end;
  7844. }
  7845. }
  7846. for (int index = 0; index < GB_QUANTITY; index++)
  7847. {
  7848. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7849. {
  7850. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7851. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7852. if(gunType[2] == GUN_TYPE_GBT)
  7853. {
  7854. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7855. }
  7856. else
  7857. {
  7858. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7859. }
  7860. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7861. goto end;
  7862. }
  7863. }
  7864. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7865. {
  7866. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7867. {
  7868. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7869. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7870. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7871. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7872. goto end;
  7873. }
  7874. }
  7875. for (int index = 0; index < AC_QUANTITY; index++)
  7876. {
  7877. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7878. {
  7879. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7880. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7882. {
  7883. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7884. }
  7885. else
  7886. {
  7887. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7888. }
  7889. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7890. goto end;
  7891. }
  7892. }
  7893. }
  7894. //The reservationId does NOT match the reservationId
  7895. sendCancelReservationConfirmation(uuid, comfirmstr);
  7896. end:
  7897. // Fill in ocpp packet uuid
  7898. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7899. return result;
  7900. }
  7901. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7902. {
  7903. mtrace();
  7904. int result = FAIL;
  7905. int gunIndex = -1;
  7906. char typeStr[16]={0};
  7907. char comfirmstr[20];
  7908. int specificId = FALSE;
  7909. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7910. json_object *ChangeAvailability;
  7911. ChangeAvailability = json_tokener_parse(payload);
  7912. if(!is_error(ChangeAvailability))
  7913. {
  7914. // Required data
  7915. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7916. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7917. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7918. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7919. }
  7920. json_object_put(ChangeAvailability);
  7921. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7922. {
  7923. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7924. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7925. }
  7926. else if(gunIndex == 0)
  7927. {
  7928. for(int i=0; i < gunTotalNumber; i++)
  7929. {
  7930. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7931. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7932. }
  7933. }
  7934. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7935. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7936. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7937. {
  7938. specificId = TRUE;
  7939. }
  7940. if(specificId == FALSE)
  7941. goto end;
  7942. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7943. {
  7944. //----------------------gunIndex is 0 ------------------------------------------------//
  7945. if(gunIndex == 0)
  7946. {
  7947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7948. {
  7949. for(int i=0; i < gunTotalNumber; i++)
  7950. {
  7951. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7952. {
  7953. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7954. {
  7955. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7956. {
  7957. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7958. goto end;
  7959. }
  7960. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7961. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7962. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7963. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7964. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7965. {
  7966. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7967. goto end;
  7968. }
  7969. }
  7970. }//END FOR CHAdeMO_QUANTITY
  7971. for (int index = 0; index < CCS_QUANTITY; index++)
  7972. {
  7973. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7974. {
  7975. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7976. {
  7977. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7978. goto end;
  7979. }
  7980. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7981. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7982. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7983. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7984. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7985. {
  7986. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7987. goto end;
  7988. }
  7989. }
  7990. }//END FOR CCS_QUANTITY
  7991. for (int index = 0; index < GB_QUANTITY; index++)
  7992. {
  7993. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7994. {
  7995. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7996. {
  7997. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7998. goto end;
  7999. }
  8000. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8001. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8002. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8003. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8004. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8005. {
  8006. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8007. goto end;
  8008. }
  8009. }
  8010. }// END FOR GB_QUANTITY
  8011. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8012. {
  8013. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8014. {
  8015. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8016. {
  8017. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8018. goto end;
  8019. }
  8020. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8021. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8022. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8023. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8024. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8025. {
  8026. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8027. goto end;
  8028. }
  8029. }
  8030. }// END FOR GENERAL_GUN_QUANTITY
  8031. for (int index = 0; index < AC_QUANTITY; index++)
  8032. {
  8033. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8034. {
  8035. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8036. {
  8037. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8038. goto end;
  8039. }
  8040. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8041. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8042. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8043. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8044. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8045. {
  8046. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8047. goto end;
  8048. }
  8049. }
  8050. }//END FOR AC_QUANTITY
  8051. }// END FOR gunTotalNumber
  8052. }
  8053. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8054. {
  8055. for(int i=0; i < gunTotalNumber; i++)
  8056. {
  8057. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8058. {
  8059. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8060. goto end;
  8061. }
  8062. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8063. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8064. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8065. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8066. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8067. {
  8068. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8069. goto end;
  8070. }
  8071. }
  8072. }
  8073. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8074. goto end;
  8075. }
  8076. //----------------------gunIndex is not 0 ------------------------------------------------//
  8077. //check Transaction active
  8078. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8079. {
  8080. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8081. {
  8082. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8083. {
  8084. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8085. goto end;
  8086. }
  8087. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8088. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8089. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8090. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8091. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8092. {
  8093. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8094. goto end;
  8095. }
  8096. else
  8097. {
  8098. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8099. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8100. goto end;
  8101. }
  8102. }
  8103. }//END FOR CHAdeMO_QUANTITY
  8104. for (int index = 0; index < CCS_QUANTITY; index++)
  8105. {
  8106. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8107. {
  8108. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8109. {
  8110. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8111. goto end;
  8112. }
  8113. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8114. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8115. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8116. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8117. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8118. {
  8119. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8120. goto end;
  8121. }
  8122. else
  8123. {
  8124. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8125. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8126. goto end;
  8127. }
  8128. }
  8129. }//END FOR CCS_QUANTITY
  8130. for (int index = 0; index < GB_QUANTITY; index++)
  8131. {
  8132. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8133. {
  8134. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8135. {
  8136. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8137. goto end;
  8138. }
  8139. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8140. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8141. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8142. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8143. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8144. {
  8145. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8146. goto end;
  8147. }
  8148. else
  8149. {
  8150. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8151. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8152. goto end;
  8153. }
  8154. }
  8155. }// END FOR GB_QUANTITY
  8156. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8157. {
  8158. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8159. {
  8160. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8161. {
  8162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8163. goto end;
  8164. }
  8165. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8166. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8167. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8168. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8169. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8170. {
  8171. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8172. goto end;
  8173. }
  8174. else
  8175. {
  8176. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8177. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8178. goto end;
  8179. }
  8180. }
  8181. }// END FOR GENERAL_GUN_QUANTITY
  8182. for (int index = 0; index < AC_QUANTITY; index++)
  8183. {
  8184. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8185. {
  8186. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8187. {
  8188. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8189. goto end;
  8190. }
  8191. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8192. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8193. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8194. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8195. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8196. {
  8197. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8198. goto end;
  8199. }
  8200. else
  8201. {
  8202. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8203. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8204. goto end;
  8205. }
  8206. }
  8207. }//END FOR AC_QUANTITY
  8208. }//END FOR AvailabilityTypeStr[Inoperative]
  8209. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8210. {
  8211. //----------------------gunIndex is 0 ------------------------------------------------//
  8212. if(gunIndex == 0)
  8213. {
  8214. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8215. {
  8216. for(int i=0; i < gunTotalNumber; i++)
  8217. {
  8218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8219. {
  8220. 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
  8221. {
  8222. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8223. goto end;
  8224. }
  8225. }//END FOR CHAdeMO_QUANTITY
  8226. for (int index = 0; index < CCS_QUANTITY; index++)
  8227. {
  8228. 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
  8229. {
  8230. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8231. goto end;
  8232. }
  8233. }//END FOR CCS_QUANTITY
  8234. for (int index = 0; index < GB_QUANTITY; index++)
  8235. {
  8236. 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
  8237. {
  8238. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8239. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8240. goto end;
  8241. }
  8242. }// END FOR GB_QUANTITY
  8243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8244. {
  8245. 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
  8246. {
  8247. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8248. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8249. goto end;
  8250. }
  8251. }// END FOR GENERAL_GUN_QUANTITY
  8252. for (int index = 0; index < AC_QUANTITY; index++)
  8253. {
  8254. 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
  8255. {
  8256. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8257. goto end;
  8258. }
  8259. }//END FOR CHAdeMO_QUANTITY
  8260. }// END FOR gunTotalNumber
  8261. }
  8262. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8263. {
  8264. for(int i=0; i < gunTotalNumber; i++)
  8265. {
  8266. for (int index = 0; index < AC_QUANTITY; index++)
  8267. {
  8268. 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
  8269. {
  8270. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8271. goto end;
  8272. }
  8273. }//END FOR CHAdeMO_QUANTITY
  8274. } // END FOR gunTotalNumber
  8275. }
  8276. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8277. goto end;
  8278. }
  8279. //----------------------gunIndex is not 0 ------------------------------------------------//
  8280. //check Transaction active
  8281. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8282. {
  8283. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8284. {
  8285. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8286. goto end;
  8287. }
  8288. }//END FOR CHAdeMO_QUANTITY
  8289. for (int index = 0; index < CCS_QUANTITY; index++)
  8290. {
  8291. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8292. {
  8293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8294. goto end;
  8295. }
  8296. }//END FOR CCS_QUANTITY
  8297. for (int index = 0; index < GB_QUANTITY; index++)
  8298. {
  8299. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8300. {
  8301. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8302. goto end;
  8303. }
  8304. }// END FOR GB_QUANTITY
  8305. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8306. {
  8307. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8308. {
  8309. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8310. goto end;
  8311. }
  8312. }// END FOR GENERAL_GUN_QUANTITY
  8313. for (int index = 0; index < AC_QUANTITY; index++)
  8314. {
  8315. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8316. {
  8317. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8318. goto end;
  8319. }
  8320. }//END FOR AC_QUANTITY
  8321. }//END FOR AvailabilityTypeStr[Operative]
  8322. end:
  8323. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8324. {
  8325. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8326. }
  8327. else
  8328. {
  8329. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8330. }
  8331. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8332. {
  8333. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8334. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8335. }
  8336. else if(gunIndex == 0)
  8337. {
  8338. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8339. {
  8340. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8341. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8342. }
  8343. }
  8344. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8345. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8346. return result;
  8347. }
  8348. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8349. {
  8350. mtrace();
  8351. int valueInvalid = NO;
  8352. int result = FAIL;
  8353. char keystr[40]={0};
  8354. char valuestr[501]={0}; //value should be limited in 500 bytes
  8355. char comfirmstr[20]={0};
  8356. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8357. json_object *ChangeConfiguration;
  8358. ChangeConfiguration = json_tokener_parse(payload);
  8359. if(!is_error(ChangeConfiguration))
  8360. {
  8361. // Required data
  8362. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8363. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8364. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8365. {
  8366. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8367. }
  8368. else
  8369. {
  8370. valueInvalid = YES;
  8371. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8372. }
  8373. }
  8374. json_object_put(ChangeConfiguration);
  8375. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8376. {
  8377. DEBUG_ERROR("Payload is null or not accepted.\n");
  8378. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8379. }
  8380. else
  8381. {
  8382. int status = setKeyValue(keystr, valuestr);
  8383. switch(status)
  8384. {
  8385. case ConfigurationStatus_Accepted:
  8386. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8387. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8388. StoreConfigurationTable();
  8389. break;
  8390. case RebootRequired:
  8391. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8392. StoreConfigurationTable();
  8393. break;
  8394. case NotSupported:
  8395. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8396. break;
  8397. case ConfigurationStatus_Rejected:
  8398. default:
  8399. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8400. break;
  8401. }
  8402. }
  8403. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8404. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8405. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8406. {
  8407. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8408. SetOcppConnStatus(FALSE);
  8409. }
  8410. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8411. {
  8412. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8413. }
  8414. return result;
  8415. }
  8416. int handleClearCacheRequest(char *uuid, char *payload)
  8417. {
  8418. mtrace();
  8419. int result = FAIL;
  8420. char comfirmstr[20];
  8421. char rmFileCmd[100]={0};
  8422. struct stat stats;
  8423. DEBUG_INFO("handleClearCacheRequest...\n");
  8424. stat("/Storage/OCPP_PH", &stats);
  8425. // Check for directory existence
  8426. if (S_ISDIR(stats.st_mode) == 1)
  8427. {}
  8428. else
  8429. {
  8430. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8431. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8432. system(rmFileCmd);
  8433. }
  8434. if(OCPP_cleanLocalCache())
  8435. {
  8436. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8437. }
  8438. else
  8439. {
  8440. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8441. }
  8442. sendClearCacheConfirmation(uuid, comfirmstr);
  8443. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8444. return result;
  8445. }
  8446. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8447. {
  8448. mtrace();
  8449. int result = FAIL;
  8450. int resultRename;
  8451. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8452. char chargingProfilePurposeStr[26]={0};
  8453. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8454. char tempchargingProfilePurposeStr[26]={0};
  8455. char str[100]={0};
  8456. char fname[200]={0};
  8457. char comfirmstr[20]={0};
  8458. char word[1600]={0};
  8459. int clearflag = FALSE;
  8460. int chargingProfileIdIsNULL = FALSE;
  8461. int connectorIsNULL = FALSE;
  8462. int chargingProfilePurposeIsNULL = FALSE;
  8463. int stackLevelIsNULL = FALSE;
  8464. //int GotoEnd = FALSE;
  8465. FILE *fptr1, *fptr2;
  8466. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8467. int n_chargingProfile=0;
  8468. int isEmptyFile = FALSE;
  8469. char sLineWord[1600]={0};
  8470. char chargingProfiles[10][100]={0};
  8471. int ChargeProfileCount = 0;
  8472. int ch;
  8473. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8474. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8475. json_object *ClearChargingProfile;
  8476. ClearChargingProfile = json_tokener_parse(payload);
  8477. if(!is_error(ClearChargingProfile))
  8478. {
  8479. // Optional data
  8480. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8481. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8482. else
  8483. chargingProfileIdIsNULL = TRUE;
  8484. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8485. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8486. else
  8487. connectorIsNULL = TRUE;
  8488. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8489. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8490. else
  8491. chargingProfilePurposeIsNULL = TRUE;
  8492. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8493. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8494. else
  8495. stackLevelIsNULL = TRUE;
  8496. }
  8497. json_object_put(ClearChargingProfile);
  8498. if(connectorIsNULL == FALSE)
  8499. {
  8500. switch(connectorIdInt)
  8501. {
  8502. case 0:
  8503. if(chargingProfilePurposeIsNULL == TRUE)
  8504. {
  8505. int l = 0;
  8506. strcpy(fname, ChargePointMaxProfile_JSON);
  8507. if((access(fname,F_OK))!=-1)
  8508. {
  8509. strcpy(chargingProfiles[l], fname);
  8510. l = l + 1;
  8511. }
  8512. strcpy(fname, TxDefaultProfile_0_JSON);
  8513. if((access(fname,F_OK))!=-1)
  8514. {
  8515. strcpy(chargingProfiles[l], fname);
  8516. l = l + 1;
  8517. }
  8518. ChargeProfileCount = l;
  8519. }
  8520. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8521. {
  8522. strcpy(fname, ChargePointMaxProfile_JSON);
  8523. if((access(fname,F_OK))!=-1)
  8524. {
  8525. strcpy(chargingProfiles[0], fname);
  8526. ChargeProfileCount = 1;
  8527. }
  8528. }
  8529. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8530. {
  8531. strcpy(fname, TxDefaultProfile_0_JSON);
  8532. if((access(fname,F_OK))!=-1)
  8533. {
  8534. strcpy(chargingProfiles[0], fname);
  8535. ChargeProfileCount = 1;
  8536. }
  8537. }
  8538. break;
  8539. default:
  8540. if(chargingProfilePurposeIsNULL == TRUE)
  8541. {
  8542. int m = 0;
  8543. memset(fname, 0, ARRAY_SIZE(fname));
  8544. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8545. if((access(fname,F_OK))!=-1)
  8546. {
  8547. strcpy(chargingProfiles[m], fname);
  8548. m = m + 1;
  8549. }
  8550. memset(fname, 0, ARRAY_SIZE(fname));
  8551. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8552. if((access(fname,F_OK))!=-1)
  8553. {
  8554. strcpy(chargingProfiles[m], fname);
  8555. m = m + 1;
  8556. }
  8557. ChargeProfileCount = m;
  8558. }
  8559. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8560. {
  8561. //strcpy(fname, TxDefaultProfile_1_JSON);
  8562. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8563. if((access(fname,F_OK))!=-1)
  8564. {
  8565. strcpy(chargingProfiles[0], fname);
  8566. ChargeProfileCount = 1;
  8567. }
  8568. }
  8569. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8570. {
  8571. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8572. if((access(fname,F_OK))!=-1)
  8573. {
  8574. strcpy(chargingProfiles[0], fname);
  8575. ChargeProfileCount = 1;
  8576. }
  8577. //strcpy(fname, TxProfile_1_JSON);
  8578. }
  8579. //strcpy(fname, ChargePointMaxProfile_JSON );
  8580. break;
  8581. }
  8582. }
  8583. else // Check all Charging Profiles
  8584. {
  8585. int i = 0;
  8586. char fnametemp[200]={0};
  8587. ChargeProfileCount = 0;
  8588. //Check ChargePointMaxProfile.json exit
  8589. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8590. {
  8591. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8592. i = i + 1;
  8593. }
  8594. //Check TxDefaultProfile_0.json exit
  8595. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8596. {
  8597. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8598. i = i + 1;
  8599. }
  8600. //Check TxDefaultProfile_%d.json
  8601. for(int j=1; j <= gunTotalNumber; j++)
  8602. {
  8603. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8604. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8605. if((access(fnametemp,F_OK))!=-1)
  8606. {
  8607. strcpy(chargingProfiles[i], fnametemp);
  8608. i = i + 1;
  8609. }
  8610. }
  8611. //Check TxProfile_%d.json
  8612. for(int j=1; j <= gunTotalNumber; j++)
  8613. {
  8614. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8615. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8616. if((access(fnametemp,F_OK))!=-1)
  8617. {
  8618. strcpy(chargingProfiles[i], fnametemp);
  8619. i = i + 1;
  8620. }
  8621. }
  8622. ChargeProfileCount = i;
  8623. }// End connectorIsNULL is TRUE
  8624. if(ChargeProfileCount == 0)
  8625. {
  8626. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8627. goto end;
  8628. }
  8629. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8630. {
  8631. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8632. goto end;
  8633. }
  8634. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8635. {
  8636. memset(str, 0, ARRAY_SIZE(str));
  8637. // clear temp file
  8638. sprintf(str,"rm -f %s",temp);
  8639. system(str);
  8640. for(int k=0; k < ChargeProfileCount; k++)
  8641. {
  8642. memset(str, 0, ARRAY_SIZE(str));
  8643. //clear file in C
  8644. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8645. system(str);
  8646. }
  8647. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8648. goto end;
  8649. }
  8650. else if(connectorIsNULL == TRUE)
  8651. {
  8652. for(int k=0; k < ChargeProfileCount; k++)
  8653. {
  8654. fptr1 = fopen(chargingProfiles[k], "r");
  8655. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8656. //Check Charging Profile Count
  8657. while(fscanf(fptr1, "%s", word) != EOF)
  8658. {
  8659. //DEBUG_INFO("word=%s\n",word);
  8660. if(strstr(word, "chargingProfileId")!= NULL)
  8661. {
  8662. //DEBUG_INFO("test chargingProfileId \n");
  8663. n_chargingProfile = n_chargingProfile + 1;
  8664. //DEBUG_INFO("chargingProfileId Found\n");
  8665. }
  8666. }
  8667. rewind(fptr1);
  8668. //search Charging Profile Element
  8669. //int i= 0;
  8670. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8671. {
  8672. json_object *tmpProfilee;
  8673. tmpProfilee = json_tokener_parse(sLineWord);
  8674. if(!is_error(tmpProfilee))
  8675. {
  8676. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8677. {
  8678. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8679. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8680. }
  8681. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8682. {
  8683. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8684. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8685. }
  8686. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8687. {
  8688. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8689. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8690. }
  8691. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8692. {
  8693. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8694. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8695. }
  8696. }
  8697. json_object_put(tmpProfilee);
  8698. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8699. {
  8700. //------- not write to fptr2-------//
  8701. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8702. //clearflag = TRUE;
  8703. }
  8704. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8705. {
  8706. //------- not write to fptr2-------//
  8707. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8708. }
  8709. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8710. {
  8711. //------- not write to fptr2-------//
  8712. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8713. }
  8714. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8715. {
  8716. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8717. }
  8718. else
  8719. {
  8720. fprintf(fptr2, sLineWord);//writing data into file
  8721. }
  8722. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8723. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8724. if(clearflag == TRUE)
  8725. {
  8726. fclose(fptr1);
  8727. fclose(fptr2);
  8728. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8729. system(str);
  8730. // clear temp file
  8731. sprintf(str,"rm -f %s",temp);
  8732. system(str);
  8733. }
  8734. else
  8735. {
  8736. fclose(fptr1);
  8737. fclose(fptr2);
  8738. memset(str, 0, ARRAY_SIZE(str));
  8739. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8740. system(str);
  8741. resultRename = rename(temp, chargingProfiles[k]);
  8742. if(resultRename == 0)
  8743. {
  8744. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8745. }
  8746. else
  8747. {
  8748. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8749. }
  8750. if(comfirmstr[0]== 0)
  8751. {
  8752. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8753. }
  8754. //Check chargingProfile is empty file
  8755. /*------ Read the file ----------------*/
  8756. fptr1=fopen(chargingProfiles[k],"r");
  8757. ch=fgetc(fptr1);
  8758. rewind(fptr1);
  8759. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8760. if(ch!=EOF)
  8761. {
  8762. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8763. {
  8764. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8765. if(sLineWord[0]=='\0')
  8766. {
  8767. isEmptyFile = TRUE;
  8768. break;
  8769. }
  8770. else
  8771. {
  8772. isEmptyFile = FALSE;
  8773. break;
  8774. }
  8775. }
  8776. }
  8777. else
  8778. isEmptyFile = TRUE;
  8779. fclose(fptr1);
  8780. if(isEmptyFile == TRUE)
  8781. {
  8782. memset(str, 0, ARRAY_SIZE(str));
  8783. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8784. system(str);
  8785. }
  8786. }
  8787. }// End of while(int k=0; k < ChargePointCount; k++)
  8788. }
  8789. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8790. {
  8791. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8792. for(int k=0; k < ChargeProfileCount; k++)
  8793. {
  8794. fptr1 = fopen(chargingProfiles[k], "r");
  8795. fptr2 = fopen(temp, "w+");
  8796. //Check Charging Profile Count
  8797. while(fscanf(fptr1, "%s", word) != EOF)
  8798. {
  8799. //DEBUG_INFO("word=%s\n",word);
  8800. if(strstr(word, "chargingProfileId")!= NULL)
  8801. {
  8802. n_chargingProfile = n_chargingProfile + 1;
  8803. }
  8804. }
  8805. rewind(fptr1);
  8806. //search Charging Profile Element
  8807. //int i= 0;
  8808. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8809. {
  8810. json_object *tmpProfilee;
  8811. tmpProfilee = json_tokener_parse(sLineWord);
  8812. if(!is_error(tmpProfilee))
  8813. {
  8814. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8815. {
  8816. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8817. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8818. }
  8819. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8820. {
  8821. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8822. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8823. }
  8824. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8825. {
  8826. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8827. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8828. }
  8829. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8830. {
  8831. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8832. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8833. }
  8834. }
  8835. json_object_put(tmpProfilee);
  8836. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8837. {
  8838. //------- not write to fptr2-------//
  8839. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8840. //clearflag = TRUE;
  8841. }
  8842. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8843. {
  8844. //------- not write to fptr2-------//
  8845. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8846. }
  8847. else if(stackLevelIsNULL == TRUE)
  8848. {
  8849. //Clear Whole File
  8850. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8851. clearflag = TRUE;
  8852. break;
  8853. }
  8854. else
  8855. {
  8856. fprintf(fptr2, sLineWord);//writing data into file
  8857. }
  8858. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8859. }
  8860. if(clearflag == TRUE)
  8861. {
  8862. fclose(fptr1);
  8863. fclose(fptr2);
  8864. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8865. system(str);
  8866. // clear temp file
  8867. sprintf(str,"rm -f %s",temp);
  8868. system(str);
  8869. }
  8870. else
  8871. {
  8872. fclose(fptr1);
  8873. fclose(fptr2);
  8874. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8875. system(str);
  8876. resultRename = rename(temp, chargingProfiles[k]);
  8877. if(resultRename == 0)
  8878. {
  8879. DEBUG_INFO("File ChargingProfile renamed successfully");
  8880. }
  8881. else
  8882. {
  8883. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8884. }
  8885. if(comfirmstr[0]== 0)
  8886. {
  8887. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8888. }
  8889. //Check chargingProfile is empty file
  8890. /*------ Read the file ----------------*/
  8891. fptr1=fopen(chargingProfiles[k],"r");
  8892. ch=fgetc(fptr1);
  8893. rewind(fptr1);
  8894. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8895. if(ch!=EOF)
  8896. {
  8897. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8898. {
  8899. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8900. if(sLineWord[0]=='\0')
  8901. {
  8902. isEmptyFile = TRUE;
  8903. break;
  8904. }
  8905. else
  8906. {
  8907. isEmptyFile = FALSE;
  8908. break;
  8909. }
  8910. }
  8911. }
  8912. else
  8913. isEmptyFile = TRUE;
  8914. fclose(fptr1);
  8915. if(isEmptyFile == TRUE)
  8916. {
  8917. memset(str, 0, ARRAY_SIZE(str));
  8918. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8919. system(str);
  8920. }
  8921. /*------- End of reading ---------------*/
  8922. }
  8923. } // while(int k=0; k < ChargeProfileCount; k++)
  8924. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8925. end:
  8926. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8927. {
  8928. if(connectorIdInt == 0)
  8929. {
  8930. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8931. {
  8932. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8933. }
  8934. }
  8935. else
  8936. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8937. }
  8938. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8939. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8940. return result;
  8941. }
  8942. void createFirmwareVersionByDataTransfer(void)
  8943. {
  8944. json_object *FirmwareDataTransfer = json_object_new_object();
  8945. // AC & DC model
  8946. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8947. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8948. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8949. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8950. // DC model
  8951. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8952. {
  8953. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8954. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8955. (gunType[3] != GUN_TYPE_UNKNOWN))
  8956. {
  8957. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8958. }
  8959. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8960. {
  8961. // DS DM DW
  8962. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8963. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8964. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8965. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8966. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8967. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8968. }
  8969. else
  8970. {
  8971. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8972. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8973. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8974. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8975. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8976. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8977. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8978. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8979. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8980. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8981. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8982. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8983. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8984. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8985. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8986. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8987. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8988. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8989. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8990. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8991. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8992. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8993. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8994. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8995. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8996. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8997. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8998. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8999. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9000. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9001. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9002. }
  9003. }
  9004. // 4G model
  9005. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9006. {
  9007. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9008. }
  9009. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9010. json_object_put(FirmwareDataTransfer);
  9011. }
  9012. int handleDataTransferRequest(char *uuid, char *payload)
  9013. {
  9014. mtrace();
  9015. json_object *response = json_object_new_object();
  9016. int result = FAIL;
  9017. char tempvendorId[255]={0};
  9018. char tempmessageId[50]={0};
  9019. char tempdata[1024]={0};
  9020. char message[2048]={0};
  9021. DEBUG_INFO("handleDataTransferRequest...\n");
  9022. if((uuid != NULL) && (payload != NULL))
  9023. {
  9024. json_object *DataTransfer;
  9025. DataTransfer = json_tokener_parse(payload);
  9026. if(!is_error(DataTransfer))
  9027. {
  9028. // Required data
  9029. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9030. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9031. // Optional data
  9032. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9033. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9034. if(json_object_object_get(DataTransfer, "data") != NULL)
  9035. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9036. result = PASS;
  9037. }
  9038. json_object_put(DataTransfer);
  9039. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9040. {
  9041. // Send all moudle firmware version on EVSE
  9042. createFirmwareVersionByDataTransfer();
  9043. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9044. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9045. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9046. json_object_put(response);
  9047. }
  9048. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9049. {
  9050. system("/usr/bin/run_tmate_restart.sh &");
  9051. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9052. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9053. json_object_put(response);
  9054. }
  9055. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9056. {
  9057. json_object *data;
  9058. data = json_tokener_parse(tempdata);
  9059. if(!is_error(data))
  9060. {
  9061. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9062. {
  9063. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9064. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9065. if(json_object_object_get(data, "SOC") != NULL)
  9066. {
  9067. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9068. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9069. }
  9070. if(json_object_object_get(data, "Energy") != NULL)
  9071. {
  9072. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9073. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9074. }
  9075. if(json_object_object_get(data, "Duration") != NULL)
  9076. {
  9077. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9078. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9079. }
  9080. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9081. }
  9082. else
  9083. {
  9084. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9085. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9086. }
  9087. }
  9088. else
  9089. {
  9090. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9091. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9092. }
  9093. json_object_put(data);
  9094. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9095. json_object_put(response);
  9096. }
  9097. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9098. {
  9099. json_object *data;
  9100. data = json_tokener_parse(tempdata);
  9101. if(!is_error(data))
  9102. {
  9103. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9104. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9105. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9106. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9107. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9108. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9109. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9110. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9111. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9112. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9113. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9114. }
  9115. else
  9116. {
  9117. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9118. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9119. }
  9120. json_object_put(data);
  9121. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9122. json_object_put(response);
  9123. }
  9124. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9125. {
  9126. json_object *data;
  9127. data = json_tokener_parse(tempdata);
  9128. if(!is_error(data))
  9129. {
  9130. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9131. if(json_object_object_get(data, "idToken") != NULL)
  9132. {
  9133. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9134. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9135. }
  9136. if(json_object_object_get(data, "price") != NULL)
  9137. {
  9138. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9139. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9140. }
  9141. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9142. }
  9143. else
  9144. {
  9145. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9146. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9147. }
  9148. json_object_put(data);
  9149. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9150. json_object_put(response);
  9151. }
  9152. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9153. {
  9154. json_object *data;
  9155. data = json_tokener_parse(tempdata);
  9156. if(!is_error(data))
  9157. {
  9158. if(json_object_object_get(data, "txId") != NULL)
  9159. {
  9160. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9161. for(int idx = 0;idx<gunTotalNumber;idx++)
  9162. {
  9163. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9164. {
  9165. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9166. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9167. if(json_object_object_get(data, "description") != NULL)
  9168. {
  9169. // California pricing V1.0
  9170. DEBUG_INFO("California pricing V1.0\n");
  9171. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9172. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9173. }
  9174. else
  9175. {
  9176. // California pricing V1.1
  9177. DEBUG_INFO("California pricing V1.1\n");
  9178. if(json_object_object_get(data, "timestamp") != NULL)
  9179. {
  9180. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9181. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9182. }
  9183. if(json_object_object_get(data, "meterValue") != NULL)
  9184. {
  9185. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9186. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9187. }
  9188. if(json_object_object_get(data, "cost") != NULL)
  9189. {
  9190. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9191. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9192. }
  9193. if(json_object_object_get(data, "state") != NULL)
  9194. {
  9195. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9196. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9197. }
  9198. if(json_object_object_get(data, "chargingPrice") != NULL)
  9199. {
  9200. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9201. {
  9202. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9203. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9204. }
  9205. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9206. {
  9207. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9208. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9209. }
  9210. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9211. {
  9212. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9213. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9214. }
  9215. }
  9216. if(json_object_object_get(data, "idlePrice") != NULL)
  9217. {
  9218. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9219. {
  9220. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9221. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9222. }
  9223. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9224. {
  9225. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9226. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9227. }
  9228. }
  9229. if(json_object_object_get(data, "nextPeriod") != NULL)
  9230. {
  9231. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9232. {
  9233. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9234. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9235. }
  9236. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9237. {
  9238. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9239. {
  9240. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  9241. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  9242. }
  9243. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9244. {
  9245. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  9246. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  9247. }
  9248. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9249. {
  9250. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  9251. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  9252. }
  9253. }
  9254. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9255. {
  9256. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9257. {
  9258. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  9259. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  9260. }
  9261. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9262. {
  9263. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  9264. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  9265. }
  9266. }
  9267. }
  9268. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9269. {
  9270. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9271. {
  9272. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9273. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9274. }
  9275. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9276. {
  9277. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9278. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9279. }
  9280. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9281. {
  9282. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9283. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9284. }
  9285. }
  9286. }
  9287. }
  9288. }
  9289. }
  9290. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9291. }
  9292. else
  9293. {
  9294. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9295. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9296. }
  9297. json_object_put(data);
  9298. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9299. json_object_put(response);
  9300. }
  9301. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9302. {
  9303. json_object *data;
  9304. data = json_tokener_parse(tempdata);
  9305. if(!is_error(data))
  9306. {
  9307. if(json_object_object_get(data, "txId") != NULL)
  9308. {
  9309. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9310. for(int idx = 0;idx<gunTotalNumber;idx++)
  9311. {
  9312. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9313. {
  9314. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9315. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9316. if(json_object_object_get(data, "description") != NULL)
  9317. {
  9318. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9319. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9320. }
  9321. }
  9322. }
  9323. }
  9324. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9325. }
  9326. else
  9327. {
  9328. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9329. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9330. }
  9331. json_object_put(data);
  9332. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9333. json_object_put(response);
  9334. }
  9335. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9336. {
  9337. json_object *data;
  9338. data = json_tokener_parse(tempdata);
  9339. if(!is_error(data))
  9340. {
  9341. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9342. if(json_object_object_get(data, "Content_Type") != NULL)
  9343. {
  9344. 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))
  9345. {
  9346. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9347. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9348. {
  9349. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9350. }
  9351. }
  9352. else
  9353. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9354. }
  9355. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9356. }
  9357. else
  9358. {
  9359. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9360. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9361. }
  9362. json_object_put(data);
  9363. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9364. json_object_put(response);
  9365. }
  9366. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9367. {
  9368. json_object *data;
  9369. data = json_tokener_parse(tempdata);
  9370. if(!is_error(data))
  9371. {
  9372. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9373. if(json_object_object_get(data, "ConnectorId") != NULL)
  9374. {
  9375. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9376. }
  9377. if(json_object_object_get(data, "SerialNo") != NULL)
  9378. {
  9379. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9380. }
  9381. if(json_object_object_get(data, "Page_Index") != NULL)
  9382. {
  9383. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9384. }
  9385. if(json_object_object_get(data, "Duration") != NULL)
  9386. {
  9387. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9388. }
  9389. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9390. }
  9391. else
  9392. {
  9393. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9394. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9395. }
  9396. json_object_put(data);
  9397. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9398. json_object_put(response);
  9399. }
  9400. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9401. {
  9402. json_object *data;
  9403. data = json_tokener_parse(tempdata);
  9404. if(!is_error(data))
  9405. {
  9406. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9407. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9408. {
  9409. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9410. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9411. else
  9412. {
  9413. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9414. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9415. }
  9416. }
  9417. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9418. {
  9419. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9420. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9421. else
  9422. {
  9423. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9424. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9425. }
  9426. }
  9427. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9428. {
  9429. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9430. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9431. else
  9432. {
  9433. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9434. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9435. }
  9436. }
  9437. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9438. {
  9439. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9440. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9441. else
  9442. {
  9443. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9444. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9445. }
  9446. }
  9447. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9448. {
  9449. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9450. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9451. else
  9452. {
  9453. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9454. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9455. }
  9456. }
  9457. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9458. {
  9459. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9460. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9461. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9462. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9463. else
  9464. {
  9465. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9466. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9467. }
  9468. }
  9469. if(json_object_object_get(data, "isAuthentication") != NULL)
  9470. {
  9471. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9472. {
  9473. case 0:
  9474. case 1:
  9475. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9476. break;
  9477. default:
  9478. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9479. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9480. break;
  9481. }
  9482. }
  9483. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9484. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9485. }
  9486. else
  9487. {
  9488. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9489. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9490. }
  9491. json_object_put(data);
  9492. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9493. json_object_put(response);
  9494. }
  9495. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9496. {
  9497. json_object *data;
  9498. data = json_tokener_parse(tempdata);
  9499. if(!is_error(data))
  9500. {
  9501. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9502. if(json_object_object_get(data, "stationName") != NULL)
  9503. {
  9504. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9505. }
  9506. else
  9507. {
  9508. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9509. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9510. }
  9511. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9512. {
  9513. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9514. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9515. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9516. }
  9517. }
  9518. else
  9519. {
  9520. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9521. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9522. }
  9523. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9524. json_object_put(response);
  9525. }
  9526. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9527. {
  9528. json_object *data;
  9529. data = json_tokener_parse(tempdata);
  9530. if(!is_error(data))
  9531. {
  9532. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9533. if(json_object_object_get(data, "weatherId") != NULL)
  9534. {
  9535. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9536. }
  9537. else
  9538. {
  9539. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9540. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9541. }
  9542. if(json_object_object_get(data, "Temperature") != NULL)
  9543. {
  9544. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9545. }
  9546. else
  9547. {
  9548. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9549. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9550. }
  9551. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9552. {
  9553. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9554. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9555. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9556. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9557. }
  9558. }
  9559. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9560. {
  9561. json_object *data;
  9562. data = json_tokener_parse(tempdata);
  9563. if(!is_error(data))
  9564. {
  9565. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9566. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9567. {
  9568. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9569. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9570. }
  9571. else
  9572. {
  9573. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9574. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9575. }
  9576. }
  9577. else
  9578. {
  9579. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9580. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9581. }
  9582. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9583. json_object_put(response);
  9584. }
  9585. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9586. {
  9587. json_object *data;
  9588. data = json_tokener_parse(tempdata);
  9589. if(!is_error(data))
  9590. {
  9591. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9592. {
  9593. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9594. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9595. if(gun_index < gunTotalNumber)
  9596. {
  9597. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9598. {
  9599. json_object *responsedata = json_object_new_object();
  9600. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9601. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9602. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9603. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9604. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9605. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9606. }
  9607. else
  9608. {
  9609. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9610. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9611. }
  9612. }
  9613. else
  9614. {
  9615. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9616. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9617. }
  9618. }
  9619. else
  9620. {
  9621. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9622. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9623. }
  9624. }
  9625. else
  9626. {
  9627. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9628. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9629. }
  9630. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9631. json_object_put(response);
  9632. }
  9633. else
  9634. {
  9635. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9636. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9637. }
  9638. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9639. json_object_put(response);
  9640. }
  9641. else
  9642. {
  9643. // Can not find valid message id
  9644. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9645. }
  9646. }
  9647. else
  9648. {
  9649. // Payload is null
  9650. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9651. }
  9652. LWS_Send(message);
  9653. return result;
  9654. }
  9655. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9656. {
  9657. mtrace();
  9658. int result = FAIL;
  9659. int connectorIdInt, durationInt;
  9660. char chargingRateUnitStr[4]={0};
  9661. char comfirmstr[20];
  9662. int confirmPeriods = 0;
  9663. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9664. json_object *GetCompositeSchedule;
  9665. GetCompositeSchedule = json_tokener_parse(payload);
  9666. if(!is_error(GetCompositeSchedule))
  9667. {
  9668. // Required data
  9669. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9670. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9671. else
  9672. connectorIdInt = -1;
  9673. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9674. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9675. else
  9676. durationInt = 86400;
  9677. // Optional data
  9678. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9679. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9680. }
  9681. json_object_put(GetCompositeSchedule);
  9682. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9683. if((connectorIdInt == 0) ||
  9684. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9685. {
  9686. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9687. struct StructChargingProfile tmpProfile[1];
  9688. if(strstr(chargingRateUnitStr, "W") != NULL)
  9689. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9690. else
  9691. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9692. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9693. {
  9694. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9695. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9696. }
  9697. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9698. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9699. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9700. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9701. {
  9702. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9703. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9704. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9705. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9706. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9707. {
  9708. confirmPeriods = idx;
  9709. break;
  9710. }
  9711. }
  9712. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9713. {
  9714. confirmPeriods += 1;
  9715. }
  9716. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9717. }
  9718. else
  9719. {
  9720. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9721. }
  9722. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9723. return result;
  9724. }
  9725. int handleGetConfigurationRequest(char *uuid, char *payload)
  9726. {
  9727. mtrace();
  9728. int result = FAIL;
  9729. int MaxKeySupported = 0;
  9730. int n_keys = 0;
  9731. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9732. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9733. json_object *GetConfiguration;
  9734. GetConfiguration = json_tokener_parse(payload);
  9735. if(!is_error(GetConfiguration))
  9736. {
  9737. // Optional data
  9738. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9739. {
  9740. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9741. {
  9742. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9743. n_keys = idx + 1;
  9744. }
  9745. }
  9746. }
  9747. json_object_put(GetConfiguration);
  9748. UnknownKeynum = 0;
  9749. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9750. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9751. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9752. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9753. if(n_keys != 0)
  9754. {
  9755. for(int i=0;i<n_keys;i++)
  9756. {
  9757. getKeyValue(requestKey[i]);
  9758. }
  9759. }
  9760. else
  9761. {
  9762. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9763. getKeyValue("");
  9764. }
  9765. processUnkownKey();
  9766. sendGetConfigurationConfirmation(uuid);
  9767. return result;
  9768. }
  9769. static char fnamePlusPath[100]={0};
  9770. static char fnamePWithNoPath[60]={0};
  9771. void checkUploadLog(void)
  9772. {
  9773. FILE *fp;
  9774. /* Open the command for reading. */
  9775. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9776. if (fp == NULL) {
  9777. DEBUG_WARN("Failed to run command\n" );
  9778. exit(1);
  9779. }
  9780. int ftppathlen = 0;
  9781. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9782. int i = 0;
  9783. /* Read the output a line at a time - output it. */
  9784. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9785. if(i==0)
  9786. {
  9787. ftppathlen = strlen(fnamePlusPath);
  9788. DEBUG_INFO("%s\n", fnamePlusPath);
  9789. fnamePlusPath[ftppathlen]='\0';
  9790. break;
  9791. }
  9792. i= i+1;
  9793. }
  9794. /* close */
  9795. pclose(fp);
  9796. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9797. {
  9798. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9799. {
  9800. fnamePlusPath[k]='\0';
  9801. }
  9802. }
  9803. i=1;
  9804. //char fname[60]={0};
  9805. while(i < ftppathlen)
  9806. {
  9807. int len=ftppathlen-i;
  9808. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9809. {
  9810. DEBUG_INFO("compare '/' all right\n");
  9811. break;
  9812. }
  9813. i=i+1;
  9814. }
  9815. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9816. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9817. fnamePWithNoPath[i+1] = '\0';
  9818. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9819. {
  9820. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9821. {
  9822. fnamePWithNoPath[j]='\0';
  9823. }
  9824. }
  9825. FILE* fp1 = fopen(fnamePlusPath, "r");
  9826. if (fp1)
  9827. {
  9828. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9829. // file exists
  9830. fclose(fp1);
  9831. }
  9832. else
  9833. {
  9834. // file doesn't exist
  9835. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9836. }
  9837. }
  9838. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9839. {
  9840. mtrace();
  9841. int result = FAIL;
  9842. time_t CurrentTime;
  9843. struct tm *tm;
  9844. pthread_t th_Status;
  9845. CurrentTime = time(NULL);
  9846. tm = localtime(&CurrentTime);
  9847. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9848. 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);
  9849. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9850. if(!interLock.isGetDiagnosticGoing)
  9851. {
  9852. interLock.isGetDiagnosticGoing = 1;
  9853. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9854. sleep(1);
  9855. }
  9856. else
  9857. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9858. return result;
  9859. }
  9860. void* GetDiagnosticsProcess(void* data)
  9861. {
  9862. pthread_detach(pthread_self());
  9863. mtrace();
  9864. int retriesInt=0, retryIntervalInt=0;
  9865. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9866. 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};
  9867. int port=0;
  9868. int isSuccess = FALSE;
  9869. char ftpbuf[200]={0};
  9870. char cmdBuf[2048];
  9871. struct tm *tmNow;
  9872. time_t CurrentTime;
  9873. struct tm tmStart;
  9874. struct tm tmStop;
  9875. CurrentTime = time(NULL);
  9876. tmNow=localtime(&CurrentTime);
  9877. uint16_t targetYear, targetMonth;
  9878. json_object *GetDiagnostics;
  9879. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9880. GetDiagnostics = json_tokener_parse(data);
  9881. if(!is_error(GetDiagnostics))
  9882. {
  9883. // Required data
  9884. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9885. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9886. // Optional data
  9887. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9888. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9889. else
  9890. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9891. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9892. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9893. else
  9894. retryIntervalInt = 30;
  9895. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9896. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9897. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9898. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9899. }
  9900. json_object_put(GetDiagnostics);
  9901. // Pack log to compress file
  9902. 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) &&
  9903. (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))
  9904. {
  9905. // Pack system log
  9906. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9907. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9908. targetYear = tmStart.tm_year;
  9909. targetMonth = tmStart.tm_mon;
  9910. do
  9911. {
  9912. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9913. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9914. if(targetMonth+1>=13)
  9915. {
  9916. targetYear += 1;
  9917. targetMonth = 1;
  9918. }
  9919. else
  9920. {
  9921. targetMonth += 1;
  9922. }
  9923. }while((targetYear < (tmNow->tm_year+1900)) ||
  9924. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9925. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9926. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9927. system(cmdBuf);
  9928. // Pack charging & event log
  9929. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9930. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9931. targetYear = tmStart.tm_year;
  9932. targetMonth = tmStart.tm_mon;
  9933. do
  9934. {
  9935. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9936. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9937. if(targetMonth+1>=13)
  9938. {
  9939. targetYear += 1;
  9940. targetMonth = 1;
  9941. }
  9942. else
  9943. {
  9944. targetMonth += 1;
  9945. }
  9946. }while((targetYear < (tmNow->tm_year+1900)) ||
  9947. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9948. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9949. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9950. system(cmdBuf);
  9951. // Combine log file
  9952. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9953. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9954. }
  9955. else
  9956. {
  9957. system("exec /root/logPackTools 'log' 6");
  9958. }
  9959. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9960. system(cmdBuf);
  9961. checkUploadLog();
  9962. //****************location*******************/
  9963. if(strcmp(locationstr,"")==0)
  9964. {
  9965. DEBUG_INFO("location is <Empty>!\n");
  9966. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9967. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9968. goto end;
  9969. }
  9970. memset(protocol, 0, ARRAY_SIZE(protocol));
  9971. memset(user, 0, ARRAY_SIZE(user) );
  9972. memset(password, 0, ARRAY_SIZE(password));
  9973. memset(host, 0, ARRAY_SIZE(host));
  9974. memset(path, 0, ARRAY_SIZE(path));
  9975. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9976. memset(host1, 0, ARRAY_SIZE(host1));
  9977. memset(path1, 0, ARRAY_SIZE(path1));
  9978. /*location: ftp://user:password@host:port/path*/
  9979. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9980. if((access(fnamePlusPath,F_OK))!=-1)
  9981. {
  9982. DEBUG_INFO("fnamePlusPath exist.\n");
  9983. }
  9984. else
  9985. {
  9986. DEBUG_INFO("fnamePlusPath not exist!\n");
  9987. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9988. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9989. goto end;
  9990. }
  9991. if(strchr(locationstr,'@')==NULL)
  9992. {
  9993. sscanf(locationstr,
  9994. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9995. protocol, host, &port, path);
  9996. strcpy(user,"anonymous");
  9997. strcpy(password,"");
  9998. }
  9999. else
  10000. {
  10001. //DEBUG_INFO("pch=%s\n", pch);
  10002. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10003. protocol, user, password, host, &port, path);
  10004. }
  10005. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10006. {
  10007. DEBUG_INFO("protocol is not ftp/http ! \n");
  10008. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10009. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10010. goto end;
  10011. }
  10012. if(strncmp(locationstr,"http", 4) == 0)
  10013. {
  10014. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10015. sprintf(ftppath,"/%s", path);
  10016. do
  10017. {
  10018. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10019. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10020. sleep(3);
  10021. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10022. if(!isSuccess)
  10023. {
  10024. DEBUG_INFO("Diagnostics fail.\n");
  10025. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10026. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10027. sleep(retryIntervalInt);
  10028. }
  10029. else
  10030. {
  10031. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10032. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10033. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10034. }
  10035. retriesInt--;
  10036. }while((isSuccess == 0)&&(retriesInt >= 0));
  10037. }
  10038. else
  10039. {
  10040. sscanf(host,"%[^/]%s",host1, path1);
  10041. if(strlen(path) > 0)
  10042. sprintf(ftppath,"/%s", path);
  10043. else
  10044. sprintf(ftppath,"/%s", path1);
  10045. int ftppathlen=strlen(ftppath);
  10046. int i=1;
  10047. char filenametemp[50];
  10048. while(i < ftppathlen)
  10049. {
  10050. int len=ftppathlen-i;
  10051. if(ftppath[len]== 47) // '/' ascll code: 47
  10052. {
  10053. DEBUG_INFO("find '/' all right\n");
  10054. break;
  10055. }
  10056. i=i+1;
  10057. }
  10058. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10059. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10060. filenametemp[i+1] = 0;
  10061. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10062. if(port == 0)
  10063. port = 21;
  10064. do
  10065. {
  10066. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10067. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10068. sleep(3);
  10069. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10070. if(!isSuccess)
  10071. {
  10072. DEBUG_INFO("Diagnostics fail.\n");
  10073. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10074. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10075. sleep(retryIntervalInt);
  10076. }
  10077. else
  10078. {
  10079. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10080. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10081. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10082. }
  10083. retriesInt--;
  10084. }while((!isSuccess)&&(retriesInt >= 0));
  10085. }
  10086. end:
  10087. system("rm -f /mnt/*");
  10088. sleep(5);
  10089. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10090. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10091. interLock.isGetDiagnosticGoing = 0;
  10092. pthread_exit(NULL);
  10093. }
  10094. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10095. {
  10096. mtrace();
  10097. int result = FAIL;
  10098. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10099. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10100. {
  10101. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10102. locallistVersion = -1;
  10103. }
  10104. else
  10105. {
  10106. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10107. locallistVersion = 0;
  10108. OCPP_getListVerion();
  10109. }
  10110. //from db.OCPP_getListVerion
  10111. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10112. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10113. sendGetLocalListVersionConfirmation(uuid,"");
  10114. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10115. return result;
  10116. }
  10117. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10118. {
  10119. mtrace();
  10120. int result = FAIL;
  10121. int connectorIdInt=-1;
  10122. int tempIndex = 0;
  10123. int connectorIdIsNULL, chargingProfileIsNULL;
  10124. char comfirmstr[20]={0};
  10125. char cmdBuf[512];
  10126. json_object *RemoteStartTransaction;
  10127. FILE *fp;
  10128. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10129. if(server_pending == TRUE)
  10130. {
  10131. return 0;
  10132. }
  10133. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10134. RemoteStartTransaction = json_tokener_parse(payload);
  10135. if(!is_error(RemoteStartTransaction))
  10136. {
  10137. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10138. {
  10139. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10140. }
  10141. else
  10142. {
  10143. connectorIdIsNULL = TRUE;
  10144. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10145. {
  10146. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10147. {
  10148. connectorIdIsNULL = FALSE;
  10149. connectorIdInt = (gun_index+1);
  10150. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10151. break;
  10152. }
  10153. }
  10154. }
  10155. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10156. {
  10157. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10158. // Required data
  10159. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10160. // Optional data
  10161. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10162. {
  10163. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10164. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10165. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10166. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10167. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10168. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10169. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10170. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10171. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10172. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10173. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10174. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10175. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10176. {
  10177. 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")));
  10178. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10179. 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"));
  10180. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10181. 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"));
  10182. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10183. 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")));
  10184. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10185. {
  10186. 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++)
  10187. {
  10188. 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"));
  10189. 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"));
  10190. 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)
  10191. 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"));
  10192. }
  10193. }
  10194. }
  10195. }
  10196. else
  10197. {
  10198. chargingProfileIsNULL = TRUE;
  10199. }
  10200. }
  10201. }
  10202. else
  10203. {
  10204. connectorIdIsNULL = TRUE;
  10205. }
  10206. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10207. {
  10208. DEBUG_WARN("Connector id is NULL\n.");
  10209. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10210. goto end;
  10211. }
  10212. /*
  10213. enum _SYSTEM_STATUS
  10214. {
  10215. S_BOOTING = 0,
  10216. S_IDLE, = 1
  10217. S_AUTHORIZING, = 2
  10218. S_REASSIGN_CHECK, = 3
  10219. S_REASSIGN, = 4
  10220. S_PRECHARGE, = 5
  10221. S_PREPARING_FOR_EV, = 6
  10222. S_PREPARING_FOR_EVSE, = 7
  10223. S_CHARGING, = 8
  10224. S_TERMINATING, = 9
  10225. S_COMPLETE, = 10
  10226. S_ALARM, = 11
  10227. S_FAULT = 12
  10228. }
  10229. */
  10230. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10231. {
  10232. //check Transaction active
  10233. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10234. {
  10235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10236. {
  10237. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10238. }
  10239. else
  10240. {
  10241. tempIndex = connectorIdInt -1;
  10242. }
  10243. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10244. {
  10245. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10246. {
  10247. 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))
  10248. {
  10249. //Reserved
  10250. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10251. }
  10252. 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))
  10253. {
  10254. //Reserved
  10255. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10256. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10257. goto end;
  10258. }
  10259. else
  10260. {
  10261. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10262. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10263. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10264. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10265. {
  10266. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10267. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10268. goto end;
  10269. }
  10270. }//END FOR ELSE
  10271. }
  10272. }// END FOR CHAdeMO_QUANTITY
  10273. }
  10274. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10275. {
  10276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10277. {
  10278. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10279. }
  10280. else
  10281. {
  10282. tempIndex = connectorIdInt -1;
  10283. }
  10284. for (int index = 0; index < CCS_QUANTITY; index++)
  10285. {
  10286. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10287. {
  10288. 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))
  10289. {
  10290. //Reserved
  10291. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10292. }
  10293. 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))
  10294. {
  10295. //Reserved
  10296. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10297. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10298. goto end;
  10299. }
  10300. else
  10301. {
  10302. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10303. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10304. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10305. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10306. {
  10307. DEBUG_WARN("CCS connector not allow start\n.");
  10308. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10309. goto end;
  10310. }
  10311. }// END FOR ELSE
  10312. }
  10313. }// END FOR CCS_QUANTITY
  10314. }
  10315. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10316. {
  10317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10318. {
  10319. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10320. }
  10321. else
  10322. {
  10323. tempIndex = connectorIdInt -1;
  10324. }
  10325. for (int index = 0; index < GB_QUANTITY; index++)
  10326. {
  10327. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10328. {
  10329. 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))
  10330. {
  10331. //Reserved
  10332. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10333. }
  10334. 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))
  10335. {
  10336. //Reserved
  10337. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10338. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10339. goto end;
  10340. }
  10341. else
  10342. {
  10343. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10344. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10345. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10346. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10347. {
  10348. DEBUG_WARN("GB connector not allow start\n.");
  10349. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10350. goto end;
  10351. }
  10352. }// END FOR ELSE
  10353. }
  10354. } // END FOR GB_QUANTITY
  10355. }
  10356. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10357. {
  10358. tempIndex = connectorIdInt -1;
  10359. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10360. {
  10361. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10362. {
  10363. 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))
  10364. {
  10365. //Reserved
  10366. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10367. }
  10368. 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))
  10369. {
  10370. //Reserved
  10371. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10372. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10373. goto end;
  10374. }
  10375. else
  10376. {
  10377. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10378. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10379. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10380. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10381. {
  10382. DEBUG_WARN("GB connector not allow start\n.");
  10383. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10384. goto end;
  10385. }
  10386. }// END FOR ELSE
  10387. }
  10388. } // END FOR GB_QUANTITY
  10389. }
  10390. else
  10391. {
  10392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10393. {
  10394. tempIndex = 2;
  10395. }
  10396. else
  10397. {
  10398. tempIndex = connectorIdInt -1;
  10399. }
  10400. for (int index = 0; index < AC_QUANTITY; index++)
  10401. {
  10402. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10403. {
  10404. 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))
  10405. {
  10406. //Reserved
  10407. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10408. }
  10409. 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))
  10410. {
  10411. //Reserved
  10412. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10413. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10414. goto end;
  10415. }
  10416. else
  10417. {
  10418. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10419. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10420. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10421. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10422. {
  10423. DEBUG_WARN("AC connector not allow start\n.");
  10424. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10425. goto end;
  10426. }
  10427. }//END FOR ELSE
  10428. }
  10429. }// END FOR AC_QUANTITY
  10430. }
  10431. if(chargingProfileIsNULL == FALSE)
  10432. {
  10433. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10434. {
  10435. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10436. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10437. //memset idTag
  10438. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10439. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10440. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10441. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10442. // Save profile to file
  10443. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10444. system(cmdBuf);
  10445. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10446. fp = fopen(cmdBuf, "w");
  10447. 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));
  10448. fclose(fp);
  10449. }
  10450. else
  10451. {
  10452. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10453. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10454. }
  10455. }
  10456. else
  10457. {
  10458. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10459. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10460. //memset idTag
  10461. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10462. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10463. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10465. }
  10466. }
  10467. else
  10468. {
  10469. DEBUG_WARN("Connector id over\n.");
  10470. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10471. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10472. }
  10473. end:
  10474. json_object_put(RemoteStartTransaction);
  10475. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10476. {
  10477. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10478. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10479. }
  10480. //OCPP send RemoteStartConfirmation by first.
  10481. sendRemoteStartConfirmation(uuid, comfirmstr);
  10482. return result;
  10483. }
  10484. int handleRemoteStartRequest(char *uuid, char *payload)
  10485. {
  10486. mtrace();
  10487. int result = PASS;
  10488. int connectorIdInt=-1;
  10489. int tempIndex = 0;
  10490. char comfirmstr[20]={0};
  10491. char cmdBuf[512];
  10492. json_object *RemoteStartTransaction;
  10493. FILE *fp;
  10494. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10495. if(server_pending == TRUE)
  10496. {
  10497. result = FAIL;
  10498. }
  10499. RemoteStartTransaction = json_tokener_parse(payload);
  10500. if(!is_error(RemoteStartTransaction))
  10501. {
  10502. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10503. {
  10504. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10505. }
  10506. else
  10507. {
  10508. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10509. {
  10510. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10511. {
  10512. connectorIdInt = (gun_index+1);
  10513. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10514. break;
  10515. }
  10516. }
  10517. }
  10518. if(connectorIdInt == 0)
  10519. {
  10520. DEBUG_WARN("Connector id shall not equal 0.\n");
  10521. result = FAIL;
  10522. }
  10523. else if(connectorIdInt == -1)
  10524. {
  10525. DEBUG_INFO("Connector id does not specific.\n");
  10526. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10527. {
  10528. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10529. // Required data
  10530. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10531. // Optional data
  10532. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10533. {
  10534. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10535. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10536. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10537. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10538. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10539. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10540. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10541. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10542. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10543. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10544. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10545. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10546. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10547. {
  10548. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10549. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10550. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10551. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10552. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10553. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10554. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10555. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10556. {
  10557. 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++)
  10558. {
  10559. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].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"));
  10560. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].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"));
  10561. 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)
  10562. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].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"));
  10563. }
  10564. }
  10565. }
  10566. }
  10567. else
  10568. {
  10569. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10570. }
  10571. }
  10572. }
  10573. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10574. {
  10575. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10576. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10577. // Required data
  10578. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10579. // Optional data
  10580. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10581. {
  10582. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10583. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10584. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10585. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10586. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10587. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10588. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10589. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10590. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10591. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10592. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10593. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10594. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10595. {
  10596. 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")));
  10597. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10598. 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"));
  10599. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10600. 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"));
  10601. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10602. 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")));
  10603. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10604. {
  10605. 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++)
  10606. {
  10607. 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"));
  10608. 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"));
  10609. 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)
  10610. 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"));
  10611. }
  10612. }
  10613. }
  10614. }
  10615. else
  10616. {
  10617. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10618. }
  10619. }
  10620. else
  10621. {
  10622. DEBUG_WARN("Connector id is over maximun value.\n");
  10623. result = FAIL;
  10624. }
  10625. }
  10626. if(result == PASS)
  10627. {
  10628. if(connectorIdInt > 0)
  10629. {
  10630. //check Transaction active
  10631. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10632. {
  10633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10634. {
  10635. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10636. }
  10637. else
  10638. {
  10639. tempIndex = connectorIdInt -1;
  10640. }
  10641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10642. {
  10643. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10644. {
  10645. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10646. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10647. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10648. {
  10649. //Reserved
  10650. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10651. }
  10652. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10653. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10654. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10655. {
  10656. //Reserved
  10657. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10658. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10659. goto end;
  10660. }
  10661. else
  10662. {
  10663. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10664. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10665. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10666. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10667. {
  10668. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10669. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10670. goto end;
  10671. }
  10672. }//END FOR ELSE
  10673. }
  10674. }// END FOR CHAdeMO_QUANTITY
  10675. }
  10676. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10677. {
  10678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10679. {
  10680. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10681. }
  10682. else
  10683. {
  10684. tempIndex = connectorIdInt -1;
  10685. }
  10686. for (int index = 0; index < CCS_QUANTITY; index++)
  10687. {
  10688. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10689. {
  10690. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10691. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10692. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10693. {
  10694. //Reserved
  10695. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10696. }
  10697. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10698. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10699. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10700. {
  10701. //Reserved
  10702. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10703. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10704. goto end;
  10705. }
  10706. else
  10707. {
  10708. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10709. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10710. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10711. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10712. {
  10713. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10714. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10715. goto end;
  10716. }
  10717. }// END FOR ELSE
  10718. }
  10719. }// END FOR CCS_QUANTITY
  10720. }
  10721. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10722. {
  10723. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10724. {
  10725. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10726. }
  10727. else
  10728. {
  10729. tempIndex = connectorIdInt -1;
  10730. }
  10731. for (int index = 0; index < GB_QUANTITY; index++)
  10732. {
  10733. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10734. {
  10735. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10736. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10737. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10738. {
  10739. //Reserved
  10740. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10741. }
  10742. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10743. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10744. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10745. {
  10746. //Reserved
  10747. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10748. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10749. goto end;
  10750. }
  10751. else
  10752. {
  10753. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10754. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10755. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10756. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10757. {
  10758. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10759. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10760. goto end;
  10761. }
  10762. }// END FOR ELSE
  10763. }
  10764. } // END FOR GB_QUANTITY
  10765. }
  10766. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10767. {
  10768. tempIndex = connectorIdInt -1;
  10769. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10770. {
  10771. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10772. {
  10773. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10774. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10775. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10776. {
  10777. //Reserved
  10778. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10779. }
  10780. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10781. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10782. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10783. {
  10784. //Reserved
  10785. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10786. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10787. goto end;
  10788. }
  10789. else
  10790. {
  10791. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10792. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10793. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10794. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10795. {
  10796. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10797. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10798. goto end;
  10799. }
  10800. }// END FOR ELSE
  10801. }
  10802. } // END FOR GB_QUANTITY
  10803. }
  10804. else
  10805. {
  10806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10807. {
  10808. tempIndex = 2;
  10809. }
  10810. else
  10811. {
  10812. tempIndex = connectorIdInt -1;
  10813. }
  10814. for (int index = 0; index < AC_QUANTITY; index++)
  10815. {
  10816. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10817. {
  10818. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10819. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10820. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10821. {
  10822. //Reserved
  10823. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10824. }
  10825. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10826. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10827. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10828. {
  10829. //Reserved
  10830. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10831. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10832. goto end;
  10833. }
  10834. else
  10835. {
  10836. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10837. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10838. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10839. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10840. {
  10841. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10842. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10843. goto end;
  10844. }
  10845. }//END FOR ELSE
  10846. }
  10847. }// END FOR AC_QUANTITY
  10848. }
  10849. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10850. {
  10851. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10852. {
  10853. // Save profile to file
  10854. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10855. system(cmdBuf);
  10856. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10857. fp = fopen(cmdBuf, "w");
  10858. 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));
  10859. fclose(fp);
  10860. }
  10861. else
  10862. {
  10863. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10864. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10865. goto end;
  10866. }
  10867. }
  10868. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10869. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10870. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10871. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10872. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10873. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10874. }
  10875. else
  10876. {
  10877. uint8_t isHasIdleConnector = FALSE;
  10878. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10879. {
  10880. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10881. {
  10882. isHasIdleConnector = TRUE;
  10883. break;
  10884. }
  10885. }
  10886. if(isHasIdleConnector == TRUE)
  10887. {
  10888. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10889. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10890. {
  10891. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10892. {
  10893. // Save profile to file
  10894. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10895. system(cmdBuf);
  10896. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10897. fp = fopen(cmdBuf, "w");
  10898. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10899. fclose(fp);
  10900. refreshStartTimer(&clientTime.RemoteStartWait);
  10901. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10902. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10903. }
  10904. else
  10905. {
  10906. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10907. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10908. }
  10909. }
  10910. else
  10911. {
  10912. refreshStartTimer(&clientTime.RemoteStartWait);
  10913. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10914. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10915. }
  10916. }
  10917. else
  10918. {
  10919. DEBUG_INFO("There is not any connector is idle.\n");
  10920. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10921. }
  10922. }
  10923. }
  10924. else
  10925. {
  10926. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10927. }
  10928. end:
  10929. json_object_put(RemoteStartTransaction);
  10930. sendRemoteStartConfirmation(uuid, comfirmstr);
  10931. return result;
  10932. }
  10933. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10934. {
  10935. mtrace();
  10936. int result = FAIL;
  10937. int match = FALSE;
  10938. int GunNO = 0;
  10939. int tempIndex = 0;
  10940. int transactionIdInt=0;
  10941. int transactionIdIsNULL= TRUE;
  10942. char comfirmstr[20];
  10943. json_object *RemoteStopTransaction;
  10944. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10945. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10946. if(server_pending == TRUE)
  10947. {
  10948. return 0;
  10949. }
  10950. RemoteStopTransaction = json_tokener_parse(payload);
  10951. if(!is_error(RemoteStopTransaction))
  10952. {
  10953. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10954. {
  10955. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10956. transactionIdIsNULL = FALSE;
  10957. }
  10958. }
  10959. json_object_put(RemoteStopTransaction);
  10960. if(transactionIdIsNULL == FALSE)
  10961. {
  10962. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10963. {
  10964. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10965. {
  10966. //check Transaction active
  10967. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10968. {
  10969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10970. {
  10971. tempIndex = ((gun_index==2) ? 1: 0);
  10972. }
  10973. else
  10974. {
  10975. tempIndex = gun_index;
  10976. }
  10977. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10978. {
  10979. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10980. {
  10981. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10982. {
  10983. match = TRUE;
  10984. GunNO = gun_index;
  10985. }
  10986. }
  10987. }// END FOR CHAdeMO_QUANTITY
  10988. }
  10989. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10990. {
  10991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10992. {
  10993. tempIndex = ((gun_index==2) ? 1: 0);
  10994. }
  10995. else
  10996. {
  10997. tempIndex = gun_index;
  10998. }
  10999. for (int index = 0; index < CCS_QUANTITY; index++)
  11000. {
  11001. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11002. {
  11003. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11004. {
  11005. match = TRUE;
  11006. GunNO = gun_index;
  11007. }
  11008. }
  11009. }// END FOR CCS_QUANTITY
  11010. }
  11011. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11012. {
  11013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11014. {
  11015. tempIndex = ((gun_index==2) ? 1: 0);
  11016. }
  11017. else
  11018. {
  11019. tempIndex = gun_index;
  11020. }
  11021. for (int index = 0; index < GB_QUANTITY; index++)
  11022. {
  11023. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11024. {
  11025. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11026. {
  11027. match = TRUE;
  11028. GunNO = gun_index;
  11029. }
  11030. }
  11031. }// END FOR GB_QUANTITY
  11032. }
  11033. else if(gunType[gun_index] == GUN_TYPE_DO)
  11034. {
  11035. tempIndex = gun_index;
  11036. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11037. {
  11038. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11039. {
  11040. 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
  11041. {
  11042. match = TRUE;
  11043. GunNO = gun_index;
  11044. }
  11045. }
  11046. }// END FOR GB_QUANTITY
  11047. }
  11048. else
  11049. {
  11050. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11051. {
  11052. tempIndex = 2;
  11053. }
  11054. else
  11055. {
  11056. tempIndex = gun_index;
  11057. }
  11058. for (int index = 0; index < AC_QUANTITY; index++)
  11059. {
  11060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11061. {
  11062. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11063. {
  11064. match = TRUE;
  11065. GunNO = gun_index;
  11066. }
  11067. }
  11068. }// END FOR CHAdeMO_QUANTITY
  11069. } // END FOR AC ELSE
  11070. }// CHECK IF ResponseTransactionId == transactionIdInt
  11071. }//END FOR
  11072. if( match == TRUE)
  11073. {
  11074. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11075. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11076. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11077. }
  11078. else
  11079. {
  11080. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11081. }
  11082. }
  11083. else
  11084. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11085. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11086. return result;
  11087. }
  11088. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11089. {
  11090. mtrace();
  11091. int result = FAIL;
  11092. int connectorIdInt=0, reservationIdInt=0;
  11093. int tempIndex = 0;
  11094. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11095. char comfirmstr[20]={0};
  11096. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11097. int c = 0;
  11098. char *loc;
  11099. //char *ptr;
  11100. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11101. strcpy(sstrtemp, stringtrimspace(payload));
  11102. //***(1)connectorId ****/
  11103. c=0;
  11104. loc = strstr(sstrtemp, "connectorId");
  11105. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11106. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11107. {
  11108. sstr[c] = loc[strlen("connectorId")+2+c];
  11109. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11110. c++;
  11111. }
  11112. sstr[c] = '\0';
  11113. connectorIdInt = atoi(sstr);
  11114. //***(2)expiryDate ****/
  11115. loc = strstr(sstrtemp, "expiryDate");
  11116. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11117. c = 0;
  11118. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11119. {
  11120. sstr[c] = loc[3+strlen("expiryDate")+c];
  11121. c++;
  11122. }
  11123. sstr[c] = '\0';
  11124. strcpy(expiryDatestr, sstr);
  11125. //***(3)idTag ****/
  11126. loc = strstr(sstrtemp, "idTag");
  11127. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11128. c = 0;
  11129. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11130. {
  11131. sstr[c] = loc[3+strlen("idTag")+c];
  11132. c++;
  11133. }
  11134. sstr[c] = '\0';
  11135. strcpy(idTagstr, sstr);
  11136. //***(4)parentIdTag ****/
  11137. loc = strstr(sstrtemp, "parentIdTag");
  11138. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11139. c = 0;
  11140. if(loc == NULL)
  11141. {
  11142. strcpy(parentIdTagstr, "");
  11143. }
  11144. else
  11145. {
  11146. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11147. {
  11148. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11149. c++;
  11150. }
  11151. sstr[c] = '\0';
  11152. strcpy(parentIdTagstr, sstr);
  11153. }
  11154. //***(5)reservationId ****/
  11155. c=0;
  11156. loc = strstr(sstrtemp, "reservationId");
  11157. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11158. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11159. {
  11160. sstr[c] = loc[strlen("reservationId")+2+c];
  11161. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11162. c++;
  11163. }
  11164. sstr[c] = '\0';
  11165. reservationIdInt = atoi(sstr);
  11166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11167. /*
  11168. enum SYSTEM_STATUS
  11169. {
  11170. SYS_MODE_BOOTING = 0,
  11171. SYS_MODE_IDLE = 1,
  11172. SYS_MODE_AUTHORIZING = 2,
  11173. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11174. SYS_MODE_REASSIGN = 4,
  11175. SYS_MODE_PREPARING = 5,
  11176. SYS_MODE_PREPARE_FOR_EV = 6,
  11177. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11178. SYS_MODE_CHARGING = 8,
  11179. SYS_MODE_TERMINATING = 9,
  11180. SYS_MODE_COMPLETE = 10,
  11181. SYS_MODE_ALARM = 11,
  11182. SYS_MODE_FAULT = 12,
  11183. SYS_MODE_RESERVATION = 13,
  11184. SYS_MODE_BOOKING = 14,
  11185. SYS_MODE_MAINTAIN = 15,
  11186. SYS_MODE_DEBUG = 16,
  11187. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11188. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11189. SYS_MODE_UPDATE = 19
  11190. };
  11191. */
  11192. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11193. {
  11194. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11195. goto end;
  11196. }
  11197. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11198. {
  11199. //check Transaction active
  11200. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11201. {
  11202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11203. {
  11204. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11205. }
  11206. else
  11207. {
  11208. tempIndex = connectorIdInt -1;
  11209. }
  11210. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11211. {
  11212. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11213. {
  11214. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11215. {
  11216. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11217. {
  11218. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11219. {
  11220. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11221. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11222. }
  11223. 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'))
  11224. {
  11225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11226. }
  11227. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11228. {
  11229. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11230. }
  11231. else
  11232. {
  11233. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11234. }
  11235. }
  11236. 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
  11237. {
  11238. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11239. }
  11240. }
  11241. else
  11242. {
  11243. //replace reservation
  11244. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11245. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11246. }
  11247. }
  11248. } // END FOR CHAdeMO_QUANTITY
  11249. }
  11250. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11251. {
  11252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11253. {
  11254. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11255. }
  11256. else
  11257. {
  11258. tempIndex = connectorIdInt -1;
  11259. }
  11260. for (int index = 0; index < CCS_QUANTITY; index++)
  11261. {
  11262. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11263. {
  11264. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11265. {
  11266. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11267. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11268. {
  11269. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11270. {
  11271. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11272. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11273. }
  11274. 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'))
  11275. {
  11276. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11277. }
  11278. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11279. {
  11280. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11281. }
  11282. else
  11283. {
  11284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11285. }
  11286. }
  11287. 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
  11288. {
  11289. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11290. }
  11291. }
  11292. else
  11293. {
  11294. //replace reservation
  11295. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11296. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11297. }
  11298. }
  11299. } // END FOR CCS_QUANTITY
  11300. }
  11301. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11302. {
  11303. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11304. {
  11305. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11306. }
  11307. else
  11308. {
  11309. tempIndex = connectorIdInt -1;
  11310. }
  11311. for (int index = 0; index < GB_QUANTITY; index++)
  11312. {
  11313. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11314. {
  11315. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11316. {
  11317. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11318. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11319. {
  11320. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11321. {
  11322. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11324. }
  11325. 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'))
  11326. {
  11327. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11328. }
  11329. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11330. {
  11331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11332. }
  11333. else
  11334. {
  11335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11336. }
  11337. }
  11338. 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
  11339. {
  11340. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11341. }
  11342. }
  11343. else
  11344. {
  11345. //replace reservation
  11346. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11347. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11348. }
  11349. }
  11350. }// END FOR GB_QUANTITY
  11351. }
  11352. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11353. {
  11354. tempIndex = connectorIdInt -1;
  11355. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11356. {
  11357. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11358. {
  11359. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11360. {
  11361. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11362. 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
  11363. {
  11364. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11365. {
  11366. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11367. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11368. }
  11369. 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'))
  11370. {
  11371. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11372. }
  11373. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11374. {
  11375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11376. }
  11377. else
  11378. {
  11379. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11380. }
  11381. }
  11382. 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
  11383. {
  11384. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11385. }
  11386. }
  11387. else
  11388. {
  11389. //replace reservation
  11390. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11391. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11392. }
  11393. }
  11394. }// END FOR GB_QUANTITY
  11395. }
  11396. else
  11397. {
  11398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11399. {
  11400. tempIndex = 2;
  11401. }
  11402. else
  11403. {
  11404. tempIndex = (connectorIdInt -1);
  11405. }
  11406. for (int index = 0; index < AC_QUANTITY; index++)
  11407. {
  11408. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11409. {
  11410. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11411. {
  11412. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11413. {
  11414. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11415. {
  11416. 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))
  11417. {
  11418. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11419. }
  11420. else
  11421. {
  11422. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11423. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11424. }
  11425. }
  11426. 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'))
  11427. {
  11428. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11429. }
  11430. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11431. {
  11432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11433. }
  11434. else
  11435. {
  11436. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11437. }
  11438. }
  11439. 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
  11440. {
  11441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11442. }
  11443. }
  11444. else
  11445. {
  11446. //replace reservation
  11447. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11448. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11449. }
  11450. }
  11451. } // END FOR AC_QUANTITY
  11452. }
  11453. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11454. }
  11455. else if(connectorIdInt == 0)
  11456. {
  11457. //check Transaction active
  11458. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11459. {
  11460. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11461. {
  11462. 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'))
  11463. {
  11464. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11465. goto end;
  11466. }
  11467. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11468. {
  11469. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11470. goto end;
  11471. }
  11472. 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
  11473. {
  11474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11475. goto end;
  11476. }
  11477. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11478. {
  11479. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11480. goto end;
  11481. }
  11482. }
  11483. }// END FOR CHAdeMO_QUANTITY
  11484. for (int index = 0; index < CCS_QUANTITY; index++)
  11485. {
  11486. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11487. {
  11488. 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'))
  11489. {
  11490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11491. goto end;
  11492. }
  11493. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11494. {
  11495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11496. goto end;
  11497. }
  11498. 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
  11499. {
  11500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11501. goto end;
  11502. }
  11503. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11504. {
  11505. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11506. goto end;
  11507. }
  11508. }
  11509. } // END FOR CCS_QUANTITY
  11510. for (int index = 0; index < GB_QUANTITY; index++)
  11511. {
  11512. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11513. {
  11514. 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'))
  11515. {
  11516. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11517. goto end;
  11518. }
  11519. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11520. {
  11521. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11522. goto end;
  11523. }
  11524. 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
  11525. {
  11526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11527. goto end;
  11528. }
  11529. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11530. {
  11531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11532. goto end;
  11533. }
  11534. }
  11535. } // END FOR GB_QUANTITY
  11536. for (int index = 0; index < AC_QUANTITY; index++)
  11537. {
  11538. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11539. {
  11540. 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'))
  11541. {
  11542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11543. goto end;
  11544. }
  11545. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11546. {
  11547. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11548. goto end;
  11549. }
  11550. 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
  11551. {
  11552. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11553. goto end;
  11554. }
  11555. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11556. {
  11557. 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))
  11558. {
  11559. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11560. goto end;
  11561. }
  11562. }
  11563. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11564. {
  11565. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11566. goto end;
  11567. }
  11568. }
  11569. }// END FOR AC_QUANTITY
  11570. //The connectorId is 0
  11571. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11572. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11573. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11574. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11575. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11576. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11577. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11578. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11579. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11580. result = TRUE;
  11581. return result;
  11582. }
  11583. else
  11584. {
  11585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11586. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11587. }
  11588. if(strcmp(comfirmstr,"Accepted") == 0)
  11589. {
  11590. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11591. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11592. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11593. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11594. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11595. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11596. result = TRUE;
  11597. return result;
  11598. }
  11599. end:
  11600. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11601. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11602. return result;
  11603. }
  11604. int handleResetRequest(char *uuid, char *payload)
  11605. {
  11606. mtrace();
  11607. int result = FAIL;
  11608. char sstr[10]={0},sstrtemp[30]={ 0 };
  11609. char typestr[10]={0};
  11610. char comfirmstr[20]={0};
  11611. int c = 0;
  11612. char *loc;
  11613. DEBUG_INFO("handleResetRequest...\n");
  11614. strcpy(sstrtemp, stringtrimspace(payload));
  11615. loc = strstr(sstrtemp, "type");
  11616. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11617. c = 0;
  11618. while (loc[3+strlen("type")+c] != '\"')
  11619. {
  11620. sstr[c] = loc[3+strlen("type")+c];
  11621. c++;
  11622. }
  11623. sstr[c] = '\0';
  11624. strcpy(typestr,sstr);
  11625. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11626. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11627. {
  11628. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11629. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11630. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11631. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11632. }
  11633. else
  11634. {
  11635. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11636. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11637. result = PASS;
  11638. }
  11639. sendResetConfirmation(uuid, comfirmstr);
  11640. return result;
  11641. }
  11642. int handleSendLocalListRequest(char *uuid, char *payload)
  11643. {
  11644. mtrace();
  11645. int result = FAIL;
  11646. char comfirmstr[20];
  11647. int checkState_Faulted = FALSE;
  11648. json_object *SendLocalList;
  11649. DEBUG_INFO("handleSendLocalListRequest...\n");
  11650. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11651. {
  11652. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11653. goto end;
  11654. }
  11655. //check Charge Point state
  11656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11657. {
  11658. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11659. {
  11660. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11661. }
  11662. }
  11663. for (int index = 0; index < CCS_QUANTITY; index++)
  11664. {
  11665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11666. {
  11667. checkState_Faulted = TRUE; //OCPP Status
  11668. }
  11669. }
  11670. for (int index = 0; index < GB_QUANTITY; index++)
  11671. {
  11672. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11673. {
  11674. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11675. }
  11676. }
  11677. //check Charge Point state
  11678. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11679. {
  11680. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11681. {
  11682. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11683. }
  11684. }
  11685. //check Charge Point state
  11686. for (int index = 0; index < AC_QUANTITY; index++)
  11687. {
  11688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11689. {
  11690. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11691. }
  11692. }
  11693. if(checkState_Faulted == TRUE)
  11694. {
  11695. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11696. goto end;
  11697. }
  11698. // Parsing payload
  11699. SendLocalList = json_tokener_parse(payload);
  11700. if(!is_error(SendLocalList))
  11701. {
  11702. // Required data
  11703. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11704. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11705. // Optional data
  11706. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11707. {
  11708. //Check UpdateType
  11709. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11710. {
  11711. //Local list full update
  11712. DEBUG_INFO("Local list full update.\n");
  11713. OCPP_getListVerion();
  11714. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11715. {
  11716. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11717. goto end;
  11718. }
  11719. OCPP_cleanLocalList();
  11720. }
  11721. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11722. {
  11723. //Local list different update
  11724. DEBUG_INFO("Local list different update.\n");
  11725. OCPP_getListVerion();
  11726. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11727. {
  11728. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11729. goto end;
  11730. }
  11731. }
  11732. else
  11733. {
  11734. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11735. goto end;
  11736. }
  11737. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11738. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11739. {
  11740. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  11741. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11742. {
  11743. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  11744. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11745. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  11746. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11747. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  11748. }
  11749. // Add to db
  11750. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11751. {
  11752. //Local list full update
  11753. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11754. idx,
  11755. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11756. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11757. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11758. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11759. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11760. // update list
  11761. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11762. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11763. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11764. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11765. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11766. }
  11767. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11768. {
  11769. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11770. idx,
  11771. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11772. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11773. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11774. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11775. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11776. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11777. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11778. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11779. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11780. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11781. }
  11782. }
  11783. }
  11784. else
  11785. {
  11786. //Check UpdateType
  11787. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11788. {
  11789. //Local list full update
  11790. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11791. OCPP_cleanLocalList();
  11792. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11793. goto end;
  11794. }
  11795. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11796. {
  11797. //Local list different update
  11798. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11799. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11800. goto end;
  11801. }
  11802. }
  11803. result = PASS;
  11804. }
  11805. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11806. end:
  11807. json_object_put(SendLocalList);
  11808. sendSendLocalListConfirmation(uuid, comfirmstr);
  11809. return result;
  11810. }
  11811. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11812. {
  11813. mtrace();
  11814. int result = FAIL;
  11815. struct StructSetChargingProfile SetProfileReq = {0};
  11816. int tempchargingProfileIdInt;
  11817. int tempstackLevelInt;
  11818. int chargingSchedulePeriodCount = 0;
  11819. char comfirmstr[20]={0};
  11820. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11821. char rmFileCmd[128]={0};
  11822. int profileQuantity = 0;
  11823. int isReplaceable = FALSE;
  11824. json_object *SetChargingProfile;
  11825. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11826. SetChargingProfile = json_tokener_parse(payload);
  11827. if(!is_error(SetChargingProfile))
  11828. {
  11829. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11830. {
  11831. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11832. }
  11833. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11834. {
  11835. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11836. {
  11837. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11838. }
  11839. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11840. {
  11841. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11842. }
  11843. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11844. {
  11845. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11846. }
  11847. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11848. {
  11849. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11850. }
  11851. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11852. {
  11853. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11854. }
  11855. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11856. {
  11857. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11858. }
  11859. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11860. {
  11861. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11862. }
  11863. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11864. {
  11865. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11866. }
  11867. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11868. {
  11869. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11870. {
  11871. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  11872. }
  11873. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11874. {
  11875. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11876. }
  11877. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11878. {
  11879. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11880. }
  11881. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11882. {
  11883. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  11884. }
  11885. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11886. {
  11887. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11888. if(chargingSchedulePeriodCount <= 10)
  11889. {
  11890. 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++)
  11891. {
  11892. 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)
  11893. {
  11894. SetProfileReq.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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  11895. }
  11896. 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)
  11897. {
  11898. SetProfileReq.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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  11899. }
  11900. 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)
  11901. {
  11902. SetProfileReq.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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  11903. }
  11904. }
  11905. }
  11906. }
  11907. }
  11908. }
  11909. }
  11910. // Profile periods quantity check
  11911. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11912. {
  11913. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11914. goto end;
  11915. }
  11916. // Check invalid limit
  11917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11918. {
  11919. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11920. {
  11921. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  11922. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11923. {
  11924. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11925. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11926. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11927. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11928. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11929. goto end;
  11930. }
  11931. }
  11932. }
  11933. else
  11934. {
  11935. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11936. {
  11937. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower) ||
  11938. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  11939. {
  11940. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11941. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11942. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11943. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11944. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11945. goto end;
  11946. }
  11947. }
  11948. }
  11949. // Profile purpose info check
  11950. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11951. {
  11952. FILE *fp;
  11953. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11954. if(SetProfileReq.ConnectorId != 0)
  11955. {
  11956. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11957. goto end;
  11958. }
  11959. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11960. if (!fp)
  11961. {
  11962. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11963. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11964. }
  11965. else
  11966. {
  11967. char *line = NULL;
  11968. size_t len = 0;
  11969. while(getline(&line, &len, fp) != -1)
  11970. {
  11971. json_object *obj = NULL;
  11972. obj = json_tokener_parse(line);
  11973. if(is_error(obj))
  11974. {
  11975. DEBUG_ERROR("Parse txProfile from file error.\n");
  11976. }
  11977. else
  11978. {
  11979. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11980. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11981. {
  11982. profileQuantity += 1;
  11983. }
  11984. else
  11985. isReplaceable = TRUE;
  11986. }
  11987. }
  11988. }
  11989. fclose(fp);
  11990. }
  11991. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11992. {
  11993. FILE *fp;
  11994. char filename[128]={0};
  11995. int tmpProfileQuantity;
  11996. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11997. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11998. {
  11999. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12000. goto end;
  12001. }
  12002. if(SetProfileReq.ConnectorId == 0)
  12003. {
  12004. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12005. {
  12006. tmpProfileQuantity = 0;
  12007. memset(filename, 0, ARRAY_SIZE(filename));
  12008. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12009. fp = fopen(filename, "r");
  12010. if (!fp)
  12011. {
  12012. DEBUG_INFO("%s does not create.\n", filename);
  12013. fp = fopen(filename, "w+");
  12014. }
  12015. else
  12016. {
  12017. char *line = NULL;
  12018. size_t len = 0;
  12019. while(getline(&line, &len, fp) != -1)
  12020. {
  12021. json_object *obj = NULL;
  12022. obj = json_tokener_parse(line);
  12023. if(is_error(obj))
  12024. {
  12025. DEBUG_ERROR("Parse txProfile from file error.\n");
  12026. }
  12027. else
  12028. {
  12029. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12030. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12031. {
  12032. tmpProfileQuantity += 1;
  12033. }
  12034. else
  12035. isReplaceable = TRUE;
  12036. }
  12037. }
  12038. }
  12039. fclose(fp);
  12040. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12041. }
  12042. }
  12043. else
  12044. {
  12045. memset(filename, 0, ARRAY_SIZE(filename));
  12046. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12047. fp = fopen(filename, "r");
  12048. if (!fp)
  12049. {
  12050. DEBUG_INFO("%s does not create.\n", filename);
  12051. fp = fopen(filename, "w+");
  12052. }
  12053. else
  12054. {
  12055. char *line = NULL;
  12056. size_t len = 0;
  12057. while(getline(&line, &len, fp) != -1)
  12058. {
  12059. json_object *obj = NULL;
  12060. obj = json_tokener_parse(line);
  12061. if(is_error(obj))
  12062. {
  12063. DEBUG_ERROR("Parse txProfile from file error.\n");
  12064. }
  12065. else
  12066. {
  12067. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12068. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12069. {
  12070. profileQuantity += 1;
  12071. }
  12072. else
  12073. isReplaceable = TRUE;
  12074. }
  12075. }
  12076. }
  12077. fclose(fp);
  12078. }
  12079. }
  12080. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12081. {
  12082. int isMatchTransactiodId= FALSE;
  12083. FILE *fp;
  12084. char filename[128]={0};
  12085. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12086. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12087. if(SetProfileReq.ConnectorId == 0)
  12088. {
  12089. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12090. goto end;
  12091. }
  12092. int tempIndex = 0;
  12093. //check Transaction active
  12094. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12095. {
  12096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12097. {
  12098. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12099. }
  12100. else
  12101. {
  12102. tempIndex = SetProfileReq.ConnectorId -1;
  12103. }
  12104. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12105. {
  12106. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12107. {
  12108. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12109. {
  12110. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12111. {
  12112. isMatchTransactiodId = TRUE;
  12113. break;
  12114. }
  12115. }
  12116. }
  12117. }
  12118. }
  12119. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12120. {
  12121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12122. {
  12123. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12124. }
  12125. else
  12126. {
  12127. tempIndex = SetProfileReq.ConnectorId -1;
  12128. }
  12129. for (int index = 0; index < CCS_QUANTITY; index++)
  12130. {
  12131. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12132. {
  12133. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12134. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12135. {
  12136. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12137. {
  12138. isMatchTransactiodId = TRUE;
  12139. break;
  12140. }
  12141. }
  12142. }
  12143. }
  12144. }
  12145. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12146. {
  12147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12148. {
  12149. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12150. }
  12151. else
  12152. {
  12153. tempIndex = SetProfileReq.ConnectorId -1;
  12154. }
  12155. for (int index = 0; index < GB_QUANTITY; index++)
  12156. {
  12157. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12158. {
  12159. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12160. {
  12161. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12162. {
  12163. isMatchTransactiodId = TRUE;
  12164. break;
  12165. }
  12166. }
  12167. }
  12168. }
  12169. }
  12170. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12171. {
  12172. tempIndex = SetProfileReq.ConnectorId -1;
  12173. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12174. {
  12175. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12176. {
  12177. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12178. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12179. {
  12180. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12181. {
  12182. isMatchTransactiodId = TRUE;
  12183. break;
  12184. }
  12185. }
  12186. }
  12187. }
  12188. }
  12189. else
  12190. {
  12191. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12192. {
  12193. tempIndex = 2;
  12194. }
  12195. else
  12196. {
  12197. tempIndex = (SetProfileReq.ConnectorId -1);
  12198. }
  12199. for (int index = 0; index < AC_QUANTITY; index++)
  12200. {
  12201. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12202. {
  12203. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12204. {
  12205. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12206. {
  12207. isMatchTransactiodId = TRUE;
  12208. break;
  12209. }
  12210. }
  12211. }
  12212. }
  12213. }
  12214. //check Transaction active
  12215. if(isMatchTransactiodId == FALSE)
  12216. {
  12217. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12218. goto end;
  12219. }
  12220. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12221. {
  12222. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12223. goto end;
  12224. }
  12225. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12226. fp = fopen(filename, "r");
  12227. if (!fp)
  12228. {
  12229. DEBUG_INFO("%s does not create.\n", filename);
  12230. fp = fopen(filename, "w+");
  12231. }
  12232. else
  12233. {
  12234. char *line = NULL;
  12235. size_t len = 0;
  12236. while(getline(&line, &len, fp) != -1)
  12237. {
  12238. json_object *obj = NULL;
  12239. obj = json_tokener_parse(line);
  12240. if(is_error(obj))
  12241. {
  12242. DEBUG_ERROR("Parse txProfile from file error.\n");
  12243. }
  12244. else
  12245. {
  12246. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12247. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12248. {
  12249. profileQuantity += 1;
  12250. }
  12251. else
  12252. isReplaceable = TRUE;
  12253. }
  12254. }
  12255. }
  12256. fclose(fp);
  12257. }
  12258. // Check ChargeProfileMaxStackLevel
  12259. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12260. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12261. {
  12262. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12263. goto end;
  12264. }
  12265. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12266. {
  12267. FILE *fp;
  12268. char dataLine[4096]={0};
  12269. char fnametemp[128]={0};
  12270. int tmpProfileQuantity;
  12271. //Check ChargePointMaxProfile.json exit
  12272. profileQuantity = 0;
  12273. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12274. {
  12275. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12276. //Check Charging Profile Count
  12277. tmpProfileQuantity = 0;
  12278. while(fscanf(fp, "%s", dataLine) != EOF)
  12279. {
  12280. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12281. {
  12282. profileQuantity += 1;
  12283. tmpProfileQuantity += 1;
  12284. }
  12285. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12286. }
  12287. fclose(fp);
  12288. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12289. }
  12290. //Check TxDefaultProfile_%d.json
  12291. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12292. {
  12293. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12294. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12295. if((access(fnametemp,F_OK))!=-1)
  12296. {
  12297. fp = fopen(fnametemp, "r");
  12298. //Check Charging Profile Count
  12299. tmpProfileQuantity = 0;
  12300. while(fscanf(fp, "%s", dataLine) != EOF)
  12301. {
  12302. //DEBUG_INFO("word=%s\n",word);
  12303. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12304. {
  12305. profileQuantity += 1;
  12306. tmpProfileQuantity += 1;
  12307. }
  12308. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12309. }
  12310. fclose(fp);
  12311. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12312. }
  12313. }
  12314. //Check TxProfile_%d.json
  12315. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12316. {
  12317. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12318. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12319. if((access(fnametemp,F_OK))!=-1)
  12320. {
  12321. fp = fopen(fnametemp, "r");
  12322. //Check Charging Profile Count
  12323. tmpProfileQuantity = 0;
  12324. while(fscanf(fp, "%s", dataLine) != EOF)
  12325. {
  12326. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12327. {
  12328. profileQuantity += 1;
  12329. tmpProfileQuantity += 1;
  12330. }
  12331. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12332. }
  12333. fclose(fp);
  12334. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12335. }
  12336. }
  12337. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12338. if((profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12339. {
  12340. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12341. goto end;
  12342. }
  12343. }
  12344. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12345. //**********************************Write to File********************************************************/
  12346. {
  12347. FILE *infile;
  12348. FILE *outfile;
  12349. char dataLine[4096]={0};
  12350. char filename[128]={0};
  12351. int chkChar=0;
  12352. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12353. {
  12354. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12355. {
  12356. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12357. }
  12358. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12359. {
  12360. if(SetProfileReq.ConnectorId==0)
  12361. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12362. else
  12363. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12364. }
  12365. else
  12366. {
  12367. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12368. }
  12369. infile = fopen (filename, "r");
  12370. outfile = fopen (tempfile, "w");
  12371. chkChar = fgetc(infile);
  12372. rewind(infile);
  12373. if(chkChar == EOF)
  12374. {
  12375. // Profile is empty
  12376. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12377. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12378. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12379. fclose(infile);
  12380. fclose(outfile);
  12381. sprintf(rmFileCmd,"rm -f %s",filename);
  12382. system(rmFileCmd);
  12383. rename(tempfile, filename);
  12384. }
  12385. else
  12386. {
  12387. // Profile is not empty
  12388. int ChargingProfileAdded = FALSE;
  12389. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12390. {
  12391. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12392. json_object *tmpChargingProfile;
  12393. tmpChargingProfile = json_tokener_parse(dataLine);
  12394. if(!is_error(SetChargingProfile))
  12395. {
  12396. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12397. {
  12398. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12399. {
  12400. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12401. }
  12402. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12403. {
  12404. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12405. }
  12406. }
  12407. }
  12408. json_object_put(tmpChargingProfile);
  12409. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12410. {
  12411. if(ChargingProfileAdded == FALSE)
  12412. {
  12413. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12414. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12415. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12416. ChargingProfileAdded = TRUE;
  12417. }
  12418. }
  12419. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12420. {
  12421. if(ChargingProfileAdded == FALSE)
  12422. {
  12423. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12424. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12425. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12426. ChargingProfileAdded = TRUE;
  12427. }
  12428. }
  12429. else
  12430. {
  12431. fprintf(outfile,"%s\n",dataLine);
  12432. if(ChargingProfileAdded == FALSE)
  12433. {
  12434. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12435. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12436. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12437. ChargingProfileAdded = TRUE;
  12438. }
  12439. }
  12440. } // end of while loop
  12441. fclose(infile);
  12442. fclose(outfile);
  12443. sprintf(rmFileCmd,"rm -f %s",filename);
  12444. system(rmFileCmd);
  12445. rename(tempfile, filename);
  12446. }
  12447. }
  12448. sleep(1);
  12449. result = TRUE;
  12450. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12451. }
  12452. end:
  12453. json_object_put(SetChargingProfile);
  12454. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12455. {
  12456. if(SetProfileReq.ConnectorId == 0)
  12457. {
  12458. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12459. {
  12460. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12461. }
  12462. }
  12463. else
  12464. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12465. }
  12466. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12467. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12468. return result;
  12469. }
  12470. int handleTriggerMessageRequest(char *uuid, char *payload)
  12471. {
  12472. mtrace();
  12473. int result = FAIL;
  12474. int connectorIdIsNULL = FALSE;
  12475. int connectorIdInt =0;
  12476. char sstr[40]={0},sstrtemp[100]={ 0 };
  12477. char requestedMessagestr[40]={0};
  12478. char comfirmstr[20]={0};
  12479. int c = 0;
  12480. char *loc;
  12481. DEBUG_INFO("handleTriggerMessageRequest\n");
  12482. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12483. strcpy(sstrtemp, stringtrimspace(payload));
  12484. c = 0;
  12485. loc = strstr(sstrtemp, "requestedMessage");
  12486. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12487. {
  12488. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12489. c++;
  12490. }
  12491. sstr[c] = '\0';
  12492. strcpy(requestedMessagestr, sstr);
  12493. c = 0;
  12494. loc = strstr(sstrtemp, "connectorId");
  12495. if(loc == NULL)
  12496. {
  12497. connectorIdIsNULL = TRUE;
  12498. }
  12499. else
  12500. {
  12501. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12502. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12503. {
  12504. sstr[c] = loc[strlen("connectorId")+2+c];
  12505. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12506. c++;
  12507. }
  12508. sstr[c] = '\0';
  12509. connectorIdInt = atoi(sstr);
  12510. }
  12511. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12512. {
  12513. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12514. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12515. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12516. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12517. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12518. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12519. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12520. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12521. {
  12522. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12523. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12524. return TRUE;
  12525. }
  12526. else
  12527. {
  12528. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12529. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12530. }
  12531. }
  12532. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12533. {
  12534. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12535. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12536. return TRUE;
  12537. }
  12538. //==========================
  12539. // Trigger message
  12540. //==========================
  12541. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12542. {
  12543. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12544. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12545. {
  12546. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12547. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12548. }
  12549. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12550. }
  12551. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12552. {
  12553. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12554. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12555. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12556. }
  12557. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12558. {
  12559. //sendBootNotificationRequest();
  12560. server_sign = FALSE;
  12561. }
  12562. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12563. {
  12564. refreshStartTimer(&clientTime.Heartbeat);
  12565. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12566. }
  12567. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12568. {
  12569. if(connectorIdIsNULL == FALSE)
  12570. {
  12571. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12572. {
  12573. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12574. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12575. }
  12576. }
  12577. else
  12578. {
  12579. for(int idx=0;idx< gunTotalNumber;idx++)
  12580. {
  12581. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12582. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12583. }
  12584. }
  12585. }
  12586. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12587. {
  12588. if(connectorIdIsNULL == FALSE)
  12589. {
  12590. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12591. {
  12592. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12593. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12594. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12595. }
  12596. }
  12597. else
  12598. {
  12599. for(int idx=0;idx< gunTotalNumber;idx++)
  12600. {
  12601. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12602. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12603. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12604. }
  12605. }
  12606. }
  12607. return result;
  12608. }
  12609. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12610. {
  12611. mtrace();
  12612. int result = FAIL;
  12613. int connectorIdInt =0;
  12614. char comfirmstr[20]={0};
  12615. int tempIndex = 0;
  12616. json_object *UnlockConnector;
  12617. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12618. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12619. UnlockConnector = json_tokener_parse(payload);
  12620. if(!is_error(UnlockConnector))
  12621. {
  12622. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12623. {
  12624. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12625. }
  12626. }
  12627. json_object_put(UnlockConnector);
  12628. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12629. if(gunTotalNumber == 0)
  12630. {
  12631. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12632. goto end;
  12633. }
  12634. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12635. {
  12636. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12637. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12638. goto end;
  12639. }
  12640. else
  12641. {
  12642. //check Transaction active
  12643. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12644. {
  12645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12646. {
  12647. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12648. }
  12649. else
  12650. {
  12651. tempIndex = connectorIdInt -1;
  12652. }
  12653. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12654. {
  12655. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12656. {
  12657. //stop Transaction
  12658. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12659. }
  12660. }
  12661. }
  12662. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12663. {
  12664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12665. {
  12666. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12667. }
  12668. else
  12669. {
  12670. tempIndex = connectorIdInt -1;
  12671. }
  12672. for (int index = 0; index < CCS_QUANTITY; index++)
  12673. {
  12674. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12675. {
  12676. //stop Transaction
  12677. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12678. }
  12679. }
  12680. }
  12681. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12682. {
  12683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12684. {
  12685. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12686. }
  12687. else
  12688. {
  12689. tempIndex = connectorIdInt -1;
  12690. }
  12691. for (int index = 0; index < GB_QUANTITY; index++)
  12692. {
  12693. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12694. {
  12695. //stop Transaction
  12696. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12697. }
  12698. }
  12699. }
  12700. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12701. {
  12702. tempIndex = connectorIdInt -1;
  12703. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12704. {
  12705. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12706. {
  12707. //stop Transaction
  12708. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12709. }
  12710. }
  12711. }
  12712. else
  12713. {
  12714. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12715. {
  12716. tempIndex = 2;
  12717. }
  12718. else
  12719. {
  12720. tempIndex = connectorIdInt-1;
  12721. }
  12722. for (int index = 0; index < AC_QUANTITY; index++)
  12723. {
  12724. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12725. {
  12726. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12727. }
  12728. }
  12729. }
  12730. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12731. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12732. result = TRUE;
  12733. return result;
  12734. }
  12735. end:
  12736. //json_object_put(obj); --- remove temporally
  12737. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12738. return result;
  12739. }
  12740. static char UpdateFirmwarepayloadData[300]={0};
  12741. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12742. {
  12743. mtrace();
  12744. int result = FAIL;
  12745. pthread_t t;
  12746. sendUpdateFirmwareConfirmation(uuid);
  12747. memset(UpdateFirmwarepayloadData, 0, 300);
  12748. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12749. if(!interLock.isUpdateFirmwareGoing)
  12750. {
  12751. interLock.isUpdateFirmwareGoing = 1;
  12752. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12753. sleep(1);
  12754. }
  12755. else
  12756. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12757. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12758. return result;
  12759. }
  12760. void *UpdateFirmwareProcess(void *data)
  12761. {
  12762. pthread_detach(pthread_self());
  12763. mtrace();
  12764. int retriesInt =0, retryIntervalInt=0;
  12765. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12766. int port=0;
  12767. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12768. int isSuccess = 0;
  12769. char ftpbuf[512];
  12770. char temp[100];
  12771. char * pch;
  12772. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12773. json_object *UpdateFirmware;
  12774. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12775. if(!is_error(UpdateFirmware))
  12776. {
  12777. // Required data
  12778. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12779. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12780. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12781. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12782. // Optional data
  12783. if(json_object_object_get(UpdateFirmware, "retries"))
  12784. {
  12785. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12786. }
  12787. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12788. {
  12789. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12790. }
  12791. }
  12792. json_object_put(UpdateFirmware);
  12793. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12794. memset(path, 0, ARRAY_SIZE(path));
  12795. // Wait retrieveData
  12796. if(strlen(retrieveDatestr) > 10)
  12797. {
  12798. do
  12799. {
  12800. sleep(1);
  12801. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12802. }
  12803. // Ready to download
  12804. system("rm -f /mnt/*");
  12805. if(strncmp(locationstr,"http", 4) == 0)
  12806. {
  12807. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12808. sprintf(ftppath,"/%s", path);
  12809. DEBUG_INFO("locationstr: %s\n", locationstr);
  12810. DEBUG_INFO("protocol: %s\n",protocol);
  12811. DEBUG_INFO("host: %s\n",host);
  12812. DEBUG_INFO("path: %s\n",path);
  12813. DEBUG_INFO("ftppath: %s\n",ftppath);
  12814. int ftppathlen=strlen(ftppath);
  12815. int i=1;
  12816. char filenametemp[50];
  12817. while(i < ftppathlen)
  12818. {
  12819. int len=ftppathlen-i;
  12820. if(ftppath[len]== 47) // '/' ascll code: 47
  12821. {
  12822. DEBUG_INFO("compare '/' all right\n");
  12823. break;
  12824. }
  12825. i=i+1;
  12826. }
  12827. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12828. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12829. filenametemp[i+1] = 0;
  12830. do
  12831. {
  12832. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12833. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12834. sleep(1);
  12835. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12836. if(!isSuccess)
  12837. {
  12838. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12839. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12840. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12841. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12842. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12843. }
  12844. else
  12845. {
  12846. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12847. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12848. }
  12849. retriesInt--;
  12850. }while((isSuccess == 0)&&(retriesInt >= 0));
  12851. }
  12852. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12853. {
  12854. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12855. memset(temp, 0, ARRAY_SIZE(temp));
  12856. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12857. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12858. int ftppathlen=strlen(ftpbuf);
  12859. int i=1;
  12860. char filenametemp[50];
  12861. while(i < ftppathlen)
  12862. {
  12863. int len=ftppathlen-i;
  12864. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12865. {
  12866. DEBUG_INFO(" compare '/' all right\n");
  12867. break;
  12868. }
  12869. i=i+1;
  12870. }
  12871. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12872. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12873. filenametemp[i+1] = 0;
  12874. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12875. pch=strchr(temp,'@');
  12876. if(pch==NULL)
  12877. {
  12878. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12879. protocol, host, &port, path);
  12880. strcpy(user,"anonymous");
  12881. strcpy(password,"");
  12882. }
  12883. else
  12884. {
  12885. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12886. protocol, user, password, host, &port, path);
  12887. }
  12888. sscanf(host,"%[^/]%s",host1, path1);
  12889. sprintf(ftppath,"%s", path1);
  12890. //DEBUG_INFO("protocol =%s\n",protocol);
  12891. //DEBUG_INFO("user =%s\n",user);
  12892. //DEBUG_INFO("password =%s\n",password);
  12893. //DEBUG_INFO("host1 =%s\n",host1);
  12894. //DEBUG_INFO("port =%d\n",port);
  12895. //DEBUG_INFO("path1 =%s\n",path1);
  12896. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12897. //ftpFile(host, user, password, port, ftppath, fname);
  12898. //download firmware pthred
  12899. if(port == 0)
  12900. {
  12901. port = 21;
  12902. }
  12903. do
  12904. {
  12905. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12906. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12907. sleep(1);
  12908. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12909. if(!isSuccess)
  12910. {
  12911. //BulldogUtil.sleepMs(interval*1000);
  12912. DEBUG_INFO("Update firmware request and download file fail.\n");
  12913. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12914. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12915. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12916. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12917. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12918. }
  12919. else
  12920. {
  12921. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12922. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12923. }
  12924. retriesInt--;
  12925. }while((!isSuccess)&&(retriesInt >= 0));
  12926. }
  12927. else
  12928. {
  12929. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12930. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12931. sleep(1);
  12932. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12933. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12934. }
  12935. // OCPPPH only, must announce CSU upgrade firmware
  12936. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12937. interLock.isUpdateFirmwareGoing = 0;
  12938. pthread_exit(NULL);
  12939. }
  12940. int handleCertificateSignedRequest(char *uuid, char *payload)
  12941. {
  12942. mtrace();
  12943. int result = PASS;
  12944. json_object *CertificateSigned;
  12945. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12946. CertificateSigned = json_tokener_parse(payload);
  12947. if(!is_error(CertificateSigned))
  12948. {
  12949. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12950. }
  12951. json_object_put(CertificateSigned);
  12952. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12953. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12954. fclose(fp);
  12955. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12956. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12957. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12958. sendCertificateSignedConfirmation(uuid);
  12959. return result;
  12960. }
  12961. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12962. {
  12963. mtrace();
  12964. int result = PASS;
  12965. json_object *DeleteCertificate;
  12966. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12967. DeleteCertificate = json_tokener_parse(payload);
  12968. if(!is_error(DeleteCertificate))
  12969. {
  12970. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12971. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12972. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12973. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12974. }
  12975. json_object_put(DeleteCertificate);
  12976. /*
  12977. * TODO: Delete certificateSigned process
  12978. */
  12979. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12980. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12981. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12982. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12983. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12984. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12985. sendDeleteCertificateConfirmation(uuid);
  12986. return result;
  12987. }
  12988. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12989. {
  12990. mtrace();
  12991. int result = PASS;
  12992. json_object *ExtendedTriggerMessage;
  12993. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12994. ExtendedTriggerMessage = json_tokener_parse(payload);
  12995. if(!is_error(ExtendedTriggerMessage))
  12996. {
  12997. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12998. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12999. {
  13000. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13001. }
  13002. else
  13003. {
  13004. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13005. }
  13006. }
  13007. json_object_put(ExtendedTriggerMessage);
  13008. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13009. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13010. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13011. {
  13012. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13013. }
  13014. else
  13015. {
  13016. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13017. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13018. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13019. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13020. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13021. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13022. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13023. {
  13024. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13025. }
  13026. else
  13027. {
  13028. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13029. }
  13030. }
  13031. sendExtendedTriggerMessageConfirmation(uuid);
  13032. //==========================
  13033. // Trigger message
  13034. //==========================
  13035. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13036. {
  13037. //sendBootNotificationRequest();
  13038. server_sign = FALSE;
  13039. }
  13040. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13041. {
  13042. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13043. }
  13044. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13045. {
  13046. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13047. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13048. {
  13049. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13050. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13051. }
  13052. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13053. }
  13054. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13055. {
  13056. refreshStartTimer(&clientTime.Heartbeat);
  13057. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13058. }
  13059. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13060. {
  13061. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13062. {
  13063. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13064. }
  13065. else
  13066. {
  13067. for(int idx=0;idx< gunTotalNumber;idx++)
  13068. {
  13069. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13070. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13071. }
  13072. }
  13073. }
  13074. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13075. {
  13076. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13077. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13078. {
  13079. 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\" &");
  13080. }
  13081. }
  13082. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13083. {
  13084. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13085. {
  13086. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13087. }
  13088. else
  13089. {
  13090. for(int idx=0;idx< gunTotalNumber;idx++)
  13091. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13092. }
  13093. }
  13094. return result;
  13095. }
  13096. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13097. {
  13098. mtrace();
  13099. int result = PASS;
  13100. json_object *GetInstalledCertificateIds;
  13101. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13102. GetInstalledCertificateIds = json_tokener_parse(payload);
  13103. if(!is_error(GetInstalledCertificateIds))
  13104. {
  13105. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13106. }
  13107. json_object_put(GetInstalledCertificateIds);
  13108. /*
  13109. * TODO: Return installed certificate process
  13110. */
  13111. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13112. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13113. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13114. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13115. sendGetInstalledCertificateIdsConfirmation(uuid);
  13116. return result;
  13117. }
  13118. int handleGetLogRequest(char *uuid, char *payload)
  13119. {
  13120. mtrace();
  13121. int result = PASS;
  13122. json_object *GetLog;
  13123. DEBUG_INFO("handleGetLogRequest...\n");
  13124. GetLog = json_tokener_parse(payload);
  13125. if(!is_error(GetLog))
  13126. {
  13127. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13128. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13129. if(json_object_object_get(GetLog, "retries") != NULL)
  13130. {
  13131. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13132. }
  13133. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13134. {
  13135. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13136. }
  13137. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13138. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13139. {
  13140. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13141. }
  13142. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13143. {
  13144. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13145. }
  13146. }
  13147. json_object_put(GetLog);
  13148. /*
  13149. * TODO: Upload log process
  13150. */
  13151. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13152. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13153. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13154. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13155. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13156. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13157. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13158. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13159. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13160. sendGetLogConfirmation(uuid);
  13161. return result;
  13162. }
  13163. int handleInstallCertificateRequest(char *uuid, char *payload)
  13164. {
  13165. mtrace();
  13166. int result = PASS;
  13167. json_object *InstallCertificate;
  13168. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13169. InstallCertificate = json_tokener_parse(payload);
  13170. if(!is_error(InstallCertificate))
  13171. {
  13172. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13173. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13174. /*
  13175. * TODO: Install certificate process
  13176. */
  13177. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13178. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13179. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13180. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13181. sendInstallCertificateConfirmation(uuid);
  13182. }
  13183. json_object_put(InstallCertificate);
  13184. return result;
  13185. }
  13186. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13187. {
  13188. mtrace();
  13189. int result = PASS;
  13190. json_object *SignedUpdateFirmware;
  13191. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13192. SignedUpdateFirmware = json_tokener_parse(payload);
  13193. if(!is_error(SignedUpdateFirmware))
  13194. {
  13195. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13196. {
  13197. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13198. }
  13199. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13200. {
  13201. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13202. }
  13203. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13204. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13205. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13206. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13207. {
  13208. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13209. }
  13210. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13211. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13212. }
  13213. json_object_put(SignedUpdateFirmware);
  13214. /*
  13215. * TODO: Upgrade firmware process
  13216. */
  13217. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13218. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13219. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13220. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13221. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13222. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13223. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13224. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13225. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13226. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13227. sendInstallCertificateConfirmation(uuid);
  13228. return result;
  13229. }
  13230. int handleUnknownRequest(char *uuid, char *payload)
  13231. {
  13232. mtrace();
  13233. int result = PASS;
  13234. DEBUG_INFO("handleUnknownRequest...\n");
  13235. sendUnknownConfirmation(uuid);
  13236. result = PASS;
  13237. return result;
  13238. }
  13239. //==========================================
  13240. // Handle server response routine
  13241. //==========================================
  13242. void handleAuthorizeResponse(char *payload, int gun_index)
  13243. {
  13244. mtrace();
  13245. char expiryDatestr[30]={0};
  13246. char parentIdTagstr[20]={0};
  13247. char statusstr[20]={0};
  13248. int expiryDateISNULL=FALSE;
  13249. int parentIdTagISNULL=FALSE;
  13250. DEBUG_INFO("handleAuthorizeResponse...\n");
  13251. json_object *Authorize;
  13252. Authorize = json_tokener_parse(payload);
  13253. if(!is_error(Authorize))
  13254. {
  13255. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13256. {
  13257. // Required data
  13258. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13259. // Optional data
  13260. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13261. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13262. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13263. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13264. }
  13265. }
  13266. json_object_put(Authorize);
  13267. if(expiryDateISNULL == FALSE)
  13268. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13269. if(parentIdTagISNULL == FALSE)
  13270. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13271. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13272. //Update idTag information to authorization cache if supproted
  13273. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13274. {
  13275. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13276. }
  13277. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13278. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13279. authorizeRetryTimes = 0;
  13280. }
  13281. void handleBootNotificationResponse(char *payload, int gun_index)
  13282. {
  13283. mtrace();
  13284. char statusStr[12]={0};
  13285. char currentTimeStr[30]={0};
  13286. int intervalInt = 0;
  13287. DEBUG_INFO("handleBootNotificationResponse...\n");
  13288. json_object *BootNotification;
  13289. BootNotification = json_tokener_parse(payload);
  13290. if(!is_error(BootNotification))
  13291. {
  13292. // Required data
  13293. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13294. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13295. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13296. }
  13297. json_object_put(BootNotification);
  13298. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13299. BootNotificationInterval = intervalInt;
  13300. //write back to ShmOCPP16DataPH->BootNotification
  13301. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13302. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13303. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13304. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13305. {
  13306. BootNotificationInterval = 0;
  13307. if((intervalInt == 0) || (intervalInt >= 10))
  13308. {
  13309. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13310. HeartBeatWaitTime = intervalInt;
  13311. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13312. }
  13313. server_sign = TRUE;
  13314. server_pending =FALSE;
  13315. }
  13316. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13317. {
  13318. server_pending = TRUE;
  13319. }
  13320. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13321. srand(time(NULL));
  13322. refreshStartTimer(&clientTime.Heartbeat);
  13323. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13324. SetOcppConnStatus(TRUE);
  13325. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13326. }
  13327. void handleDataTransferResponse(char *payload, int gun_index)
  13328. {
  13329. json_object *DataTransfer = json_tokener_parse(payload);
  13330. if(!is_error(DataTransfer))
  13331. {
  13332. // Required data
  13333. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13334. // Optional data
  13335. if(json_object_object_get(DataTransfer, "data") != NULL)
  13336. {
  13337. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13338. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13339. if(!is_error(Data))
  13340. {
  13341. if(json_object_object_get(Data, "msgId") != NULL)
  13342. {
  13343. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13344. {
  13345. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  13346. }
  13347. }
  13348. }
  13349. json_object_put(Data);
  13350. }
  13351. }
  13352. json_object_put(DataTransfer);
  13353. }
  13354. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13355. {
  13356. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13357. //struct json_object *obj;
  13358. // obj = json_tokener_parse(payload);
  13359. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13360. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13361. //No fields are defined.
  13362. }
  13363. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13364. {
  13365. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13366. //struct json_object *obj;
  13367. // obj = json_tokener_parse(payload);
  13368. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13369. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13370. //No fields are defined.
  13371. }
  13372. void handleHeartbeatResponse(char *payload, int gun_index)
  13373. {
  13374. mtrace();
  13375. DEBUG_INFO("handleHeartbeatResponse...\n");
  13376. json_object *Heartbeat;
  13377. Heartbeat = json_tokener_parse(payload);
  13378. if(!is_error(Heartbeat))
  13379. {
  13380. // Required data
  13381. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13382. }
  13383. json_object_put(Heartbeat);
  13384. if(FirstHeartBeat == 0)
  13385. {
  13386. FirstHeartBeat = 1;
  13387. DEBUG_INFO("FirstHeartBeat \n");
  13388. }
  13389. HeartBeatWithNOResponse = 0;
  13390. refreshStartTimer(&clientTime.Heartbeat);
  13391. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13392. }
  13393. void handleMeterValuesResponse(char *payload, int gun_index)
  13394. {
  13395. mtrace();
  13396. DEBUG_INFO("handleMeterValuesResponse...\n");
  13397. isQueueSendable = 1;
  13398. }
  13399. void handleStartTransactionResponse(char *payload, int gun_index)
  13400. {
  13401. mtrace();
  13402. //int transactionIdInt = 0;
  13403. FILE *outfile;
  13404. char data[100]={0};
  13405. DEBUG_INFO("handleStartTransactionResponse...\n");
  13406. json_object *StartTransaction;
  13407. StartTransaction = json_tokener_parse(payload);
  13408. if(!is_error(StartTransaction))
  13409. {
  13410. // Required data
  13411. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13412. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13413. // Optional data
  13414. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13415. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13416. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13417. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13418. }
  13419. json_object_put(StartTransaction);
  13420. isQueueSendable = 1;
  13421. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13422. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13423. //-----------Start : write to the Queue TransactionId file -----------------//
  13424. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13425. {}
  13426. else
  13427. {
  13428. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13429. if(log == NULL)
  13430. {
  13431. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13432. return ;
  13433. }
  13434. else
  13435. {
  13436. fclose(log);
  13437. }
  13438. }
  13439. // open file for writing
  13440. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13441. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13442. {
  13443. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13444. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13445. fputs(data, outfile);
  13446. fclose (outfile);
  13447. }
  13448. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13449. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13450. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13451. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13452. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13453. }
  13454. void handleStatusNotificationResponse(char *payload, int gun_index)
  13455. {
  13456. mtrace();
  13457. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13458. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13459. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13460. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13461. }
  13462. void handleStopTransactionnResponse(char *payload, int gun_index)
  13463. {
  13464. mtrace();
  13465. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13466. json_object *StopTransaction;
  13467. StopTransaction = json_tokener_parse(payload);
  13468. if(!is_error(StopTransaction))
  13469. {
  13470. // Optional data
  13471. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13472. {
  13473. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13474. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13475. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13476. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13477. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13478. }
  13479. }
  13480. json_object_put(StopTransaction);
  13481. isQueueSendable = 1;
  13482. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13483. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13484. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13485. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13486. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13487. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13488. }
  13489. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13490. {
  13491. mtrace();
  13492. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13493. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13494. }
  13495. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13496. {
  13497. mtrace();
  13498. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13499. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13500. }
  13501. void handleSignCertificateResponse(char *payload, int gun_index)
  13502. {
  13503. mtrace();
  13504. DEBUG_INFO("handleSignCertificateResponse...\n");
  13505. json_object *SignCertificate;
  13506. SignCertificate = json_tokener_parse(payload);
  13507. if(!is_error(SignCertificate))
  13508. {
  13509. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13510. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13511. }
  13512. json_object_put(SignCertificate);
  13513. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13514. }
  13515. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13516. {
  13517. mtrace();
  13518. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13519. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13520. }
  13521. //==========================================
  13522. // Handle Error routine
  13523. //==========================================
  13524. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13525. {
  13526. mtrace();
  13527. #ifdef SystemLogMessage
  13528. DEBUG_INFO("errorCode: %s\n", errorCode);
  13529. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13530. DEBUG_INFO("errorDetails: %s\n", payload);
  13531. #endif
  13532. }
  13533. //===============================================
  13534. // Common routine
  13535. //===============================================
  13536. int initialConfigurationTable(void)
  13537. {
  13538. //clock_t start_t, end_t, total_t;
  13539. FILE *fp;
  13540. FILE *outfile;
  13541. char str[512]={0};
  13542. char sstr[256]={0};
  13543. int c = 0;
  13544. char *loc;
  13545. int confVersion = 13;
  13546. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13547. //start_t = clock();
  13548. //printf("Starting of the program, start_t = %ld\n", start_t);
  13549. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13550. // Check configuration file size is correct
  13551. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13552. {
  13553. struct stat st;
  13554. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13555. if(st.st_size < 3100)
  13556. {
  13557. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13558. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13559. }
  13560. }
  13561. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13562. {
  13563. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13564. if(outfile == NULL)
  13565. {
  13566. DEBUG_INFO("Error opening file\n");
  13567. return FALSE;
  13568. }
  13569. /*Core Profile*/
  13570. //AllowOfflineTxForUnknownId
  13571. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13572. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13573. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13575. //AuthorizationCacheEnabled
  13576. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13577. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13578. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13580. //AuthorizeRemoteTxRequests
  13581. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13582. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13583. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13585. //BlinkRepeat
  13586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13587. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13588. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13590. //ClockAlignedDataInterval
  13591. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13592. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13593. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13595. //ConnectionTimeOut
  13596. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13597. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13598. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13600. //GetConfigurationMaxKeys
  13601. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13603. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13605. // HeartbeatInterval
  13606. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13607. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13610. // LightIntensity
  13611. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13612. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13615. // LocalAuthorizeOffline
  13616. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13617. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13618. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13620. // LocalPreAuthorize
  13621. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13622. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13623. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13625. // MaxEnergyOnInvalidId
  13626. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13627. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13628. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13630. // MeterValuesAlignedData
  13631. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13632. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13633. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13634. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13635. else
  13636. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13638. // MeterValuesAlignedDataMaxLength
  13639. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13640. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13641. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13642. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13643. else
  13644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13646. // MeterValuesSampledData
  13647. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13648. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13649. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13650. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13651. else
  13652. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13654. // MeterValuesSampledDataMaxLength
  13655. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13656. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13659. else
  13660. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13662. // MeterValueSampleInterval
  13663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13667. // MinimumStatusDuration
  13668. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13669. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13670. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13671. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13673. // NumberOfConnectors
  13674. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13675. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13676. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13677. {
  13678. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13679. }
  13680. else
  13681. {
  13682. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13683. }
  13684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13685. // ResetRetries
  13686. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13687. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13688. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13690. // ConnectorPhaseRotation
  13691. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13692. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13693. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13695. // ConnectorPhaseRotationMaxLength
  13696. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13697. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13698. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13700. // StopTransactionOnEVSideDisconnect
  13701. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13702. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13703. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13705. // StopTransactionOnInvalidId
  13706. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13707. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13708. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13710. // StopTxnAlignedData
  13711. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13712. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13713. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13715. // StopTxnAlignedDataMaxLength
  13716. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13717. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13718. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13720. // StopTxnSampledData
  13721. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13723. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13724. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13725. else
  13726. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13728. // StopTxnSampledDataMaxLength
  13729. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13730. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13731. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13732. {
  13733. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13734. }
  13735. else
  13736. {
  13737. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13738. }
  13739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13740. // SupportedFeatureProfiles
  13741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13742. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13743. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13745. // SupportedFeatureProfilesMaxLength
  13746. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13747. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13748. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13750. // TransactionMessageAttempts
  13751. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13752. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13753. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13754. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13756. // TransactionMessageRetryInterval
  13757. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13758. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13759. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13760. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13762. // UnlockConnectorOnEVSideDisconnect
  13763. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13764. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13765. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13767. // WebSocketPingInterval
  13768. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13769. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13770. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13772. // QueueOffLineMeterValues
  13773. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13774. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13775. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13777. // AuthorizationKey
  13778. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13779. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13780. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13782. // SecurityProfile
  13783. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13785. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13787. // DefaultPrice
  13788. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13789. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13792. // CustomDisplayCostAndPrice
  13793. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13794. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13797. // CustomIdleFeeAfterStop
  13798. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13802. // SystemUptimeSec
  13803. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13804. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13807. // FreeVend
  13808. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13810. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13812. // FreeVendIdtag
  13813. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13814. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13815. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13817. // OcppServer
  13818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13820. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13822. // MaintainServer
  13823. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13824. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13825. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13827. // StatusNotificationPeriodically
  13828. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13832. // StatusNotificationInterval
  13833. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13834. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13835. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13837. // Configuration Version
  13838. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13839. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13840. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13842. //* Local Auth List Management Profile*/
  13843. #if 0
  13844. //For OCTT Test Case
  13845. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13848. #endif
  13849. #if 1
  13850. //LocalAuthListEnabled
  13851. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13853. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13855. #endif
  13856. //LocalAuthListMaxLength
  13857. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13861. //SendLocalListMaxLength
  13862. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13863. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13864. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13866. //ReserveConnectorZeroSupported
  13867. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13871. //* Smart Charging Profile */
  13872. //ChargeProfileMaxStackLevel
  13873. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13874. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13877. // ChargingScheduleAllowedChargingRateUnit
  13878. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13879. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13882. // ChargingScheduleMaxPeriods
  13883. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13884. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13885. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13887. // ConnectorSwitch3to1PhaseSupported
  13888. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13892. // MaxChargingProfilesInstalled
  13893. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13895. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13897. fclose(outfile);
  13898. }
  13899. else
  13900. {
  13901. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13902. char keystr[60]={0};
  13903. char readonlystr[10]={0};
  13904. char valuestr[256]={0};
  13905. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13906. if(fp == NULL) {
  13907. DEBUG_INFO("Error opening file");
  13908. return FALSE;
  13909. }
  13910. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13911. {
  13912. //DEBUG_INFO("Get Configuration \n");
  13913. if(strlen(str) > 0)
  13914. {
  13915. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13916. //*************************key*********************************/
  13917. if(strstr(str, "key") != NULL)
  13918. {
  13919. loc = strstr(str, "key");
  13920. c = 0;
  13921. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13922. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13923. {
  13924. sstr[c] = loc[strlen("key")+3+c];
  13925. c++;
  13926. }
  13927. sstr[c] = '\0';
  13928. strcpy(keystr,sstr);
  13929. }
  13930. //*************************readonly*********************************/
  13931. if(strstr(str, "readonly") != NULL)
  13932. {
  13933. loc = strstr(str, "readonly");
  13934. c = 0;
  13935. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13936. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13937. {
  13938. sstr[c] = loc[strlen("readonly")+2+c];
  13939. c++;
  13940. }
  13941. sstr[c] = '\0';
  13942. strcpy(readonlystr,sstr);
  13943. }
  13944. //*************************value*********************************/
  13945. if(strstr(str, "value") != NULL)
  13946. {
  13947. loc = strstr(str, "value");
  13948. c = 0;
  13949. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13950. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13951. {
  13952. sstr[c] = loc[strlen("value")+3+c];
  13953. c++;
  13954. }
  13955. sstr[c] = '\0';
  13956. strcpy(valuestr,sstr);
  13957. }
  13958. // DEBUG_INFO("keystr=%s\n",keystr);
  13959. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13960. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13961. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13962. {
  13963. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13964. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13965. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13966. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13967. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13968. }
  13969. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13970. {
  13971. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13972. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13973. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13974. }
  13975. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13976. {
  13977. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13978. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13979. }
  13980. if(strcmp(keystr, "BlinkRepeat") == 0)
  13981. {
  13982. //Charger.BlinkRepeat = Integer.parseInt(value);
  13983. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13984. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13985. }
  13986. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13987. {
  13988. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13989. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13990. }
  13991. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13992. {
  13993. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13994. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13995. }
  13996. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13997. {
  13998. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13999. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14000. }
  14001. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14002. {
  14003. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14004. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14005. HeartBeatWaitTime = atoi(valuestr);
  14006. }
  14007. if(strcmp(keystr, "LightIntensity") == 0)
  14008. {
  14009. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14010. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14011. }
  14012. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14013. {
  14014. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14015. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14016. }
  14017. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14018. {
  14019. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14020. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14021. }
  14022. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14023. {
  14024. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14025. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14026. }
  14027. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14028. {
  14029. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14030. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14031. }
  14032. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14033. {
  14034. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14035. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14036. }
  14037. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14038. {
  14039. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14040. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14041. }
  14042. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14043. {
  14044. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14045. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14046. }
  14047. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14048. {
  14049. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14050. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14051. }
  14052. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14053. {
  14054. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14055. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14056. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14057. }
  14058. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14059. {
  14060. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14061. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14062. }
  14063. if(strcmp(keystr, "ResetRetries") == 0)
  14064. {
  14065. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14066. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14067. }
  14068. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14069. {
  14070. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14071. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14072. }
  14073. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14074. {
  14075. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14076. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14077. }
  14078. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14079. {
  14080. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14081. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14082. }
  14083. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14084. {
  14085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14086. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14087. }
  14088. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14089. {
  14090. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14091. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14092. }
  14093. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14094. {
  14095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14096. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14097. }
  14098. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14099. {
  14100. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14101. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14102. }
  14103. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14104. {
  14105. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14106. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14107. }
  14108. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14109. {
  14110. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14111. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14112. }
  14113. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14114. {
  14115. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14117. }
  14118. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14119. {
  14120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14121. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14122. TransactionMessageAttemptsValue = atoi(valuestr);
  14123. }
  14124. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14125. {
  14126. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14127. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14128. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14129. }
  14130. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14131. {
  14132. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14133. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14134. }
  14135. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14136. {
  14137. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14138. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14139. }
  14140. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14141. {
  14142. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14143. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14144. }
  14145. if(strcmp(keystr, "AuthorizationKey") == 0)
  14146. {
  14147. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14148. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14149. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14150. }
  14151. if(strcmp(keystr, "SecurityProfile") == 0)
  14152. {
  14153. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14154. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14155. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14156. }
  14157. if(strcmp(keystr, "DefaultPrice") == 0)
  14158. {
  14159. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14160. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14161. }
  14162. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14163. {
  14164. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14165. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14166. }
  14167. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14168. {
  14169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14170. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14171. }
  14172. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14173. {
  14174. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14175. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14176. }
  14177. if(strcmp(keystr, "FreeVend") == 0)
  14178. {
  14179. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14180. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14181. }
  14182. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14183. {
  14184. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14185. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14186. }
  14187. if(strcmp(keystr, "OcppServer") == 0)
  14188. {
  14189. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14190. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14191. }
  14192. if(strcmp(keystr, "MaintainServer") == 0)
  14193. {
  14194. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14195. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14196. }
  14197. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14198. {
  14199. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14200. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14201. }
  14202. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14203. {
  14204. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14205. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14206. }
  14207. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14208. {
  14209. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14210. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14211. }
  14212. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14213. {
  14214. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14215. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14216. }
  14217. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14218. {
  14219. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14220. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14221. }
  14222. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14223. {
  14224. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14225. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14226. }
  14227. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14228. {
  14229. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14230. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14231. }
  14232. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14233. {
  14234. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14235. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14236. }
  14237. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14238. {
  14239. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14240. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14241. }
  14242. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14243. {
  14244. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14245. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14246. }
  14247. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14248. {
  14249. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14250. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14251. }
  14252. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14253. {
  14254. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14255. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14256. }
  14257. }
  14258. }
  14259. fclose(fp);
  14260. }
  14261. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14262. {
  14263. return PASS;
  14264. }
  14265. else
  14266. {
  14267. return FAIL;
  14268. }
  14269. }
  14270. void StoreConfigurationTable(void)
  14271. {
  14272. FILE *outfile;
  14273. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14274. if(outfile == NULL)
  14275. {
  14276. DEBUG_INFO("Error opening file");
  14277. return ;
  14278. }
  14279. /*Core Profile*/
  14280. //AllowOfflineTxForUnknownId
  14281. /*
  14282. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14283. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14284. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14285. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14286. */
  14287. //DEBUG_INFO("data=%s\n",data);
  14288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14289. //AuthorizationCacheEnabled
  14290. /*
  14291. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14292. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14293. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14294. */
  14295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14296. //AuthorizeRemoteTxRequests
  14297. /*
  14298. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14299. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14301. */
  14302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14303. //BlinkRepeat
  14304. /*
  14305. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14308. */
  14309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14310. //ClockAlignedDataInterval
  14311. /*
  14312. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14313. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14314. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14315. */
  14316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14317. //ConnectionTimeOut
  14318. /*
  14319. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14320. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14321. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14322. */
  14323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14324. //GetConfigurationMaxKeys
  14325. /*
  14326. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14327. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14329. */
  14330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14331. // HeartbeatInterval
  14332. /*
  14333. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14334. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14335. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14336. */
  14337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14338. // LightIntensity
  14339. /*
  14340. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14341. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14343. */
  14344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14345. // LocalAuthorizeOffline
  14346. /*
  14347. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14349. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14350. */
  14351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14352. // LocalPreAuthorize
  14353. /*
  14354. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14355. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14357. */
  14358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14359. // MaxEnergyOnInvalidId
  14360. /*
  14361. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14363. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14364. */
  14365. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14367. // MeterValuesAlignedData
  14368. /*
  14369. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14371. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14372. */
  14373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14374. // MeterValuesAlignedDataMaxLength
  14375. /*
  14376. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14377. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14379. */
  14380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14381. // MeterValuesSampledData
  14382. /*
  14383. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14384. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14385. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14386. */
  14387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14388. // MeterValuesSampledDataMaxLength
  14389. /*
  14390. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14391. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14392. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14393. */
  14394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14395. // MeterValueSampleInterval
  14396. /*
  14397. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14400. */
  14401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14402. // MinimumStatusDuration
  14403. /*
  14404. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14406. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14407. */
  14408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14409. // NumberOfConnectors
  14410. /*
  14411. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14413. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14414. {
  14415. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14416. }
  14417. else
  14418. {
  14419. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14420. }
  14421. */
  14422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14423. // ResetRetries
  14424. /*
  14425. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14426. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14428. */
  14429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14430. // ConnectorPhaseRotation
  14431. /*
  14432. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14433. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14434. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14435. */
  14436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14437. // ConnectorPhaseRotationMaxLength
  14438. /*
  14439. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14440. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14441. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14442. */
  14443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14444. // StopTransactionOnEVSideDisconnect
  14445. /*
  14446. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14447. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14448. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14449. */
  14450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14451. // StopTransactionOnInvalidId
  14452. /*
  14453. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14454. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14455. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14456. */
  14457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14458. // StopTxnAlignedData
  14459. /*
  14460. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14461. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14462. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14463. */
  14464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14465. // StopTxnAlignedDataMaxLength
  14466. /*
  14467. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14468. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14469. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14470. */
  14471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14472. // StopTxnSampledData
  14473. /*
  14474. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14475. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14476. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14477. */
  14478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14479. // StopTxnSampledDataMaxLength
  14480. /*
  14481. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14482. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14483. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14484. */
  14485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14486. // SupportedFeatureProfiles
  14487. /*
  14488. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14489. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14490. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14491. */
  14492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14493. // SupportedFeatureProfilesMaxLength
  14494. /*
  14495. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14496. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14497. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14498. */
  14499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14500. // TransactionMessageAttempts
  14501. /*
  14502. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14503. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14504. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14505. */
  14506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14507. // TransactionMessageRetryInterval
  14508. /*
  14509. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14510. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14511. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14512. */
  14513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14514. // UnlockConnectorOnEVSideDisconnect
  14515. /*
  14516. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14517. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14518. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14519. */
  14520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14521. // WebSocketPingInterval
  14522. /*
  14523. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14524. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14525. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14526. */
  14527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14528. // QueueOffLineMeterValues
  14529. /*
  14530. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14531. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14532. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14533. */
  14534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14535. // AuthorizationKey
  14536. /*
  14537. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14538. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14539. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14540. */
  14541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14542. // SecurityProfile
  14543. /*
  14544. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14545. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14546. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14547. */
  14548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14549. // DefaultPrice
  14550. /*
  14551. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14552. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14553. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14554. */
  14555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14556. // CustomDisplayCostAndPrice
  14557. /*
  14558. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14559. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14560. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14561. */
  14562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14563. // CustomIdleFeeAfterStop
  14564. /*
  14565. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14566. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14567. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14568. */
  14569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14570. // SystemUptimeSec
  14571. /*
  14572. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14573. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14574. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14575. */
  14576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14577. // FreeVend
  14578. /*
  14579. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14580. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14581. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14582. */
  14583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14584. // FreeVendIdtag
  14585. /*
  14586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14587. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14588. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14589. */
  14590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14591. // OcppServer
  14592. /*
  14593. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14594. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14595. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14596. */
  14597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14598. // MaintainServer
  14599. /*
  14600. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14601. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14603. */
  14604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14605. // StatusNotificationPeriodically
  14606. /*
  14607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14609. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14610. */
  14611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14612. // StatusNotificationInterval
  14613. /*
  14614. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14615. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14616. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14617. */
  14618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14619. // ConfigurationVersion
  14620. /*
  14621. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14622. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14623. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14624. */
  14625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14626. //* Local Auth List Management Profile*/
  14627. //LocalAuthListEnabled
  14628. /*
  14629. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14630. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14631. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14632. */
  14633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14634. //LocalAuthListMaxLength
  14635. /*
  14636. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14637. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14638. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14639. */
  14640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14641. //SendLocalListMaxLength
  14642. /*
  14643. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14645. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14646. */
  14647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14648. //ReserveConnectorZeroSupported
  14649. /*
  14650. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14651. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14652. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14653. */
  14654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14655. //* Smart Charging Profile */
  14656. //ChargeProfileMaxStackLevel
  14657. /*
  14658. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14659. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14660. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14661. */
  14662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14663. // ChargingScheduleAllowedChargingRateUnit
  14664. /*
  14665. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14666. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14667. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14668. */
  14669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14670. // ChargingScheduleMaxPeriods
  14671. /*
  14672. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14673. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14674. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14675. */
  14676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14677. // ConnectorSwitch3to1PhaseSupported
  14678. /*
  14679. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14680. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14681. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14682. */
  14683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14684. // MaxChargingProfilesInstalled
  14685. /*
  14686. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14687. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14688. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14689. */
  14690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14691. fclose(outfile);
  14692. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14693. }
  14694. void getKeyValue(char *keyReq)
  14695. {
  14696. int isEmpty = FALSE;
  14697. int isKnowKey = FALSE;
  14698. DEBUG_INFO("keyReq = %s\n", keyReq);
  14699. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14700. isEmpty = TRUE;
  14701. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14702. {
  14703. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14705. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14706. {
  14707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14708. }
  14709. else
  14710. {
  14711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14712. }
  14713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14714. isKnowKey = TRUE;
  14715. }
  14716. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14717. {
  14718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14720. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14721. {
  14722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14723. }
  14724. else
  14725. {
  14726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14727. }
  14728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14729. isKnowKey = TRUE;
  14730. }
  14731. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14732. {
  14733. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14734. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14735. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14736. {
  14737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14738. }
  14739. else
  14740. {
  14741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14742. }
  14743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14744. isKnowKey = TRUE;
  14745. }
  14746. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14747. {
  14748. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14749. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14750. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14751. {
  14752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14753. }
  14754. else
  14755. {
  14756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14757. }
  14758. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14759. isKnowKey = TRUE;
  14760. }
  14761. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14762. {
  14763. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14764. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14765. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14766. {
  14767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14768. }
  14769. else
  14770. {
  14771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14772. }
  14773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14774. isKnowKey = TRUE;
  14775. }
  14776. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14777. {
  14778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14779. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14780. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14781. {
  14782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14783. }
  14784. else
  14785. {
  14786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14787. }
  14788. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14789. isKnowKey = TRUE;
  14790. }
  14791. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14792. {
  14793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14795. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14796. {
  14797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14798. }
  14799. else
  14800. {
  14801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14802. }
  14803. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14804. isKnowKey = TRUE;
  14805. }
  14806. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14807. {
  14808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14810. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14811. {
  14812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14813. }
  14814. else
  14815. {
  14816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14817. }
  14818. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14819. isKnowKey = TRUE;
  14820. }
  14821. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14822. {
  14823. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14824. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14825. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14826. {
  14827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14828. }
  14829. else
  14830. {
  14831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14832. }
  14833. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14834. isKnowKey = TRUE;
  14835. }
  14836. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14837. {
  14838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14839. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14840. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14841. {
  14842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14843. }
  14844. else
  14845. {
  14846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14847. }
  14848. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14849. isKnowKey = TRUE;
  14850. }
  14851. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14852. {
  14853. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14854. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14855. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14856. {
  14857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14858. }
  14859. else
  14860. {
  14861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14862. }
  14863. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14864. isKnowKey = TRUE;
  14865. }
  14866. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14867. {
  14868. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14869. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14870. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14871. {
  14872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14873. }
  14874. else
  14875. {
  14876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14877. }
  14878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14879. isKnowKey = TRUE;
  14880. }
  14881. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14882. {
  14883. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14884. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14885. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14886. {
  14887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14888. }
  14889. else
  14890. {
  14891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14892. }
  14893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14894. isKnowKey = TRUE;
  14895. }
  14896. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14897. {
  14898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14899. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14900. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14901. {
  14902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14903. }
  14904. else
  14905. {
  14906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14907. }
  14908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14909. isKnowKey = TRUE;
  14910. }
  14911. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14912. {
  14913. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14914. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14915. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14916. {
  14917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14918. }
  14919. else
  14920. {
  14921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14922. }
  14923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14924. isKnowKey = TRUE;
  14925. }
  14926. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14927. {
  14928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14929. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14930. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14931. {
  14932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14933. }
  14934. else
  14935. {
  14936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14937. }
  14938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14939. isKnowKey = TRUE;
  14940. }
  14941. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14942. {
  14943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14944. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14945. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14946. {
  14947. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14948. }
  14949. else
  14950. {
  14951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14952. }
  14953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14954. isKnowKey = TRUE;
  14955. }
  14956. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14957. {
  14958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14959. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14960. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14961. {
  14962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14963. }
  14964. else
  14965. {
  14966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14967. }
  14968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14969. isKnowKey = TRUE;
  14970. }
  14971. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14972. {
  14973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14975. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14976. {
  14977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14978. }
  14979. else
  14980. {
  14981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14982. }
  14983. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14984. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14985. isKnowKey = TRUE;
  14986. }
  14987. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14988. {
  14989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14990. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14991. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14992. {
  14993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14994. }
  14995. else
  14996. {
  14997. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14998. }
  14999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15000. isKnowKey = TRUE;
  15001. }
  15002. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15003. {
  15004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15005. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15006. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15007. {
  15008. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15009. }
  15010. else
  15011. {
  15012. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15013. }
  15014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15015. isKnowKey = TRUE;
  15016. }
  15017. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15018. {
  15019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15020. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15021. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15022. {
  15023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15024. }
  15025. else
  15026. {
  15027. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15028. }
  15029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15030. isKnowKey = TRUE;
  15031. }
  15032. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15033. {
  15034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15036. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15037. {
  15038. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15039. }
  15040. else
  15041. {
  15042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15043. }
  15044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15045. isKnowKey = TRUE;
  15046. }
  15047. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15048. {
  15049. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15051. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15052. {
  15053. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15054. }
  15055. else
  15056. {
  15057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15058. }
  15059. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15060. isKnowKey = TRUE;
  15061. }
  15062. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15063. {
  15064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15066. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15067. {
  15068. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15069. }
  15070. else
  15071. {
  15072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15073. }
  15074. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15075. isKnowKey = TRUE;
  15076. }
  15077. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15078. {
  15079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15081. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15082. {
  15083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15084. }
  15085. else
  15086. {
  15087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15088. }
  15089. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15090. isKnowKey = TRUE;
  15091. }
  15092. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15093. {
  15094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15096. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15097. {
  15098. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15099. }
  15100. else
  15101. {
  15102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15103. }
  15104. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15105. isKnowKey = TRUE;
  15106. }
  15107. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15108. {
  15109. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15111. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15112. {
  15113. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15114. }
  15115. else
  15116. {
  15117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15118. }
  15119. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15120. isKnowKey = TRUE;
  15121. }
  15122. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15123. {
  15124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15126. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15127. {
  15128. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15129. }
  15130. else
  15131. {
  15132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15133. }
  15134. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15135. isKnowKey = TRUE;
  15136. }
  15137. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15138. {
  15139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15141. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15142. {
  15143. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15144. }
  15145. else
  15146. {
  15147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15148. }
  15149. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15150. isKnowKey = TRUE;
  15151. }
  15152. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15153. {
  15154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15156. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15157. {
  15158. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15159. }
  15160. else
  15161. {
  15162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15163. }
  15164. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15165. isKnowKey = TRUE;
  15166. }
  15167. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15168. {
  15169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15171. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15172. {
  15173. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15174. }
  15175. else
  15176. {
  15177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15178. }
  15179. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15180. isKnowKey = TRUE;
  15181. }
  15182. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15183. {
  15184. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15186. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15187. {
  15188. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15189. }
  15190. else
  15191. {
  15192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15193. }
  15194. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15195. isKnowKey = TRUE;
  15196. }
  15197. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15198. {
  15199. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15201. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15202. {
  15203. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15204. }
  15205. else
  15206. {
  15207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15208. }
  15209. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15210. isKnowKey = TRUE;
  15211. }
  15212. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15213. {
  15214. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15215. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15216. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15217. {
  15218. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15219. }
  15220. else
  15221. {
  15222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15223. }
  15224. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15225. isKnowKey = TRUE;
  15226. }
  15227. /*
  15228. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15229. {
  15230. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15231. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15232. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15233. {
  15234. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15235. }
  15236. else
  15237. {
  15238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15239. }
  15240. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15241. isKnowKey = TRUE;
  15242. }*/
  15243. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15244. {
  15245. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15247. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15248. {
  15249. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15250. }
  15251. else
  15252. {
  15253. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15254. }
  15255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15256. isKnowKey = TRUE;
  15257. }
  15258. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15259. {
  15260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15262. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15263. {
  15264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15265. }
  15266. else
  15267. {
  15268. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15269. }
  15270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15271. isKnowKey = TRUE;
  15272. }
  15273. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15274. {
  15275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15276. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15277. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15278. {
  15279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15280. }
  15281. else
  15282. {
  15283. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15284. }
  15285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15286. isKnowKey = TRUE;
  15287. }
  15288. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15289. {
  15290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15291. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15292. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15293. {
  15294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15295. }
  15296. else
  15297. {
  15298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15299. }
  15300. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15301. isKnowKey = TRUE;
  15302. }
  15303. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15304. {
  15305. struct sysinfo s_info;
  15306. int error = sysinfo(&s_info);
  15307. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15309. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15310. {
  15311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15312. }
  15313. else
  15314. {
  15315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15316. }
  15317. if(error != 0)
  15318. {
  15319. DEBUG_WARN("System uptime get error: %d\n", error);
  15320. }
  15321. else
  15322. {
  15323. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15324. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15325. }
  15326. isKnowKey = TRUE;
  15327. }
  15328. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15329. {
  15330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15332. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15333. {
  15334. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15335. }
  15336. else
  15337. {
  15338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15339. }
  15340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15341. isKnowKey = TRUE;
  15342. }
  15343. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15344. {
  15345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15347. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15348. {
  15349. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15350. }
  15351. else
  15352. {
  15353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15354. }
  15355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15356. isKnowKey = TRUE;
  15357. }
  15358. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15359. {
  15360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15362. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15363. {
  15364. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15365. }
  15366. else
  15367. {
  15368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15369. }
  15370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15371. isKnowKey = TRUE;
  15372. }
  15373. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15374. {
  15375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15377. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15378. {
  15379. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15380. }
  15381. else
  15382. {
  15383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15384. }
  15385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15386. isKnowKey = TRUE;
  15387. }
  15388. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15389. {
  15390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15392. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15393. {
  15394. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15395. }
  15396. else
  15397. {
  15398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15399. }
  15400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15401. isKnowKey = TRUE;
  15402. }
  15403. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15404. {
  15405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15407. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15408. {
  15409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15410. }
  15411. else
  15412. {
  15413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15414. }
  15415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15416. isKnowKey = TRUE;
  15417. }
  15418. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15419. {
  15420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15422. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15423. {
  15424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15425. }
  15426. else
  15427. {
  15428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15429. }
  15430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15431. isKnowKey = TRUE;
  15432. }
  15433. #if 1
  15434. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15435. {
  15436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15438. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15439. {
  15440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15441. }
  15442. else
  15443. {
  15444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15445. }
  15446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15447. isKnowKey = TRUE;
  15448. }
  15449. #endif
  15450. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15451. {
  15452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15454. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15455. {
  15456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15457. }
  15458. else
  15459. {
  15460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15461. }
  15462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15463. isKnowKey = TRUE;
  15464. }
  15465. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15466. {
  15467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15469. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15470. {
  15471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15472. }
  15473. else
  15474. {
  15475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15476. }
  15477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15478. isKnowKey = TRUE;
  15479. }
  15480. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15481. {
  15482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15484. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15485. {
  15486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15487. }
  15488. else
  15489. {
  15490. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15491. }
  15492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15493. isKnowKey = TRUE;
  15494. }
  15495. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15496. {
  15497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15498. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15499. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15500. {
  15501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15502. }
  15503. else
  15504. {
  15505. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15506. }
  15507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15508. isKnowKey = TRUE;
  15509. }
  15510. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15511. {
  15512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15513. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15514. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15515. {
  15516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15517. }
  15518. else
  15519. {
  15520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15521. }
  15522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15523. isKnowKey = TRUE;
  15524. }
  15525. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15526. {
  15527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15529. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15530. {
  15531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15532. }
  15533. else
  15534. {
  15535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15536. }
  15537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15538. isKnowKey = TRUE;
  15539. }
  15540. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15541. {
  15542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15544. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15545. {
  15546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15547. }
  15548. else
  15549. {
  15550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15551. }
  15552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15553. isKnowKey = TRUE;
  15554. }
  15555. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15556. {
  15557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15559. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15560. {
  15561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15562. }
  15563. else
  15564. {
  15565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15566. }
  15567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15568. isKnowKey = TRUE;
  15569. }
  15570. //=========================================================
  15571. if(!isEmpty && !isKnowKey)
  15572. {
  15573. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15574. strcpy(unknownkey[UnknownKeynum], keyReq);
  15575. UnknownKeynum = UnknownKeynum + 1;
  15576. }
  15577. }
  15578. void processUnkownKey(void)
  15579. {
  15580. DEBUG_INFO("processUnkownKey...\n");
  15581. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15582. for(int index=0; index < UnknownKeynum; index++)
  15583. {
  15584. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15585. {
  15586. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15587. }
  15588. }
  15589. }
  15590. int setKeyValue(char *key, char *value)
  15591. {
  15592. int isSuccess = NotSupported;
  15593. int check_ascii=0;
  15594. char str[501]={0};
  15595. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15596. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15597. {
  15598. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15599. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15600. {
  15601. strcpy(str, (const char*)value);
  15602. for(int i = 0; str[i]; i++){
  15603. str[i] = tolower(str[i]);
  15604. }
  15605. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15606. isSuccess = ConfigurationStatus_Accepted;
  15607. }
  15608. else
  15609. {
  15610. isSuccess = ConfigurationStatus_Rejected;
  15611. }
  15612. }
  15613. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15614. {
  15615. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15616. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15617. {
  15618. strcpy(str, (const char*)value);
  15619. for(int i = 0; str[i]; i++){
  15620. str[i] = tolower(str[i]);
  15621. }
  15622. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15623. isSuccess = ConfigurationStatus_Accepted;
  15624. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15625. }
  15626. else
  15627. {
  15628. isSuccess = ConfigurationStatus_Rejected;
  15629. }
  15630. }
  15631. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15632. {
  15633. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15634. {
  15635. strcpy(str, (const char*)value);
  15636. for(int i = 0; str[i]; i++)
  15637. {
  15638. str[i] = tolower(str[i]);
  15639. }
  15640. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15641. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15642. isSuccess = ConfigurationStatus_Accepted;
  15643. }
  15644. else
  15645. {
  15646. isSuccess = ConfigurationStatus_Rejected;
  15647. }
  15648. }
  15649. if(strcmp(key, "BlinkRepeat") == 0)
  15650. {
  15651. //Charger.BlinkRepeat = Integer.parseInt(value);
  15652. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15653. {
  15654. check_ascii = value[0];
  15655. if( (check_ascii < 48) || (check_ascii > 57) )
  15656. {
  15657. isSuccess = ConfigurationStatus_Rejected;
  15658. }
  15659. else
  15660. {
  15661. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15662. isSuccess = ConfigurationStatus_Accepted;
  15663. }
  15664. }
  15665. else
  15666. {
  15667. isSuccess = ConfigurationStatus_Rejected;
  15668. }
  15669. }
  15670. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15671. {
  15672. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15673. {
  15674. check_ascii = value[0];
  15675. if( (check_ascii < 48) || (check_ascii > 57) )
  15676. {
  15677. isSuccess = ConfigurationStatus_Rejected;
  15678. }
  15679. else
  15680. {
  15681. if((atoi(value) == 0) || (atoi(value) >= 5))
  15682. {
  15683. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15684. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15685. isSuccess = ConfigurationStatus_Accepted;
  15686. }
  15687. else
  15688. isSuccess = ConfigurationStatus_Rejected;
  15689. }
  15690. }
  15691. else
  15692. {
  15693. isSuccess = ConfigurationStatus_Rejected;
  15694. }
  15695. }
  15696. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15697. {
  15698. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15699. {
  15700. check_ascii = value[0];
  15701. if( (check_ascii < 48) || (check_ascii > 57) )
  15702. {
  15703. isSuccess = ConfigurationStatus_Rejected;
  15704. }
  15705. else
  15706. {
  15707. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15708. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15709. isSuccess = ConfigurationStatus_Accepted;
  15710. }
  15711. }
  15712. else
  15713. {
  15714. isSuccess = ConfigurationStatus_Rejected;
  15715. }
  15716. }
  15717. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15718. {
  15719. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15720. {
  15721. check_ascii = value[0];
  15722. if( (check_ascii < 48) || (check_ascii > 57) )
  15723. {
  15724. isSuccess = ConfigurationStatus_Rejected;
  15725. }
  15726. else
  15727. {
  15728. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15729. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15730. isSuccess = ConfigurationStatus_Accepted;
  15731. }
  15732. }
  15733. else
  15734. {
  15735. isSuccess = ConfigurationStatus_Rejected;
  15736. }
  15737. }
  15738. if(strcmp(key, "HeartbeatInterval") == 0)
  15739. {
  15740. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15741. {
  15742. check_ascii = value[0];
  15743. if( (check_ascii < 48) || (check_ascii > 57) )
  15744. {
  15745. isSuccess = ConfigurationStatus_Rejected;
  15746. }
  15747. else
  15748. {
  15749. if((atoi(value) == 0) || (atoi(value) >= 10))
  15750. {
  15751. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15752. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15753. HeartBeatWaitTime = atoi(value);
  15754. isSuccess = ConfigurationStatus_Accepted;
  15755. }
  15756. else
  15757. {
  15758. isSuccess = ConfigurationStatus_Rejected;
  15759. }
  15760. }
  15761. }
  15762. else
  15763. {
  15764. isSuccess = ConfigurationStatus_Rejected;
  15765. }
  15766. }
  15767. if(strcmp(key, "LightIntensity") == 0)
  15768. {
  15769. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15770. {
  15771. check_ascii = value[0];
  15772. if( (check_ascii < 48) || (check_ascii > 57) )
  15773. {
  15774. isSuccess = ConfigurationStatus_Rejected;
  15775. }
  15776. else
  15777. {
  15778. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15779. isSuccess = ConfigurationStatus_Accepted;
  15780. }
  15781. }
  15782. else
  15783. {
  15784. isSuccess = ConfigurationStatus_Rejected;
  15785. }
  15786. }
  15787. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15788. {
  15789. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15790. {
  15791. strcpy(str, (const char*)value);
  15792. for(int i = 0; str[i]; i++)
  15793. {
  15794. str[i] = tolower(str[i]);
  15795. }
  15796. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15797. isSuccess = ConfigurationStatus_Accepted;
  15798. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15799. }
  15800. else
  15801. {
  15802. isSuccess = ConfigurationStatus_Rejected;
  15803. }
  15804. }
  15805. if(strcmp(key, "LocalPreAuthorize") == 0)
  15806. {
  15807. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15808. {
  15809. strcpy(str, (const char*)value);
  15810. for(int i = 0; str[i]; i++)
  15811. {
  15812. str[i] = tolower(str[i]);
  15813. }
  15814. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15815. isSuccess = ConfigurationStatus_Accepted;
  15816. }
  15817. else
  15818. {
  15819. isSuccess = ConfigurationStatus_Rejected;
  15820. }
  15821. }
  15822. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15823. {
  15824. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15825. {
  15826. check_ascii = value[0];
  15827. if( (check_ascii < 48) || (check_ascii > 57) )
  15828. {
  15829. isSuccess = ConfigurationStatus_Rejected;
  15830. }
  15831. else
  15832. {
  15833. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15834. isSuccess = ConfigurationStatus_Accepted;
  15835. }
  15836. }
  15837. else
  15838. {
  15839. isSuccess = ConfigurationStatus_Rejected;
  15840. }
  15841. }
  15842. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15843. {
  15844. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15845. {
  15846. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15847. isSuccess = ConfigurationStatus_Accepted;
  15848. }
  15849. else
  15850. {
  15851. isSuccess = ConfigurationStatus_Rejected;
  15852. }
  15853. }
  15854. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15855. {
  15856. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15857. {
  15858. check_ascii = value[0];
  15859. if( (check_ascii < 48) || (check_ascii > 57) )
  15860. {
  15861. isSuccess = ConfigurationStatus_Rejected;
  15862. }
  15863. else
  15864. {
  15865. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15866. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15867. isSuccess = ConfigurationStatus_Accepted;
  15868. }
  15869. }
  15870. else
  15871. {
  15872. isSuccess = ConfigurationStatus_Rejected;
  15873. }
  15874. }
  15875. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15876. {
  15877. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15878. {
  15879. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15880. isSuccess = ConfigurationStatus_Accepted;
  15881. }
  15882. else
  15883. {
  15884. isSuccess = ConfigurationStatus_Rejected;
  15885. }
  15886. }
  15887. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15888. {
  15889. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15890. {
  15891. check_ascii = value[0];
  15892. if( (check_ascii < 48) || (check_ascii > 57) )
  15893. {
  15894. isSuccess = ConfigurationStatus_Rejected;
  15895. }
  15896. else
  15897. {
  15898. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15899. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15900. isSuccess = ConfigurationStatus_Accepted;
  15901. }
  15902. }
  15903. else
  15904. {
  15905. isSuccess = ConfigurationStatus_Rejected;
  15906. }
  15907. }
  15908. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15909. {
  15910. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15911. {
  15912. check_ascii = value[0];
  15913. if( (check_ascii < 48) || (check_ascii > 57) )
  15914. {
  15915. isSuccess = ConfigurationStatus_Rejected;
  15916. }
  15917. else
  15918. {
  15919. if((atoi(value) == 0) || (atoi(value) >= 3))
  15920. {
  15921. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15922. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15923. isSuccess = ConfigurationStatus_Accepted;
  15924. }
  15925. else
  15926. {
  15927. isSuccess = ConfigurationStatus_Rejected;
  15928. }
  15929. }
  15930. }
  15931. else
  15932. {
  15933. isSuccess = ConfigurationStatus_Rejected;
  15934. }
  15935. }
  15936. if(strcmp(key, "MinimumStatusDuration") == 0)
  15937. {
  15938. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15939. {
  15940. check_ascii = value[0];
  15941. if( (check_ascii < 48) || (check_ascii > 57) )
  15942. {
  15943. isSuccess = ConfigurationStatus_Rejected;
  15944. }
  15945. else
  15946. {
  15947. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15948. {
  15949. isSuccess = ConfigurationStatus_Rejected;
  15950. }
  15951. else
  15952. {
  15953. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15954. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15955. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15956. isSuccess = ConfigurationStatus_Accepted;
  15957. }
  15958. }
  15959. }
  15960. else
  15961. {
  15962. isSuccess = ConfigurationStatus_Rejected;
  15963. }
  15964. }
  15965. if(strcmp(key, "NumberOfConnectors") == 0)
  15966. {
  15967. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15968. {
  15969. check_ascii = value[0];
  15970. if( (check_ascii < 48) || (check_ascii > 57) )
  15971. {
  15972. isSuccess = ConfigurationStatus_Rejected;
  15973. }
  15974. else
  15975. {
  15976. //Charger.ResetRetries = Integer.parseInt(value);
  15977. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15978. isSuccess = ConfigurationStatus_Accepted;
  15979. }
  15980. }
  15981. else
  15982. {
  15983. isSuccess = ConfigurationStatus_Rejected;
  15984. }
  15985. }
  15986. if(strcmp(key, "ResetRetries") == 0)
  15987. {
  15988. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15989. {
  15990. check_ascii = value[0];
  15991. if( (check_ascii < 48) || (check_ascii > 57) )
  15992. {
  15993. isSuccess = ConfigurationStatus_Rejected;
  15994. }
  15995. else
  15996. {
  15997. //Charger.ResetRetries = Integer.parseInt(value);
  15998. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15999. isSuccess = ConfigurationStatus_Accepted;
  16000. }
  16001. }
  16002. else
  16003. {
  16004. isSuccess = ConfigurationStatus_Rejected;
  16005. }
  16006. }
  16007. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16008. {
  16009. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16010. {
  16011. strcpy(str, (const char*)value);
  16012. for(int i = 0; str[i]; i++)
  16013. {
  16014. str[i] = tolower(str[i]);
  16015. }
  16016. if(strcmp(str, "notapplicable")== 0)
  16017. {
  16018. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16019. isSuccess = ConfigurationStatus_Accepted;
  16020. }
  16021. else if(strcmp(str, "unknown")== 0)
  16022. {
  16023. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16024. isSuccess = ConfigurationStatus_Accepted;
  16025. }
  16026. else if(strcmp(str, "rst")== 0)
  16027. {
  16028. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16029. isSuccess = ConfigurationStatus_Accepted;
  16030. }
  16031. else if(strcmp(str, "rts")== 0)
  16032. {
  16033. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16034. isSuccess = ConfigurationStatus_Accepted;
  16035. }
  16036. else if(strcmp(str, "srt")== 0)
  16037. {
  16038. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16039. isSuccess = ConfigurationStatus_Accepted;
  16040. }
  16041. else if(strcmp(str, "str")== 0)
  16042. {
  16043. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16044. isSuccess = ConfigurationStatus_Accepted;
  16045. }
  16046. else if(strcmp(str, "trs")== 0)
  16047. {
  16048. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16049. isSuccess = ConfigurationStatus_Accepted;
  16050. }
  16051. else if(strcmp(str, "tsr")== 0)
  16052. {
  16053. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16054. isSuccess = ConfigurationStatus_Accepted;
  16055. }
  16056. else
  16057. {
  16058. isSuccess = ConfigurationStatus_Rejected;
  16059. }
  16060. }
  16061. else
  16062. {
  16063. isSuccess = ConfigurationStatus_Rejected;
  16064. }
  16065. }
  16066. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16067. {
  16068. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16069. {
  16070. check_ascii = value[0];
  16071. if( (check_ascii < 48) || (check_ascii > 57) )
  16072. {
  16073. isSuccess = ConfigurationStatus_Rejected;
  16074. }
  16075. else
  16076. {
  16077. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16078. isSuccess = ConfigurationStatus_Accepted;
  16079. }
  16080. }
  16081. else
  16082. {
  16083. isSuccess = ConfigurationStatus_Rejected;
  16084. }
  16085. }
  16086. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16087. {
  16088. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16089. {
  16090. strcpy(str, (const char*)value);
  16091. for(int i = 0; str[i]; i++)
  16092. {
  16093. str[i] = tolower(str[i]);
  16094. }
  16095. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16096. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16097. isSuccess = ConfigurationStatus_Accepted;
  16098. }
  16099. else
  16100. {
  16101. isSuccess = ConfigurationStatus_Rejected;
  16102. }
  16103. }
  16104. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16105. {
  16106. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16107. {
  16108. strcpy(str, (const char*)value);
  16109. for(int i = 0; str[i]; i++)
  16110. {
  16111. str[i] = tolower(str[i]);
  16112. }
  16113. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16114. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16115. isSuccess = ConfigurationStatus_Accepted;
  16116. }
  16117. else
  16118. {
  16119. isSuccess = ConfigurationStatus_Rejected;
  16120. }
  16121. }
  16122. if(strcmp(key, "StopTxnAlignedData") == 0)
  16123. {
  16124. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16125. {
  16126. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16127. isSuccess = ConfigurationStatus_Accepted;
  16128. }
  16129. else
  16130. {
  16131. isSuccess = ConfigurationStatus_Rejected;
  16132. }
  16133. }
  16134. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16135. {
  16136. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16137. {
  16138. check_ascii = value[0];
  16139. if( (check_ascii < 48) || (check_ascii > 57) )
  16140. {
  16141. isSuccess = ConfigurationStatus_Rejected;
  16142. }
  16143. else
  16144. {
  16145. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16146. isSuccess = ConfigurationStatus_Accepted;
  16147. }
  16148. }
  16149. else
  16150. {
  16151. isSuccess = ConfigurationStatus_Rejected;
  16152. }
  16153. }
  16154. if(strcmp(key, "StopTxnSampledData") == 0)
  16155. {
  16156. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16157. {
  16158. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16159. isSuccess = ConfigurationStatus_Accepted;
  16160. }
  16161. else
  16162. {
  16163. isSuccess = ConfigurationStatus_Rejected;
  16164. }
  16165. }
  16166. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16167. {
  16168. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16169. {
  16170. check_ascii = value[0];
  16171. if( (check_ascii < 48) || (check_ascii > 57) )
  16172. {
  16173. isSuccess = ConfigurationStatus_Rejected;
  16174. }
  16175. else
  16176. {
  16177. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16178. isSuccess = ConfigurationStatus_Accepted;
  16179. }
  16180. }
  16181. else
  16182. {
  16183. isSuccess = ConfigurationStatus_Rejected;
  16184. }
  16185. }
  16186. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16187. {
  16188. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16189. {
  16190. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16191. isSuccess = ConfigurationStatus_Accepted;
  16192. }
  16193. else
  16194. {
  16195. isSuccess = ConfigurationStatus_Rejected;
  16196. }
  16197. }
  16198. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16199. {
  16200. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16201. {
  16202. check_ascii = value[0];
  16203. if( (check_ascii < 48) || (check_ascii > 57) )
  16204. {
  16205. isSuccess = ConfigurationStatus_Rejected;
  16206. }
  16207. else
  16208. {
  16209. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16210. isSuccess = ConfigurationStatus_Accepted;
  16211. }
  16212. }
  16213. else
  16214. {
  16215. isSuccess = ConfigurationStatus_Rejected;
  16216. }
  16217. }
  16218. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16219. {
  16220. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16221. {
  16222. check_ascii = value[0];
  16223. if( (check_ascii < 48) || (check_ascii > 57) )
  16224. {
  16225. isSuccess = ConfigurationStatus_Rejected;
  16226. }
  16227. else
  16228. {
  16229. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16230. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16231. TransactionMessageAttemptsValue = atoi(value);
  16232. isSuccess = ConfigurationStatus_Accepted;
  16233. }
  16234. }
  16235. else
  16236. {
  16237. isSuccess = ConfigurationStatus_Rejected;
  16238. }
  16239. }
  16240. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16241. {
  16242. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16243. {
  16244. check_ascii = value[0];
  16245. if( (check_ascii < 48) || (check_ascii > 57) )
  16246. {
  16247. isSuccess = ConfigurationStatus_Rejected;
  16248. }
  16249. else
  16250. {
  16251. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16252. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16253. TransactionMessageRetryIntervalValue = atoi(value);
  16254. isSuccess = ConfigurationStatus_Accepted;
  16255. }
  16256. }
  16257. else
  16258. {
  16259. isSuccess = ConfigurationStatus_Rejected;
  16260. }
  16261. }
  16262. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16263. {
  16264. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16265. {
  16266. strcpy(str, (const char*)value);
  16267. for(int i = 0; str[i]; i++)
  16268. {
  16269. str[i] = tolower(str[i]);
  16270. }
  16271. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16272. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16273. isSuccess = ConfigurationStatus_Accepted;
  16274. }
  16275. else
  16276. {
  16277. isSuccess = ConfigurationStatus_Rejected;
  16278. }
  16279. }
  16280. if(strcmp(key, "WebSocketPingInterval") == 0)
  16281. {
  16282. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16283. {
  16284. check_ascii = value[0];
  16285. if( (check_ascii < 48) || (check_ascii > 57) )
  16286. {
  16287. isSuccess = ConfigurationStatus_Rejected;
  16288. }
  16289. else
  16290. {
  16291. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16292. isSuccess = ConfigurationStatus_Accepted;
  16293. if((atoi(value) == 0) || (atoi(value) >= 10))
  16294. {
  16295. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16296. isSuccess = ConfigurationStatus_Accepted;
  16297. }
  16298. else
  16299. isSuccess = ConfigurationStatus_Rejected;
  16300. }
  16301. }
  16302. else
  16303. {
  16304. isSuccess = ConfigurationStatus_Rejected;
  16305. }
  16306. }
  16307. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16308. {
  16309. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16310. {
  16311. strcpy(str, (const char*)value);
  16312. for(int i = 0; str[i]; i++)
  16313. {
  16314. str[i] = tolower(str[i]);
  16315. }
  16316. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16317. isSuccess = ConfigurationStatus_Accepted;
  16318. }
  16319. else
  16320. {
  16321. isSuccess = ConfigurationStatus_Rejected;
  16322. }
  16323. }
  16324. if(strcmp(key, "AuthorizationKey") == 0)
  16325. {
  16326. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16327. {
  16328. strcpy(str, (const char*)value);
  16329. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16330. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16331. isSuccess = ConfigurationStatus_Accepted;
  16332. }
  16333. else
  16334. {
  16335. isSuccess = ConfigurationStatus_Rejected;
  16336. }
  16337. }
  16338. if(strcmp(key, "SecurityProfile") == 0)
  16339. {
  16340. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16341. {
  16342. check_ascii = value[0];
  16343. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16344. {
  16345. isSuccess = ConfigurationStatus_Rejected;
  16346. }
  16347. else if(check_ascii == 0x33)
  16348. {
  16349. isSuccess = NotSupported;
  16350. }
  16351. else
  16352. {
  16353. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16354. {
  16355. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16356. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16357. isSuccess = ConfigurationStatus_Accepted;
  16358. }
  16359. else
  16360. isSuccess = ConfigurationStatus_Rejected;
  16361. }
  16362. }
  16363. else
  16364. {
  16365. isSuccess = ConfigurationStatus_Rejected;
  16366. }
  16367. }
  16368. if(strcmp(key, "DefaultPrice") == 0)
  16369. {
  16370. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16371. {
  16372. strcpy(str, (const char*)value);
  16373. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16374. isSuccess = ConfigurationStatus_Accepted;
  16375. }
  16376. else
  16377. {
  16378. isSuccess = ConfigurationStatus_Rejected;
  16379. }
  16380. }
  16381. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16382. {
  16383. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16384. {
  16385. strcpy(str, (const char*)value);
  16386. for(int i = 0; str[i]; i++)
  16387. {
  16388. str[i] = tolower(str[i]);
  16389. }
  16390. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16391. isSuccess = ConfigurationStatus_Accepted;
  16392. }
  16393. else
  16394. {
  16395. isSuccess = ConfigurationStatus_Rejected;
  16396. }
  16397. }
  16398. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16399. {
  16400. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16401. {
  16402. strcpy(str, (const char*)value);
  16403. for(int i = 0; str[i]; i++)
  16404. {
  16405. str[i] = tolower(str[i]);
  16406. }
  16407. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16408. isSuccess = ConfigurationStatus_Accepted;
  16409. }
  16410. else
  16411. {
  16412. isSuccess = ConfigurationStatus_Rejected;
  16413. }
  16414. }
  16415. if(strcmp(key, "SystemUptimeSec") == 0)
  16416. {
  16417. isSuccess = NotSupported;
  16418. }
  16419. if(strcmp(key, "FreeVend") == 0)
  16420. {
  16421. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16422. {
  16423. strcpy(str, (const char*)value);
  16424. for(int i = 0; str[i]; i++)
  16425. {
  16426. str[i] = tolower(str[i]);
  16427. }
  16428. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16429. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16430. isSuccess = ConfigurationStatus_Accepted;
  16431. }
  16432. else
  16433. {
  16434. isSuccess = ConfigurationStatus_Rejected;
  16435. }
  16436. }
  16437. if(strcmp(key, "FreeVendIdtag") == 0)
  16438. {
  16439. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16440. {
  16441. strcpy(str, (const char*)value);
  16442. if(strlen(str) <= 20)
  16443. {
  16444. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16445. isSuccess = ConfigurationStatus_Accepted;
  16446. }
  16447. else
  16448. {
  16449. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16450. isSuccess = ConfigurationStatus_Rejected;
  16451. }
  16452. }
  16453. else
  16454. {
  16455. isSuccess = ConfigurationStatus_Rejected;
  16456. }
  16457. }
  16458. if(strcmp(key, "OcppServer") == 0)
  16459. {
  16460. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16461. {
  16462. strcpy(str, (const char*)value);
  16463. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16464. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16465. isSuccess = ConfigurationStatus_Accepted;
  16466. }
  16467. else
  16468. {
  16469. isSuccess = ConfigurationStatus_Rejected;
  16470. }
  16471. }
  16472. if(strcmp(key, "MaintainServer") == 0)
  16473. {
  16474. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16475. {
  16476. strcpy(str, (const char*)value);
  16477. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16478. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16479. isSuccess = ConfigurationStatus_Accepted;
  16480. }
  16481. else
  16482. {
  16483. isSuccess = ConfigurationStatus_Rejected;
  16484. }
  16485. }
  16486. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16487. {
  16488. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16489. {
  16490. strcpy(str, (const char*)value);
  16491. for(int i = 0; str[i]; i++)
  16492. {
  16493. str[i] = tolower(str[i]);
  16494. }
  16495. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16496. isSuccess = ConfigurationStatus_Accepted;
  16497. }
  16498. else
  16499. {
  16500. isSuccess = ConfigurationStatus_Rejected;
  16501. }
  16502. }
  16503. if(strcmp(key, "StatusNotificationInterval") == 0)
  16504. {
  16505. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16506. {
  16507. check_ascii = value[0];
  16508. if( (check_ascii < 48) || (check_ascii > 57) )
  16509. {
  16510. isSuccess = ConfigurationStatus_Rejected;
  16511. }
  16512. else
  16513. {
  16514. if((atoi(value) == 0) || (atoi(value) >= 10))
  16515. {
  16516. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16517. isSuccess = ConfigurationStatus_Accepted;
  16518. }
  16519. else
  16520. isSuccess = ConfigurationStatus_Rejected;
  16521. }
  16522. }
  16523. else
  16524. {
  16525. isSuccess = ConfigurationStatus_Rejected;
  16526. }
  16527. }
  16528. #if 0
  16529. //For OCPP Test Case
  16530. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16531. {
  16532. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16533. {
  16534. strcpy(str, (const char*)value);
  16535. for(int i = 0; str[i]; i++)
  16536. {
  16537. str[i] = tolower(str[i]);
  16538. }
  16539. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16540. isSuccess = ConfigurationStatus_Accepted;
  16541. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16542. }
  16543. else
  16544. {
  16545. isSuccess = ConfigurationStatus_Rejected;
  16546. }
  16547. }
  16548. #endif
  16549. #if 1
  16550. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16551. {
  16552. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16553. {
  16554. strcpy(str, (const char*)value);
  16555. for(int i = 0; str[i]; i++)
  16556. {
  16557. str[i] = tolower(str[i]);
  16558. }
  16559. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16560. isSuccess = ConfigurationStatus_Accepted;
  16561. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16562. }
  16563. else
  16564. {
  16565. isSuccess = ConfigurationStatus_Rejected;
  16566. }
  16567. }
  16568. #endif
  16569. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16570. {
  16571. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16572. {
  16573. check_ascii = value[0];
  16574. if( (check_ascii < 48) || (check_ascii > 57) )
  16575. {
  16576. isSuccess = ConfigurationStatus_Rejected;
  16577. }
  16578. else
  16579. {
  16580. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16581. isSuccess = ConfigurationStatus_Accepted;
  16582. }
  16583. }
  16584. else
  16585. {
  16586. isSuccess = ConfigurationStatus_Rejected;
  16587. }
  16588. }
  16589. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16590. {
  16591. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16592. {
  16593. check_ascii = value[0];
  16594. if( (check_ascii < 48) || (check_ascii > 57) )
  16595. {
  16596. isSuccess = ConfigurationStatus_Rejected;
  16597. }
  16598. else
  16599. {
  16600. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16601. isSuccess = ConfigurationStatus_Accepted;
  16602. }
  16603. }
  16604. else
  16605. {
  16606. isSuccess = ConfigurationStatus_Rejected;
  16607. }
  16608. }
  16609. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16610. {
  16611. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16612. {
  16613. strcpy(str, (const char*)value);
  16614. for(int i = 0; str[i]; i++)
  16615. {
  16616. str[i] = tolower(str[i]);
  16617. }
  16618. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16619. isSuccess = ConfigurationStatus_Accepted;
  16620. }
  16621. else
  16622. {
  16623. isSuccess = ConfigurationStatus_Rejected;
  16624. }
  16625. }
  16626. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16627. {
  16628. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16629. {
  16630. check_ascii = value[0];
  16631. if( (check_ascii < 48) || (check_ascii > 57) )
  16632. {
  16633. isSuccess = ConfigurationStatus_Rejected;
  16634. }
  16635. else
  16636. {
  16637. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16638. isSuccess = ConfigurationStatus_Accepted;
  16639. }
  16640. }
  16641. else
  16642. {
  16643. isSuccess = ConfigurationStatus_Rejected;
  16644. }
  16645. }
  16646. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16647. {
  16648. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16649. {
  16650. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16651. isSuccess = ConfigurationStatus_Accepted;
  16652. }
  16653. else
  16654. {
  16655. isSuccess = ConfigurationStatus_Rejected;
  16656. }
  16657. }
  16658. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16659. {
  16660. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16661. {
  16662. check_ascii = value[0];
  16663. if( (check_ascii < 48) || (check_ascii > 57) )
  16664. {
  16665. isSuccess = ConfigurationStatus_Rejected;
  16666. }
  16667. else
  16668. {
  16669. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16670. isSuccess = ConfigurationStatus_Accepted;
  16671. }
  16672. }
  16673. else
  16674. {
  16675. isSuccess = ConfigurationStatus_Rejected;
  16676. }
  16677. }
  16678. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16679. {
  16680. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16681. {
  16682. strcpy(str, (const char*)value);
  16683. for(int i = 0; str[i]; i++)
  16684. {
  16685. str[i] = tolower(str[i]);
  16686. }
  16687. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16688. isSuccess = ConfigurationStatus_Accepted;
  16689. }
  16690. else
  16691. {
  16692. isSuccess = ConfigurationStatus_Rejected;
  16693. }
  16694. }
  16695. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16696. {
  16697. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16698. {
  16699. check_ascii = value[0];
  16700. if( (check_ascii < 48) || (check_ascii > 57) )
  16701. {
  16702. isSuccess = ConfigurationStatus_Rejected;
  16703. }
  16704. else
  16705. {
  16706. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16707. isSuccess = ConfigurationStatus_Accepted;
  16708. }
  16709. }
  16710. else
  16711. {
  16712. isSuccess = ConfigurationStatus_Rejected;
  16713. }
  16714. }
  16715. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16716. return isSuccess;
  16717. }
  16718. int TransactionMessageAttemptsGet(void)
  16719. {
  16720. return TransactionMessageAttemptsValue;
  16721. }
  16722. int FirstHeartBeatResponse(void)
  16723. {
  16724. return FirstHeartBeat;
  16725. }
  16726. int TransactionMessageRetryIntervalGet(void)
  16727. {
  16728. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16729. }
  16730. int ReadHttpStatus(int sock)
  16731. {
  16732. //char c;
  16733. char buff[1024]="",*ptr=buff+1;
  16734. int bytes_received, status;
  16735. DEBUG_INFO("Begin Response ..\n");
  16736. while((bytes_received = recv(sock, ptr, 1, 0))){
  16737. if(bytes_received==-1){
  16738. perror("ReadHttpStatus");
  16739. exit(1);
  16740. }
  16741. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16742. ptr++;
  16743. }
  16744. *ptr=0;
  16745. ptr=buff+1;
  16746. sscanf(ptr,"%*s %d ", &status);
  16747. DEBUG_INFO("%s\n",ptr);
  16748. DEBUG_INFO("status=%d\n",status);
  16749. DEBUG_INFO("End Response ..\n");
  16750. return (bytes_received>0)?status:0;
  16751. }
  16752. //the only filed that it parsed is 'Content-Length'
  16753. int ParseHeader(int sock)
  16754. {
  16755. //char c;
  16756. char buff[1024]="",*ptr=buff+4;
  16757. int bytes_received;
  16758. DEBUG_INFO("Begin HEADER ..\n");
  16759. while((bytes_received = recv(sock, ptr, 1, 0))){
  16760. if(bytes_received==-1){
  16761. perror("Parse Header");
  16762. exit(1);
  16763. }
  16764. if(
  16765. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16766. (ptr[-1]=='\r') && (*ptr=='\n' )
  16767. ) break;
  16768. ptr++;
  16769. }
  16770. *ptr=0;
  16771. ptr=buff+4;
  16772. //printf("%s",ptr);
  16773. if(bytes_received){
  16774. ptr=strstr(ptr,"Content-Length:");
  16775. if(ptr){
  16776. sscanf(ptr,"%*s %d",&bytes_received);
  16777. }else
  16778. bytes_received=-1; //unknown size
  16779. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16780. }
  16781. DEBUG_INFO("End HEADER ..\n");
  16782. return bytes_received ;
  16783. }
  16784. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16785. {
  16786. int result = TRUE;
  16787. char rmFileCmd[100]={0};
  16788. char FilePath[100]={0};
  16789. char ftpbuf[200];
  16790. int systemresult;
  16791. sprintf(FilePath,"/mnt/%s",filename);
  16792. system("ping 8.8.8.8 &");
  16793. if((access(FilePath,F_OK))!=-1)
  16794. {
  16795. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16796. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16797. system(rmFileCmd);
  16798. }
  16799. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16800. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16801. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16802. systemresult = system(ftpbuf);
  16803. if(systemresult != 0)
  16804. {
  16805. DEBUG_INFO("http DownLoad error!\n");
  16806. result = FALSE;
  16807. }
  16808. system("pkill ping");
  16809. return result;
  16810. }
  16811. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16812. {
  16813. int result = TRUE;
  16814. char rmFileCmd[100]={0};
  16815. char FilePath[100]={0};
  16816. char ftpbuf[200];
  16817. int systemresult;
  16818. sprintf(FilePath,"/mnt/%s",filename);
  16819. system("ping 8.8.8.8 &");
  16820. if((access(FilePath,F_OK))!=-1)
  16821. {
  16822. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16823. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16824. system(rmFileCmd);
  16825. }
  16826. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16827. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16828. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16829. systemresult = system(ftpbuf);
  16830. if(systemresult != 0)
  16831. {
  16832. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16833. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16834. systemresult = system(ftpbuf);
  16835. if(systemresult != 0)
  16836. {
  16837. DEBUG_WARN("wget error!\n");
  16838. result = FALSE;
  16839. }
  16840. }
  16841. system("pkill ping");
  16842. return result;
  16843. }
  16844. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16845. {
  16846. char rmFileCmd[100]={0};
  16847. char FilePath[100]={0};
  16848. char buf[512];
  16849. int systemresult = 0;
  16850. //DEBUG_INFO("filename=%s\n",filename);
  16851. //DEBUG_INFO("url=%s\n",url);
  16852. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16853. if((access(FilePath,F_OK))!=-1)
  16854. {
  16855. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16856. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16857. system(rmFileCmd);
  16858. }
  16859. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16860. if(fp == NULL)
  16861. {
  16862. DEBUG_INFO("log is NULL\n");
  16863. return FALSE;
  16864. }
  16865. else
  16866. {
  16867. fprintf(fp, "%s\n", url);
  16868. fprintf(fp, "%s\n", filename);
  16869. fclose(fp);
  16870. }
  16871. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16872. if(phpFP == NULL)
  16873. {
  16874. DEBUG_INFO("PHP upload fail.\n");
  16875. return FALSE;
  16876. }
  16877. else
  16878. {
  16879. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16880. {
  16881. if(strstr(buf, "result") != NULL)
  16882. {
  16883. sscanf(buf, "result: %d", &systemresult);
  16884. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16885. }
  16886. }
  16887. pclose(phpFP);
  16888. }
  16889. if(systemresult != 1)
  16890. {
  16891. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  16892. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  16893. if(phpFP == NULL)
  16894. {
  16895. DEBUG_WARN("PHP PUT upload fail.\n");
  16896. return FALSE;
  16897. }
  16898. else
  16899. {
  16900. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16901. {
  16902. if(strstr(buf, "result") != NULL)
  16903. {
  16904. sscanf(buf, "result: %d", &systemresult);
  16905. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  16906. }
  16907. }
  16908. pclose(phpFP);
  16909. }
  16910. }
  16911. return TRUE;
  16912. }
  16913. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16914. {
  16915. int result = FALSE;
  16916. char ftpbuf[200];
  16917. int systemresult;
  16918. /*
  16919. // Domaind name transfer to IP address
  16920. struct hostent* server;
  16921. char *IPbuffer;
  16922. server = gethostbyname(location);
  16923. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16924. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16925. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16926. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16927. systemresult = system(ftpbuf);
  16928. if(systemresult != 0)
  16929. {
  16930. DEBUG_INFO("ftpput error!\n");
  16931. }
  16932. else
  16933. {
  16934. result = TRUE;
  16935. DEBUG_INFO("ftpput OK!\n");
  16936. }
  16937. return result;
  16938. }
  16939. int GetOcppServerURL()
  16940. {
  16941. int result = FALSE;
  16942. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16943. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16944. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16945. struct yuarel url;
  16946. char urlStr[512];
  16947. // OCPPPH only
  16948. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16949. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16950. {
  16951. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16952. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16953. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16954. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16955. if(yuarel_parse(&url, urlStr) != -1)
  16956. {
  16957. sprintf(OcppProtocol, "%s", url.scheme);
  16958. sprintf(OcppHost, "%s", url.host);
  16959. if(url.path == NULL)
  16960. OcppTempPath[0] = '\0';
  16961. else
  16962. sprintf(OcppTempPath, "%s", url.path);
  16963. if(url.port == 0)
  16964. {
  16965. if(strcmp(OcppProtocol, "wss") == 0)
  16966. OcppPort = 443;
  16967. else
  16968. OcppPort = 80;
  16969. }
  16970. else
  16971. OcppPort = url.port;
  16972. result = TRUE;
  16973. }
  16974. }
  16975. else
  16976. {
  16977. strcpy(OcppHost,"");
  16978. }
  16979. return result;
  16980. }
  16981. int GetOcppPath()
  16982. {
  16983. int result = FALSE;
  16984. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16985. {
  16986. if(OcppTempPath == NULL)
  16987. {
  16988. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16989. }
  16990. else
  16991. {
  16992. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16993. }
  16994. result = TRUE;
  16995. goto End;
  16996. }
  16997. else
  16998. {
  16999. strcpy(OcppPath,"");
  17000. }
  17001. End:
  17002. return result;
  17003. }
  17004. int GetOcppPort()
  17005. {
  17006. return OcppPort;
  17007. }
  17008. int GetOcppConnStatus(void)
  17009. {
  17010. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17011. }
  17012. void SetOcppConnStatus(uint8_t status)
  17013. {
  17014. ShmOCPP16DataPH->OcppConnStatus = status;
  17015. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17016. }
  17017. int GetHeartBeatWithNOResponse(void)
  17018. {
  17019. return HeartBeatWithNOResponse;
  17020. }
  17021. void SetHeartBeatWithNOResponse(void)
  17022. {
  17023. HeartBeatWithNOResponse = 0;
  17024. }
  17025. void GetStartTransactionIdTag(int gun_index)
  17026. {
  17027. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17028. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17029. }
  17030. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17031. {
  17032. char ch;
  17033. FILE *fptr1;
  17034. int temptransactionId;
  17035. char str[100]={0};
  17036. temptransactionId = 0;
  17037. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17038. {
  17039. DEBUG_INFO("IdTag is empty.\n");
  17040. return temptransactionId;
  17041. }
  17042. /*------ Read the file ----------------*/
  17043. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17044. if (!fptr1)
  17045. {
  17046. DEBUG_INFO("QueueTransactionId file open error.\n");
  17047. //printf(" File not found or unable to open the input file!!\n");
  17048. return temptransactionId;
  17049. }
  17050. ch=fgetc(fptr1);
  17051. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17052. rewind(fptr1);
  17053. if(ch!=EOF)
  17054. {
  17055. // printf("%c",ch);
  17056. while (fgets(str, 100, fptr1) != NULL)
  17057. {
  17058. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17059. if(str[0]=='\0')
  17060. {
  17061. break;
  17062. }
  17063. char *revbuf[8] = {0}; // Variable store string split
  17064. int num = 0;// Quantity after string split
  17065. DEBUG_INFO("Transaction queue data= %s\n", str);
  17066. splitstring(str,",",revbuf,&num); // String split
  17067. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17068. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17069. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17070. DEBUG_INFO("------------------------------\n");
  17071. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17072. {
  17073. if(isStopTransaction)
  17074. {
  17075. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17076. {
  17077. temptransactionId = atoi(revbuf[2]);
  17078. //break;
  17079. }
  17080. }
  17081. else
  17082. {
  17083. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17084. {
  17085. temptransactionId = atoi(revbuf[2]);
  17086. //break;
  17087. }
  17088. }
  17089. }
  17090. }
  17091. }
  17092. else
  17093. DEBUG_INFO("EOF\n");
  17094. fclose(fptr1);
  17095. /*------- End of reading ---------------*/
  17096. return temptransactionId;
  17097. }
  17098. void SetTransactionIdZero(int transactionId)
  17099. {
  17100. char ch;
  17101. FILE *fptr1, *fptr2;
  17102. int temptransactionId = 0;
  17103. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17104. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17105. if (!fptr1)
  17106. {
  17107. //printf(" File not found or unable to open the input file!!\n");
  17108. return ;
  17109. }
  17110. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17111. if (!fptr2)
  17112. {
  17113. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17114. fclose(fptr1);
  17115. return ;
  17116. }
  17117. ch=fgetc(fptr1);
  17118. rewind(fptr1);
  17119. if(ch!=EOF)
  17120. {
  17121. // copy all contents to the temporary file except the specific line
  17122. while (fgets(str, 100, fptr1) != NULL)
  17123. {
  17124. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17125. if(str[0]=='\0')
  17126. {
  17127. break;
  17128. }
  17129. char *revbuf[8] = {0};
  17130. int num = 0;
  17131. strcpy(strtemp, str);
  17132. splitstring(str,",",revbuf,&num);
  17133. if(revbuf[2][0] != '\0')
  17134. {
  17135. temptransactionId = atoi(revbuf[2]);
  17136. if(transactionId != temptransactionId)
  17137. {
  17138. fprintf(fptr2, "%s\n", strtemp);
  17139. }
  17140. }
  17141. }
  17142. }
  17143. fclose(fptr1);
  17144. fclose(fptr2);
  17145. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17146. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17147. /*------ Read the file ----------------*/
  17148. }
  17149. int InternetDisconnect(void)
  17150. {
  17151. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17152. }
  17153. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17154. void storeTempStopTransaction(int gun_index)
  17155. {
  17156. char guid[37]={0};
  17157. int tempIndex = 0;
  17158. char TempStopTransaction[256];
  17159. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17160. DEBUG_INFO("storeTempStopTransaction...\n");
  17161. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17162. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17163. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17164. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17165. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17166. {
  17167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17168. {
  17169. tempIndex = ((gun_index==2) ? 1: 0);
  17170. }
  17171. else
  17172. {
  17173. tempIndex = gun_index;
  17174. }
  17175. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17176. {
  17177. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17178. {
  17179. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17180. }
  17181. }// END OF CHAdeMO_QUANTITY
  17182. }
  17183. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17184. {
  17185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17186. {
  17187. tempIndex = ((gun_index==2) ? 1: 0);
  17188. }
  17189. else
  17190. {
  17191. tempIndex = gun_index;
  17192. }
  17193. for (int index = 0; index < CCS_QUANTITY; index++)
  17194. {
  17195. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17196. {
  17197. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17198. }
  17199. }// END OF CCS_QUANTITY
  17200. }
  17201. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17202. {
  17203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17204. {
  17205. tempIndex = ((gun_index==2) ? 1: 0);
  17206. }
  17207. else
  17208. {
  17209. tempIndex = gun_index;
  17210. }
  17211. for (int index = 0; index < GB_QUANTITY; index++)
  17212. {
  17213. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17214. {
  17215. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17216. }
  17217. }// END OF GB_QUANTITY
  17218. }
  17219. else if(gunType[gun_index] == GUN_TYPE_DO)
  17220. {
  17221. tempIndex = gun_index;
  17222. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17223. {
  17224. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17225. {
  17226. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17227. }
  17228. }
  17229. }
  17230. else
  17231. {
  17232. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17233. {
  17234. tempIndex = 2;
  17235. }
  17236. else
  17237. {
  17238. tempIndex = gun_index;
  17239. }
  17240. for (int index = 0; index < AC_QUANTITY; index++)
  17241. {
  17242. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17243. {
  17244. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17245. }
  17246. }// END OF AC_QUANTITY
  17247. }
  17248. //Stop Transaction Time
  17249. struct timeval tmnow;
  17250. struct tm *tm;
  17251. char buf[28];//, usec_buf[6];
  17252. gettimeofday(&tmnow, NULL);
  17253. time_t t;
  17254. t = time(NULL);
  17255. /*UTC time and date*/
  17256. tm = gmtime(&t);
  17257. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17258. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17259. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17260. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17261. random_uuid(guid);
  17262. /***********************************transactionData******************************************************/
  17263. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17264. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17265. //=================================
  17266. //1. Transaction_Begin
  17267. //=================================
  17268. //============================== Energy.Active.Import.Interval ===========================================
  17269. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17270. {
  17271. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17272. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17273. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17274. 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*/]);
  17275. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17276. 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))
  17277. {
  17278. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17279. }
  17280. else
  17281. {
  17282. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17283. }
  17284. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17285. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17286. }
  17287. //=================================
  17288. //2. Transaction_End
  17289. //=================================
  17290. //2.1====================================== Current.Import L1 ==============================================
  17291. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17292. {
  17293. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17294. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17295. {
  17296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17297. {
  17298. tempIndex = ((gun_index==2) ? 1: 0);
  17299. }
  17300. else
  17301. {
  17302. tempIndex = gun_index;
  17303. }
  17304. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17305. {
  17306. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17307. {
  17308. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17309. }
  17310. }// End of for CHAdeMO_QUANTITY
  17311. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17312. }
  17313. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17314. {
  17315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17316. {
  17317. tempIndex = ((gun_index==2) ? 1: 0);
  17318. }
  17319. else
  17320. {
  17321. tempIndex = gun_index;
  17322. }
  17323. for (int index = 0; index < CCS_QUANTITY; index++)
  17324. {
  17325. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17326. {
  17327. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17328. }
  17329. }// End of for CCS_QUANTITY
  17330. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17331. }
  17332. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17333. {
  17334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17335. {
  17336. tempIndex = ((gun_index==2) ? 1: 0);
  17337. }
  17338. else
  17339. {
  17340. tempIndex = gun_index;
  17341. }
  17342. for (int index = 0; index < GB_QUANTITY; index++)
  17343. {
  17344. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17345. {
  17346. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17347. }
  17348. }// End of for GB_QUANTITY
  17349. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17350. }
  17351. else if(gunType[gun_index] == GUN_TYPE_DO)
  17352. {
  17353. tempIndex = gun_index;
  17354. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17355. {
  17356. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17357. {
  17358. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17359. }
  17360. }
  17361. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17362. }
  17363. else
  17364. {
  17365. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17366. {
  17367. tempIndex = 2;
  17368. }
  17369. else
  17370. {
  17371. tempIndex = gun_index;
  17372. }
  17373. for (int index = 0; index < AC_QUANTITY; index++)
  17374. {
  17375. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17376. {
  17377. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17378. }
  17379. }// End of for AC_QUANTITY
  17380. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17381. }
  17382. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17383. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17384. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17385. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17386. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17387. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17388. }
  17389. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17390. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17391. {
  17392. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17393. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17394. {
  17395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17396. {
  17397. tempIndex = ((gun_index==2) ? 1: 0);
  17398. }
  17399. else
  17400. {
  17401. tempIndex = gun_index;
  17402. }
  17403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17404. {
  17405. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17406. {
  17407. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17408. }
  17409. }// END OF CHAdeMO_QUANTITY
  17410. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17411. }
  17412. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17413. {
  17414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17415. {
  17416. tempIndex = ((gun_index==2) ? 1: 0);
  17417. }
  17418. else
  17419. {
  17420. tempIndex = gun_index;
  17421. }
  17422. for (int index = 0; index < CCS_QUANTITY; index++)
  17423. {
  17424. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17425. {
  17426. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17427. }
  17428. }// END OF CCS_QUANTITY
  17429. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17430. }
  17431. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17432. {
  17433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17434. {
  17435. tempIndex = ((gun_index==2) ? 1: 0);
  17436. }
  17437. else
  17438. {
  17439. tempIndex = gun_index;
  17440. }
  17441. for (int index = 0; index < GB_QUANTITY; index++)
  17442. {
  17443. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17444. {
  17445. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17446. }
  17447. }// END OF GB_QUANTITY
  17448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17449. }
  17450. else if(gunType[gun_index] == GUN_TYPE_DO)
  17451. {
  17452. tempIndex = gun_index;
  17453. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17454. {
  17455. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17456. {
  17457. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17458. }
  17459. }
  17460. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17461. }
  17462. else
  17463. {
  17464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17465. {
  17466. tempIndex = 2;
  17467. }
  17468. else
  17469. {
  17470. tempIndex = gun_index;
  17471. }
  17472. for (int index = 0; index < AC_QUANTITY; index++)
  17473. {
  17474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17475. {
  17476. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17477. }
  17478. }// END OF AC_QUANTITY
  17479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17480. }
  17481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17482. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17483. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17484. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17486. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17487. }
  17488. //2.3====================================== Power.Active.Import =========================================
  17489. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17490. {
  17491. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17492. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17493. {
  17494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17495. {
  17496. tempIndex = ((gun_index==2) ? 1: 0);
  17497. }
  17498. else
  17499. {
  17500. tempIndex = gun_index;
  17501. }
  17502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17503. {
  17504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17505. {
  17506. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17507. }
  17508. } // End for CHAdeMO_QUANTITY
  17509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17510. }
  17511. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17512. {
  17513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17514. {
  17515. tempIndex = ((gun_index==2) ? 1: 0);
  17516. }
  17517. else
  17518. {
  17519. tempIndex = gun_index;
  17520. }
  17521. for (int index = 0; index < CCS_QUANTITY; index++)
  17522. {
  17523. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17524. {
  17525. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17526. }
  17527. } // END for CCS_QUANTITY
  17528. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17529. }
  17530. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17531. {
  17532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17533. {
  17534. tempIndex = ((gun_index==2) ? 1: 0);
  17535. }
  17536. else
  17537. {
  17538. tempIndex = gun_index;
  17539. }
  17540. for (int index = 0; index < GB_QUANTITY; index++)
  17541. {
  17542. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17543. {
  17544. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17545. }
  17546. }// END for GB_QUANTITY
  17547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17548. }
  17549. else if(gunType[gun_index] == GUN_TYPE_DO)
  17550. {
  17551. tempIndex = gun_index;
  17552. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17553. {
  17554. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17555. {
  17556. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17557. }
  17558. }
  17559. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17560. }
  17561. else
  17562. {
  17563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17564. {
  17565. tempIndex = 2;
  17566. }
  17567. else
  17568. {
  17569. tempIndex = gun_index;
  17570. }
  17571. for (int index = 0; index < AC_QUANTITY; index++)
  17572. {
  17573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17574. {
  17575. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17576. }
  17577. } // END for AC_QUANTITY
  17578. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17579. }
  17580. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17581. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17582. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17583. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17586. }
  17587. //2.4====================================== Voltage L1 ====================================================
  17588. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17589. {
  17590. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17591. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17592. {
  17593. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17594. {
  17595. tempIndex = ((gun_index==2) ? 1: 0);
  17596. }
  17597. else
  17598. {
  17599. tempIndex = gun_index;
  17600. }
  17601. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17602. {
  17603. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17604. {
  17605. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17606. }
  17607. } // END OF FOR CHAdeMO_QUANTITY
  17608. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17609. }
  17610. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17611. {
  17612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17613. {
  17614. tempIndex = ((gun_index==2) ? 1: 0);
  17615. }
  17616. else
  17617. {
  17618. tempIndex = gun_index;
  17619. }
  17620. for (int index = 0; index < CCS_QUANTITY; index++)
  17621. {
  17622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17623. {
  17624. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17625. }
  17626. } // END OF FOR CCS_QUANTITY
  17627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17628. }
  17629. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17630. {
  17631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17632. {
  17633. tempIndex = ((gun_index==2) ? 1: 0);
  17634. }
  17635. else
  17636. {
  17637. tempIndex = gun_index;
  17638. }
  17639. for (int index = 0; index < GB_QUANTITY; index++)
  17640. {
  17641. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17642. {
  17643. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17644. }
  17645. } // END OF FOR GB_QUANTITY
  17646. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17647. }
  17648. else if(gunType[gun_index] == GUN_TYPE_DO)
  17649. {
  17650. tempIndex = gun_index;
  17651. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17652. {
  17653. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17654. {
  17655. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17656. }
  17657. }
  17658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17659. }
  17660. else
  17661. {
  17662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17663. {
  17664. tempIndex = 2;
  17665. }
  17666. else
  17667. {
  17668. tempIndex = gun_index;
  17669. }
  17670. for (int index = 0; index < AC_QUANTITY; index++)
  17671. {
  17672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17673. {
  17674. 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
  17675. }
  17676. } // END OF FOR AC_QUANTITY
  17677. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17678. }
  17679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17682. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17685. }
  17686. //2.5============================================== End SoC =========================================================
  17687. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17688. {
  17689. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17690. 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))
  17691. {
  17692. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17693. {
  17694. tempIndex = ((gun_index==2) ? 1: 0);
  17695. }
  17696. else
  17697. {
  17698. tempIndex = gun_index;
  17699. }
  17700. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17701. {
  17702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17703. {
  17704. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17705. {
  17706. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17707. }
  17708. }
  17709. }
  17710. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17711. {
  17712. for (int index = 0; index < CCS_QUANTITY; index++)
  17713. {
  17714. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17715. {
  17716. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17717. }
  17718. }
  17719. }
  17720. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17721. {
  17722. for (int index = 0; index < GB_QUANTITY; index++)
  17723. {
  17724. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17725. {
  17726. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17727. }
  17728. }
  17729. }
  17730. else if(gunType[gun_index] == GUN_TYPE_DO)
  17731. {
  17732. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17733. {
  17734. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17735. {
  17736. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17737. }
  17738. }
  17739. }
  17740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17742. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17744. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17746. } // END FOR DC CASE
  17747. }
  17748. //2.6====================================== Current.Import L2 ==============================================
  17749. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17750. {
  17751. // AC 3 phase L2 current
  17752. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17753. {
  17754. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17755. {
  17756. tempIndex = 2;
  17757. }
  17758. else
  17759. {
  17760. tempIndex = gun_index;
  17761. }
  17762. for (int index = 0; index < AC_QUANTITY; index++)
  17763. {
  17764. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17765. {
  17766. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17767. }
  17768. }// End of for AC_QUANTITY
  17769. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17770. }
  17771. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17772. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17773. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17774. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17775. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17776. }
  17777. //2.7====================================== Current.Import L3 ==============================================
  17778. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17779. {
  17780. // AC 3 phase L3 current
  17781. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17782. {
  17783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17784. {
  17785. tempIndex = 2;
  17786. }
  17787. else
  17788. {
  17789. tempIndex = gun_index;
  17790. }
  17791. for (int index = 0; index < AC_QUANTITY; index++)
  17792. {
  17793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17794. {
  17795. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17796. }
  17797. }// End of for AC_QUANTITY
  17798. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17799. }
  17800. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17805. }
  17806. //2.9====================================== Voltage L2 ====================================================
  17807. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17808. {
  17809. // AC 3 phase L2 volatge
  17810. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17811. {
  17812. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17813. {
  17814. tempIndex = 2;
  17815. }
  17816. else
  17817. {
  17818. tempIndex = gun_index;
  17819. }
  17820. for (int index = 0; index < AC_QUANTITY; index++)
  17821. {
  17822. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17823. {
  17824. 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
  17825. }
  17826. } // END OF FOR AC_QUANTITY
  17827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17828. }
  17829. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17830. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17831. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17832. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17833. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17834. }
  17835. //2.10====================================== Voltage L3 ====================================================
  17836. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17837. {
  17838. // AC 3 phase L3 volatge
  17839. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17840. {
  17841. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17842. {
  17843. tempIndex = 2;
  17844. }
  17845. else
  17846. {
  17847. tempIndex = gun_index;
  17848. }
  17849. for (int index = 0; index < AC_QUANTITY; index++)
  17850. {
  17851. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17852. {
  17853. 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
  17854. }
  17855. } // END OF FOR AC_QUANTITY
  17856. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17857. }
  17858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17859. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17860. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17861. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17862. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17863. }
  17864. //====================== Start SoC ================================
  17865. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17866. {
  17867. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17868. 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))
  17869. {
  17870. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17871. {
  17872. tempIndex = ((gun_index==2) ? 1: 0);
  17873. }
  17874. else
  17875. {
  17876. tempIndex = gun_index;
  17877. }
  17878. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17879. {
  17880. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17881. {
  17882. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17883. {
  17884. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17885. }
  17886. }
  17887. }
  17888. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17889. {
  17890. for (int index = 0; index < CCS_QUANTITY; index++)
  17891. {
  17892. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17893. {
  17894. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17895. }
  17896. }
  17897. }
  17898. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17899. {
  17900. for (int index = 0; index < GB_QUANTITY; index++)
  17901. {
  17902. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17903. {
  17904. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17905. }
  17906. }
  17907. }
  17908. else if(gunType[gun_index] == GUN_TYPE_DO)
  17909. {
  17910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17911. {
  17912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17913. {
  17914. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17915. }
  17916. }
  17917. }
  17918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17919. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17920. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17922. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17923. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17924. } // END FOR DC CASE
  17925. }
  17926. //======================================== Message create ==============================================
  17927. json_object *StopTransaction = json_object_new_object();
  17928. json_object *transactionDatas = json_object_new_array();
  17929. json_object *sampledValues = json_object_new_array();
  17930. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17931. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17932. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17933. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17934. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17935. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17936. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17937. {
  17938. json_object *transactionData = json_object_new_object();
  17939. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17940. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17941. {
  17942. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17943. {
  17944. json_object *sampledValue = json_object_new_object();
  17945. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17946. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17947. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17948. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17949. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17950. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17951. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17952. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17953. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17954. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17955. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17956. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17957. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17958. json_object_array_add(sampledValues, sampledValue);
  17959. }
  17960. }
  17961. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17962. json_object_array_add(transactionDatas, transactionData);
  17963. }
  17964. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17965. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17966. ,MESSAGE_TYPE_CALL
  17967. ,guid
  17968. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17969. json_object_put(StopTransaction);
  17970. // Check File "TempStopTransaction" Exist
  17971. if((access(TempStopTransaction,F_OK))!=-1)
  17972. {
  17973. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17974. fclose(fopen(TempStopTransaction, "w"));
  17975. }
  17976. else
  17977. {
  17978. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17979. FILE *log = fopen(TempStopTransaction, "w+");
  17980. if(log == NULL)
  17981. {
  17982. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17983. return ;
  17984. }
  17985. else
  17986. {
  17987. fclose(log);
  17988. }
  17989. }
  17990. //Add TempStopTransaction | Update TempStopTransaction
  17991. // open file for writing
  17992. FILE *outfile;
  17993. outfile = fopen (TempStopTransaction, "a");
  17994. //DEBUG_INFO("data = %s\n", queuedata);
  17995. fputs(queuedata, outfile);
  17996. fputs("\n", outfile);
  17997. fclose (outfile);
  17998. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17999. }
  18000. void checkTempStopTransaction(int gun_index)
  18001. {
  18002. FILE *fptr1;
  18003. char ch;
  18004. char str[QUEUE_MESSAGE_LENGTH]={0};
  18005. char guid[37]={0};
  18006. char tempdata[65]={0};
  18007. char connectorStr[2]={0};
  18008. char TempStopTransaction[256];
  18009. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18010. fptr1 = fopen(TempStopTransaction, "r");
  18011. //TempStopTransaction格式: 槍號,StopTransaction封包
  18012. if (!fptr1)
  18013. {
  18014. //printf(" File not found or unable to open the input file!!\n");
  18015. return ;
  18016. }
  18017. ch=fgetc(fptr1);
  18018. //printf(" Now the content of the file %s is : \n",fname);
  18019. rewind(fptr1);
  18020. if(ch!=EOF)
  18021. {
  18022. // copy all contents to the temporary file except the specific line
  18023. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18024. {
  18025. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18026. if(str[0]=='\0')
  18027. {
  18028. break;
  18029. }
  18030. //TempStopTransaction格式: 槍號,StopTransaction封包
  18031. strncpy(connectorStr, str, 1);
  18032. if(atoi(connectorStr) != (gun_index+1))
  18033. {
  18034. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18035. fclose(fptr1);
  18036. return ;
  18037. }
  18038. //random_uuid(guid);
  18039. strncpy(guid, str+6, 36); //copy guid
  18040. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18041. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18042. {
  18043. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18044. }
  18045. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18046. OCPP_insert_transaction_msg(NO, str);
  18047. memset(str,0,ARRAY_SIZE(str));
  18048. }
  18049. }
  18050. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18051. fclose(fptr1);
  18052. remove(TempStopTransaction); // remove the original file
  18053. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18054. }
  18055. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18056. {
  18057. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18058. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18059. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18060. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18061. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18062. }
  18063. int GetWebSocketPingInterval(void)
  18064. {
  18065. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18066. }
  18067. int GetServerSign(void)
  18068. {
  18069. return server_sign;
  18070. }
  18071. uint8_t GetOcppSecurityProfile()
  18072. {
  18073. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18074. }
  18075. void GetOcppChargerBoxId(uint8_t *data)
  18076. {
  18077. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18078. }
  18079. void GetOcppSecurityPassword(uint8_t *data)
  18080. {
  18081. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18082. }
  18083. void SetOcppVersion(uint8_t *version)
  18084. {
  18085. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18086. DEBUG_INFO("ocpp version: %s\n", version);
  18087. if(strstr((char*)version, "ocpp1.6") != NULL)
  18088. {
  18089. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18090. }
  18091. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18092. {
  18093. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18094. system("pkill OcppBackend");
  18095. }
  18096. }
  18097. void SetServerSign(int value)
  18098. {
  18099. server_sign = value;
  18100. }
  18101. int GetBootNotificationInterval(void)
  18102. {
  18103. return BootNotificationInterval;
  18104. }
  18105. int GetInternetConn(void)
  18106. {
  18107. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18108. }
  18109. int GetBackendConnectionTimeout(void)
  18110. {
  18111. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18112. }
  18113. int isConnectorInitMode(int gun_index)
  18114. {
  18115. int tempIndex = 0;
  18116. int result = TRUE;
  18117. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18118. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18119. {
  18120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18121. {
  18122. tempIndex = ((gun_index==2) ? 1: 0);
  18123. }
  18124. else
  18125. {
  18126. tempIndex = gun_index;
  18127. }
  18128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18129. {
  18130. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18131. {
  18132. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18133. } //end of the same index
  18134. }//end of for CHAdeMO_QUANTITY
  18135. }
  18136. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18137. {
  18138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18139. {
  18140. tempIndex = ((gun_index==2) ? 1: 0);
  18141. }
  18142. else
  18143. {
  18144. tempIndex = gun_index;
  18145. }
  18146. for (int index = 0; index < CCS_QUANTITY; index++)
  18147. {
  18148. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18149. {
  18150. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18151. } //end of the same index
  18152. } // end of for CCS_QUANTITY
  18153. }
  18154. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18155. {
  18156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18157. {
  18158. tempIndex = ((gun_index==2) ? 1: 0);
  18159. }
  18160. else
  18161. {
  18162. tempIndex = gun_index;
  18163. }
  18164. for (int index = 0; index < GB_QUANTITY; index++)
  18165. {
  18166. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18167. {
  18168. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18169. } //end of the same index
  18170. } // end of for GB_QUANTITY
  18171. }
  18172. else if(gunType[gun_index] == GUN_TYPE_DO)
  18173. {
  18174. tempIndex = gun_index;
  18175. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18176. {
  18177. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18178. {
  18179. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18180. } //end of the same index
  18181. }
  18182. }
  18183. else
  18184. {
  18185. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18186. {
  18187. tempIndex = 2;
  18188. }
  18189. else
  18190. {
  18191. tempIndex = gun_index;
  18192. }
  18193. for (int index = 0; index < AC_QUANTITY; index++)
  18194. {
  18195. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18196. {
  18197. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18198. }//end of the same index
  18199. }//end of for AC_QUANTITY
  18200. }
  18201. return result;
  18202. }
  18203. void refreshProcDogTimer()
  18204. {
  18205. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18206. }
  18207. void InitialSystemValue(void)
  18208. {
  18209. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18210. locallistVersion=0;
  18211. BootNotificationInterval = 0;
  18212. authorizeRetryTimes = 0;
  18213. GunStatusInterval = 10;
  18214. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18215. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18216. //Hear Beat
  18217. HeartBeatWithNOResponse = 0;
  18218. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18219. FirstHeartBeat = 0;
  18220. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18221. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18222. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18223. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18224. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18225. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18226. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18227. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18228. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18229. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18230. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18231. //Status && ConnectorPlugIn Setting
  18232. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18233. {
  18234. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18235. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18236. }
  18237. for (int index = 0; index < CCS_QUANTITY; index++)
  18238. {
  18239. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18240. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18241. }
  18242. for (int index = 0; index < GB_QUANTITY; index++)
  18243. {
  18244. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18245. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18246. }
  18247. for (int index = 0; index < AC_QUANTITY; index++)
  18248. {
  18249. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18250. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18251. }
  18252. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18253. {
  18254. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18255. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18256. }
  18257. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18258. {
  18259. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18260. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18261. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18262. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18263. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18264. }
  18265. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18266. refreshStartTimer(&clientTime.Heartbeat);
  18267. sleep(1);
  18268. }
  18269. void LWS_Send(char *str)
  18270. {
  18271. //=====================================================
  18272. // Check InternetConn 0: disconnected, 1: connected
  18273. //====================================================
  18274. if(GetOcppConnStatus() == 0)
  18275. {
  18276. DEBUG_INFO("offline now !!!\n");
  18277. return;
  18278. }
  18279. // Only disable isWebsocketSendable operation initiated by charger
  18280. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18281. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18282. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18283. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18284. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18285. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18286. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18287. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18288. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18289. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18290. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18291. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18292. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18293. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18294. {
  18295. isWebsocketSendable = 0;
  18296. }
  18297. pthread_mutex_lock(&lock_send);
  18298. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18299. sprintf((char *)SendBuffer, "%s", str);
  18300. SendBufLen = strlen(str);
  18301. pthread_mutex_unlock(&lock_send);
  18302. lws_callback_on_writable(wsi_client);
  18303. //lws_service(context, 0);
  18304. //sleep(1);
  18305. }
  18306. void LWS_SendNow(char *str)
  18307. {
  18308. //=====================================================
  18309. // Check InternetConn 0: disconnected, 1: connected
  18310. //====================================================
  18311. if(GetOcppConnStatus() == 0)
  18312. {
  18313. DEBUG_INFO("offline now !!!\n");
  18314. return;
  18315. }
  18316. // Only disable isWebsocketSendable operation initiated by charger
  18317. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18318. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18319. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18320. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18321. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18322. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18323. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18324. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18325. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18326. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18327. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18328. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18329. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18330. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18331. {
  18332. isWebsocketSendable = 0;
  18333. }
  18334. pthread_mutex_lock(&lock_send);
  18335. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18336. sprintf((char *)SendBuffer, "%s", str);
  18337. SendBufLen = strlen(str);
  18338. pthread_mutex_unlock(&lock_send);
  18339. lws_callback_on_writable(wsi_client);
  18340. lws_service(context, 0);
  18341. //sleep(1);
  18342. }