MessageHandler.c 770 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknownkey
  21. //===============================
  22. static char unknownkey[10][20] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int localversion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //=========================================
  354. // Save configuration
  355. //=========================================
  356. int runShellCmd(const char*cmd)
  357. {
  358. int result = FAIL;
  359. char buf[256];
  360. FILE *fp;
  361. fp = popen(cmd, "r");
  362. if(fp != NULL)
  363. {
  364. while(fgets(buf, sizeof(buf), fp) != NULL)
  365. {
  366. DEBUG_INFO("%s\n", buf);
  367. }
  368. result = PASS;
  369. }
  370. pclose(fp);
  371. return result;
  372. }
  373. int StoreUsrConfigData(struct SysConfigData *UsrData)
  374. {
  375. int result = PASS;
  376. int fd,wrd;
  377. unsigned int i,Chk;
  378. unsigned char *ptr, *BufTmp;
  379. int MtdBlockSize = 0x300000;
  380. Chk=0;
  381. ptr=(unsigned char *)UsrData;
  382. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  383. {
  384. memset(BufTmp,0,MtdBlockSize);
  385. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  386. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  387. Chk+=*(BufTmp+i);
  388. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  389. // Output configuration to file.
  390. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  391. if (fd < 0)
  392. {
  393. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  394. free(BufTmp);
  395. return 0;
  396. }
  397. wrd=write(fd, BufTmp, MtdBlockSize);
  398. close(fd);
  399. if(wrd<MtdBlockSize)
  400. {
  401. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  402. free(BufTmp);
  403. return 0;
  404. }
  405. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  406. DEBUG_INFO("Erase /dev/mtd10.\n");
  407. runShellCmd("flash_erase /dev/mtd10 0 0");
  408. DEBUG_INFO("Write /dev/mtd10.\n");
  409. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  410. DEBUG_INFO("Erase /dev/mtd11.\n");
  411. runShellCmd("flash_erase /dev/mtd11 0 0");
  412. DEBUG_INFO("Write /dev/mtd11.\n");
  413. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  414. system("rm -f /mnt/EvseConfig.bin");
  415. DEBUG_INFO("EvseConfig write to flash OK\n");
  416. }
  417. else
  418. {
  419. DEBUG_ERROR("alloc BlockSize NG\r\n");
  420. result = FAIL;
  421. }
  422. if(BufTmp!=NULL)
  423. free(BufTmp);
  424. return result;
  425. }
  426. //=========================================
  427. // Sqlite3 related function
  428. //=========================================
  429. static int selectSqlCount = 0;
  430. static int callback(void *data, int argc, char **argv, char **azColName){
  431. int i;
  432. //printf("%s: ", (const char*)data);
  433. selectSqlCount = argc;
  434. for(i = 0; i<argc; i++){
  435. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  436. }
  437. //printf("\n");
  438. return 0;
  439. }
  440. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  441. //int i;
  442. //printf("%s:\n", (const char*)data);
  443. localversion = argv[5] ? atoi(argv[5]) : 0;
  444. //printf("localversion=%d\n", localversion);
  445. return 0;
  446. }
  447. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  448. //printf("%s:\n", (const char*)data);
  449. //idTag
  450. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  451. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  452. //parentIdTag
  453. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  454. //expir_date
  455. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  456. //status
  457. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  458. //version
  459. if(columenCount > 5)
  460. idTagQuery.listVersionInt = atoi(columnValue[5]);
  461. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  462. return 0;
  463. }
  464. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  465. {
  466. // localversion = argv[5] ? atoi(argv[5]) : 0;
  467. // printf("localversion=%d\n", localversion);
  468. return 0;
  469. }
  470. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  471. {
  472. for (int i = 0; i < n_columns; i++)
  473. {
  474. DEBUG_INFO("%s\t", col_values[i]);
  475. }
  476. DEBUG_INFO("\n");
  477. return 0;
  478. }
  479. int OCPP_cleanLocalCache()
  480. {
  481. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  482. char *errMsg = 0;
  483. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  484. if (SQLITE_OK != rc)
  485. {
  486. DEBUG_INFO("SQL error: %s\n",errMsg);
  487. return FALSE;
  488. }
  489. return TRUE;
  490. }
  491. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  492. {
  493. int isSuccess = TRUE;
  494. int ret = 0;
  495. //const char* data = "Callback function called";
  496. char sql[300];
  497. char zErrMsg[200];
  498. memset(sql, 0, 300);
  499. memset(zErrMsg, 0, 200);
  500. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  501. //* Execute SQL statement */
  502. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  503. if( ret != SQLITE_OK )
  504. {
  505. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  506. isSuccess = FALSE;
  507. }
  508. return isSuccess;
  509. }
  510. void OCPP_getIdTagFromLocalCache(char idTag[])
  511. {
  512. int rc = 0;
  513. char sql[100];
  514. char zErrMsg[100];
  515. memset(sql, 0, 100);
  516. memset(zErrMsg, 0, 100);
  517. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  518. memset(&idTagQuery, 0, sizeof(idTagQuery));
  519. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  520. /* Execute SQL statement */
  521. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  522. if( rc != SQLITE_OK )
  523. {
  524. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  525. }
  526. }
  527. void OCPP_getListVerion()
  528. {
  529. int rc = 0;
  530. // const char* data = "Callback function called";
  531. char sql[100];
  532. char zErrMsg[100];
  533. memset(sql, 0, 100);
  534. memset(zErrMsg, 0, 100);
  535. strcpy(sql, "select * from ocpp_auth_local order by idx");
  536. /* Execute SQL statement */
  537. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  538. if( rc != SQLITE_OK )
  539. {
  540. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  541. }
  542. }
  543. void OCPP_get_TableAuthlocalAllData(void)
  544. {
  545. int rc = 0;
  546. char sql[100];
  547. char zErrMsg[100];
  548. memset(sql, 0, 100);
  549. memset(zErrMsg, 0, 100);
  550. sprintf(sql,"select * from ocpp_auth_local ");
  551. /* Execute SQL statement */
  552. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  553. if( rc != SQLITE_OK )
  554. {
  555. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  556. }
  557. //return ver;
  558. }
  559. int OCPP_cleanLocalList()
  560. {
  561. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  562. char *errMsg = 0;
  563. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  564. if (SQLITE_OK != rc)
  565. {
  566. DEBUG_INFO("%s\n",errMsg);
  567. return FALSE;
  568. }
  569. return TRUE;
  570. }
  571. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  572. {
  573. int isSuccess = FALSE;
  574. int ret = 0;
  575. //const char* data = "Callback function called";
  576. char sql[300];
  577. char zErrMsg[200];
  578. memset(sql, 0, 300);
  579. memset(zErrMsg, 0, 200);
  580. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  581. //* Execute SQL statement */
  582. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  583. if( ret != SQLITE_OK )
  584. {
  585. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  586. return isSuccess;
  587. }
  588. memset(sql, 0, 300);
  589. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  590. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  591. if( ret != SQLITE_OK )
  592. {
  593. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  594. return isSuccess;
  595. }
  596. isSuccess = TRUE;
  597. return isSuccess;
  598. }
  599. void OCPP_getIdTagFromLocalList(char idTag[])
  600. {
  601. int rc = 0;
  602. // const char* data = "Callback function called";
  603. char sql[100];
  604. char zErrMsg[100];
  605. memset(sql, 0, 100);
  606. memset(zErrMsg, 0, 100);
  607. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  608. memset(&idTagQuery, 0, sizeof(idTagQuery));
  609. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  610. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  611. /* Execute SQL statement */
  612. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  613. if( rc != SQLITE_OK )
  614. {
  615. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  616. }
  617. //return ver;
  618. }
  619. void OCPP_deleteIdTagFromLocalList(char idTag[])
  620. {
  621. //int ver = 0;
  622. //int isSuccess = FALSE;
  623. int rc = 0;
  624. char sql[100];
  625. char zErrMsg[100];
  626. memset(sql, 0, 100);
  627. memset(zErrMsg, 0, 100);
  628. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  629. //* Execute SQL statement */
  630. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  631. if( rc != SQLITE_OK )
  632. {
  633. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  634. }
  635. }
  636. int getCurrentYear()
  637. {
  638. int result = 0;
  639. time_t CurrentTime;
  640. struct tm *tm;
  641. CurrentTime = time(NULL);
  642. tm=localtime(&CurrentTime);
  643. result = (tm->tm_year + 1900);
  644. return result;
  645. }
  646. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  647. {
  648. int result = PASS;
  649. char* errMsg = NULL;
  650. char sqlStr[8192];
  651. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  652. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  653. {
  654. result = FAIL;
  655. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  656. }
  657. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  658. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  659. {
  660. result = FAIL;
  661. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  662. }
  663. return result;
  664. }
  665. //==========================================
  666. // Check time passed since today
  667. //==========================================
  668. long long DiffTimebWithNow(struct timeb ST)
  669. {
  670. //return milli-second
  671. struct timeb ET;
  672. long long StartTime,StopTime;
  673. ftime(&ET);
  674. StartTime=(long long)ST.time;
  675. StopTime=(long long)ET.time;
  676. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  677. }
  678. int getTimePassSinceToday()
  679. {
  680. int result = -1;
  681. static time_t lastTime;
  682. time_t t;
  683. struct tm *tmStartToday;
  684. struct timeb tbStartToday;
  685. t=time(NULL);
  686. if(difftime(t, lastTime)>0)
  687. {
  688. tmStartToday=localtime(&t);
  689. tmStartToday->tm_hour = 0;
  690. tmStartToday->tm_min = 0;
  691. tmStartToday->tm_sec = 0;
  692. tbStartToday.time = mktime(tmStartToday);
  693. tbStartToday.millitm = 0;
  694. result = DiffTimebWithNow(tbStartToday)/1000;
  695. lastTime = t;
  696. }
  697. return result;
  698. }
  699. void getNowDatetime(uint8_t *data)
  700. {
  701. time_t t = time(NULL);
  702. struct tm tm = *localtime(&t);
  703. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  704. }
  705. int syncDateTimeRTC(uint8_t *data)
  706. {
  707. struct ParsingResult
  708. {
  709. int result;
  710. int scanedElement;
  711. int year;
  712. int month;
  713. int mday;
  714. int hour;
  715. int min;
  716. int sec;
  717. int tz_hour;
  718. int tz_min;
  719. float minSec;
  720. }result;
  721. struct tm tmOrg;
  722. struct tm *tmTarget;
  723. struct timeb tbTarget;
  724. char buf[128];
  725. memset(&result, 0x00, sizeof(struct ParsingResult));
  726. result.result = PASS;
  727. if(strstr((char*)data, ".") != NULL)
  728. {
  729. // Original data with mini second
  730. if(strstr((char*)data, "Z") != NULL)
  731. {
  732. // Original data with Z
  733. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  734. &result.year,
  735. &result.month,
  736. &result.mday,
  737. &result.hour,
  738. &result.min,
  739. &result.sec,
  740. &result.minSec);
  741. }
  742. else
  743. {
  744. // Original data without Z
  745. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  746. &result.year,
  747. &result.month,
  748. &result.mday,
  749. &result.hour,
  750. &result.min,
  751. &result.sec,
  752. &result.minSec,
  753. &result.tz_hour,
  754. &result.tz_min);
  755. }
  756. }
  757. else
  758. {
  759. // Original data without mini second
  760. if(strstr((char*)data, "Z") != NULL)
  761. {
  762. // Original data with Z
  763. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  764. &result.year,
  765. &result.month,
  766. &result.mday,
  767. &result.hour,
  768. &result.min,
  769. &result.sec);
  770. }
  771. else
  772. {
  773. // Original data without Z
  774. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  775. &result.year,
  776. &result.month,
  777. &result.mday,
  778. &result.hour,
  779. &result.min,
  780. &result.sec,
  781. &result.tz_hour,
  782. &result.tz_min);
  783. }
  784. }
  785. tmOrg.tm_year = result.year - 1900;
  786. tmOrg.tm_mon = result.month - 1;
  787. tmOrg.tm_mday = result.mday;
  788. tmOrg.tm_hour = result.hour;
  789. tmOrg.tm_min = result.min;
  790. tmOrg.tm_sec = result.sec;
  791. tmOrg.tm_gmtoff = 0;
  792. tbTarget.time = mktime(&tmOrg);
  793. tbTarget.timezone = 0;
  794. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  795. tmTarget = gmtime(&tbTarget.time);
  796. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  797. //DEBUG_INFO(" org date time: %s\n", data);
  798. //DEBUG_INFO("parse date time: %s\n", buf);
  799. system(buf);
  800. system("/sbin/hwclock -w --systohc");
  801. if(result.scanedElement < 6)
  802. result.result = FAIL;
  803. return result.result;
  804. }
  805. //==========================================
  806. // GetCompositeSchedule logic related function
  807. //==========================================
  808. int DiffTimebSec(struct timeb ST, struct timeb ET)
  809. {
  810. //return milli-second
  811. unsigned int StartTime,StopTime;
  812. StartTime=(unsigned int)ST.time;
  813. StopTime=(unsigned int)ET.time;
  814. return (StopTime-StartTime);
  815. }
  816. int DiffTimebWithNowSec(struct timeb ST)
  817. {
  818. //return milli-second
  819. struct timeb ET;
  820. unsigned int StartTime,StopTime;
  821. ftime(&ET);
  822. StartTime=(unsigned int)ST.time;
  823. StopTime=(unsigned int)ET.time;
  824. return (StopTime-StartTime);
  825. }
  826. int getStartStop(uint8_t *start, uint8_t *stop)
  827. {
  828. int result = -1;
  829. struct tm tmStart;
  830. struct timeb tbStart;
  831. struct tm tmStop;
  832. struct timeb tbStop;
  833. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  834. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  835. {
  836. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  837. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  838. tmStart.tm_year -= 1900;
  839. tmStart.tm_mon -= 1;
  840. tbStart.time = mktime(&tmStart);
  841. tbStart.millitm = 0;
  842. tmStop.tm_year -= 1900;
  843. tmStop.tm_mon -= 1;
  844. tbStop.time = mktime(&tmStop);
  845. tbStop.millitm = 0;
  846. result = DiffTimebSec(tbStart, tbStop);
  847. //DEBUG_INFO("getStartStop(): %d\n", result);
  848. }
  849. else
  850. {
  851. DEBUG_WARN("Start or stop date parsing error.\r\n");
  852. }
  853. return result;
  854. }
  855. int isOvertNow(uint8_t *start)
  856. {
  857. int result = NO;
  858. struct tm tmStart;
  859. struct timeb tbStart;
  860. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  861. {
  862. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  863. tmStart.tm_year -= 1900;
  864. tmStart.tm_mon -= 1;
  865. tbStart.time = mktime(&tmStart);
  866. tbStart.millitm = 0;
  867. if(DiffTimebWithNowSec(tbStart) <= 0)
  868. result = NO;
  869. else
  870. result = YES;
  871. }
  872. else
  873. {
  874. DEBUG_WARN("Start date parsing error.\n");
  875. }
  876. return result;
  877. }
  878. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  879. {
  880. int result = -1;
  881. struct tm tmStart;
  882. struct timeb tbStart;
  883. struct tm tmStop;
  884. struct timeb tbStop;
  885. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  886. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  887. {
  888. tmStart.tm_year -= 1900;
  889. tmStart.tm_mon -= 1;
  890. tbStart.time = mktime(&tmStart);
  891. tbStart.millitm = 0;
  892. tmStop.tm_year -= 1900;
  893. tmStop.tm_mon -= 1;
  894. tbStop.time = mktime(&tmStop);
  895. tbStop.millitm = 0;
  896. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  897. }
  898. return result;
  899. }
  900. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  901. {
  902. FILE *fp;
  903. char profileFileName[128];
  904. char *line = NULL;
  905. size_t len = 0;
  906. time_t CurrentTime;
  907. struct tm *tmComposite;
  908. struct StructChargingProfile maxProfile;
  909. struct StructChargingProfile defaultTxProfile;
  910. struct StructChargingProfile txProfile;
  911. struct StructChargingSchedulePeriod tmpPeriod;
  912. uint8_t limitMax=0;
  913. uint8_t limitDef=0;
  914. uint8_t limitTx=0;
  915. int compositePeriodIdx = 0;
  916. CurrentTime = time(NULL);
  917. tmComposite=localtime(&CurrentTime);
  918. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  919. if(isUnitA)
  920. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  921. else
  922. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  923. compositeProfile->ChargingSchedule.Duration = durationReq;
  924. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  925. {
  926. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  928. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  929. }
  930. compositeProfile->ChargingProfileId = 0;
  931. compositeProfile->StackLevel = 99 ;
  932. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  933. maxProfile.ChargingProfileId = -1;
  934. defaultTxProfile.ChargingProfileId = -1;
  935. txProfile.ChargingProfileId = -1;
  936. maxProfile.ChargingSchedule.Duration = -1;
  937. defaultTxProfile.ChargingSchedule.Duration = -1;
  938. txProfile.ChargingSchedule.Duration = -1;
  939. system("rm -f /tmp/*.json");
  940. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  941. /*
  942. * Search valid charging profile
  943. */
  944. //DEBUG_INFO("====================================\n");
  945. // Search tx profile
  946. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  947. if((access(profileFileName, F_OK))!=-1)
  948. {
  949. fp = fopen(profileFileName, "r");
  950. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  951. {
  952. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  953. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  954. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  955. }
  956. txProfile.ChargingProfileId = -1;
  957. txProfile.StackLevel = -1;
  958. while(getline(&line, &len, fp) != -1)
  959. {
  960. json_object *obj = NULL;
  961. obj = json_tokener_parse(line);
  962. if(is_error(obj))
  963. {
  964. DEBUG_ERROR("Parse txProfile from file error.\n");
  965. }
  966. else
  967. {
  968. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  969. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  970. )
  971. {
  972. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  973. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  974. )
  975. {
  976. struct tm tmFrom, tmTo;
  977. struct timeb tbFrom, tbTo;
  978. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  979. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  980. {
  981. tmFrom.tm_year -= 1900;
  982. tmFrom.tm_mon -= 1;
  983. tbFrom.time = mktime(&tmFrom);
  984. tmTo.tm_year -= 1900;
  985. tmTo.tm_mon -= 1;
  986. tbTo.time = mktime(&tmTo);
  987. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  988. {
  989. if(txProfile.ChargingProfileId == -1)
  990. DEBUG_INFO("TxProfile found.\n");
  991. else
  992. DEBUG_INFO("TxProfile updated.\n");
  993. // Required item
  994. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  995. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  996. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  997. if(isUnitA)
  998. {
  999. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1000. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1001. {
  1002. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1003. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1004. 3:
  1005. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1006. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1007. }
  1008. }
  1009. else
  1010. {
  1011. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1012. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1013. {
  1014. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1015. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1016. 3:
  1017. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1018. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1019. }
  1020. }
  1021. // Optional item
  1022. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1023. {
  1024. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1025. }
  1026. else
  1027. {
  1028. sprintf((char*)txProfile.ValidFrom, " ");
  1029. }
  1030. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1031. {
  1032. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1033. }
  1034. else
  1035. {
  1036. sprintf((char*)txProfile.ValidTo, " ");
  1037. }
  1038. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1039. {
  1040. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1041. }
  1042. else
  1043. {
  1044. sprintf((char*)txProfile.RecurrencyKind, " ");
  1045. }
  1046. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1047. {
  1048. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1049. }
  1050. else
  1051. {
  1052. txProfile.TransactionId = -1;
  1053. }
  1054. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1055. {
  1056. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1057. }
  1058. else
  1059. {
  1060. txProfile.ChargingSchedule.Duration = 86400;
  1061. }
  1062. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1063. {
  1064. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1065. }
  1066. else
  1067. {
  1068. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1069. }
  1070. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1071. {
  1072. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1073. }
  1074. else
  1075. {
  1076. txProfile.ChargingSchedule.MinChargingRate = -1;
  1077. }
  1078. }
  1079. }
  1080. }
  1081. else
  1082. {
  1083. if(txProfile.ChargingProfileId == -1)
  1084. DEBUG_INFO("TxProfile found.\n");
  1085. else
  1086. DEBUG_INFO("TxProfile updated.\n");
  1087. // Required item
  1088. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1089. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1090. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1091. if(isUnitA)
  1092. {
  1093. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1094. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1095. {
  1096. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1097. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1098. 3:
  1099. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1100. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1101. }
  1102. }
  1103. else
  1104. {
  1105. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1106. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1107. {
  1108. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1109. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1110. 3:
  1111. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1112. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1113. }
  1114. }
  1115. // Optional item
  1116. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1117. {
  1118. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1119. }
  1120. else
  1121. {
  1122. sprintf((char*)txProfile.ValidFrom, " ");
  1123. }
  1124. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1125. {
  1126. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1127. }
  1128. else
  1129. {
  1130. sprintf((char*)txProfile.ValidTo, " ");
  1131. }
  1132. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1133. {
  1134. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1135. }
  1136. else
  1137. {
  1138. sprintf((char*)txProfile.RecurrencyKind, " ");
  1139. }
  1140. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1141. {
  1142. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1143. }
  1144. else
  1145. {
  1146. txProfile.TransactionId = -1;
  1147. }
  1148. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1149. {
  1150. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1151. }
  1152. else
  1153. {
  1154. txProfile.ChargingSchedule.Duration = 86400;
  1155. }
  1156. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1157. {
  1158. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1159. }
  1160. else
  1161. {
  1162. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1163. }
  1164. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1165. {
  1166. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1167. }
  1168. else
  1169. {
  1170. txProfile.ChargingSchedule.MinChargingRate = -1;
  1171. }
  1172. }
  1173. }
  1174. }
  1175. json_object_put(obj);
  1176. }
  1177. fclose(fp);
  1178. /*
  1179. if(txProfile.ChargingProfileId != -1)
  1180. {
  1181. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1182. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1183. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1184. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1185. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1186. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1187. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1188. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1189. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1190. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1191. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1192. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1193. {
  1194. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1195. {
  1196. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1197. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1198. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1199. }
  1200. }
  1201. }
  1202. else
  1203. DEBUG_INFO("TxProfile not found.\n");*/
  1204. }
  1205. // Search default tx profile
  1206. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1207. if((access(profileFileName, F_OK))==-1)
  1208. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1209. if((access(profileFileName, F_OK))!=-1)
  1210. {
  1211. fp = fopen(profileFileName, "r");
  1212. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1213. {
  1214. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1215. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1216. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1217. }
  1218. defaultTxProfile.ChargingProfileId = -1;
  1219. defaultTxProfile.StackLevel = -1;
  1220. while(getline(&line, &len, fp) != -1)
  1221. {
  1222. json_object *obj = NULL;
  1223. obj = json_tokener_parse(line);
  1224. if(is_error(obj))
  1225. {
  1226. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1227. }
  1228. else
  1229. {
  1230. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1231. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1232. )
  1233. {
  1234. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1235. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1236. )
  1237. {
  1238. struct tm tmFrom, tmTo;
  1239. struct timeb tbFrom, tbTo;
  1240. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1241. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1242. {
  1243. tmFrom.tm_year -= 1900;
  1244. tmFrom.tm_mon -= 1;
  1245. tbFrom.time = mktime(&tmFrom);
  1246. tmTo.tm_year -= 1900;
  1247. tmTo.tm_mon -= 1;
  1248. tbTo.time = mktime(&tmTo);
  1249. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1250. {
  1251. if(defaultTxProfile.ChargingProfileId == -1)
  1252. DEBUG_INFO("TxDefaultProfile found.\n");
  1253. else
  1254. DEBUG_INFO("TxDefaultProfile updated.\n");
  1255. // Required item
  1256. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1257. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1258. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1259. if(isUnitA)
  1260. {
  1261. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1262. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1263. {
  1264. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1265. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1266. 3:
  1267. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1268. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1269. }
  1270. }
  1271. else
  1272. {
  1273. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1274. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1275. {
  1276. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1277. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1278. 3:
  1279. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1280. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1281. }
  1282. }
  1283. // Optional item
  1284. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1285. {
  1286. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1287. }
  1288. else
  1289. {
  1290. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1291. }
  1292. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1293. {
  1294. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1295. }
  1296. else
  1297. {
  1298. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1299. }
  1300. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1301. {
  1302. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1303. }
  1304. else
  1305. {
  1306. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1307. }
  1308. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1309. {
  1310. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1311. }
  1312. else
  1313. {
  1314. defaultTxProfile.TransactionId = -1;
  1315. }
  1316. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1317. {
  1318. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1319. }
  1320. else
  1321. {
  1322. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1323. }
  1324. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1325. {
  1326. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1327. }
  1328. else
  1329. {
  1330. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1331. }
  1332. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1333. {
  1334. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1335. }
  1336. else
  1337. {
  1338. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1339. }
  1340. }
  1341. }
  1342. }
  1343. else
  1344. {
  1345. if(defaultTxProfile.ChargingProfileId == -1)
  1346. DEBUG_INFO("TxDefaultProfile found.\n");
  1347. else
  1348. DEBUG_INFO("TxDefaultProfile updated.\n");
  1349. // Required item
  1350. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1351. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1352. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1353. if(isUnitA)
  1354. {
  1355. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1356. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1357. {
  1358. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1359. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1360. 3:
  1361. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1362. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1363. }
  1364. }
  1365. else
  1366. {
  1367. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1368. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1369. {
  1370. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1371. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1372. 3:
  1373. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1374. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1375. }
  1376. }
  1377. // Optional item
  1378. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1379. {
  1380. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1381. }
  1382. else
  1383. {
  1384. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1385. }
  1386. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1387. {
  1388. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1389. }
  1390. else
  1391. {
  1392. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1393. }
  1394. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1395. {
  1396. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1397. }
  1398. else
  1399. {
  1400. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1401. }
  1402. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1403. {
  1404. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1405. }
  1406. else
  1407. {
  1408. defaultTxProfile.TransactionId = -1;
  1409. }
  1410. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1411. {
  1412. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1413. }
  1414. else
  1415. {
  1416. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1417. }
  1418. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1419. {
  1420. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1421. }
  1422. else
  1423. {
  1424. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1425. }
  1426. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1427. {
  1428. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1429. }
  1430. else
  1431. {
  1432. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1433. }
  1434. }
  1435. }
  1436. }
  1437. json_object_put(obj);
  1438. }
  1439. fclose(fp);
  1440. /*
  1441. if(defaultTxProfile.ChargingProfileId != -1)
  1442. {
  1443. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1444. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1445. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1446. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1447. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1448. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1449. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1450. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1451. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1452. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1453. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1454. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1455. {
  1456. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1457. {
  1458. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1459. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1460. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1461. }
  1462. }
  1463. }
  1464. else
  1465. DEBUG_INFO("TxDefaultProfile not found.\n");
  1466. DEBUG_INFO("------------------------------------\n");*/
  1467. }
  1468. // Search max profile
  1469. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1470. if((access(profileFileName, F_OK))!=-1)
  1471. {
  1472. fp = fopen(profileFileName, "r");
  1473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1474. {
  1475. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1476. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1478. }
  1479. maxProfile.ChargingProfileId = -1;
  1480. maxProfile.StackLevel = -1;
  1481. while(getline(&line, &len, fp) != -1)
  1482. {
  1483. json_object *obj = NULL;
  1484. obj = json_tokener_parse(line);
  1485. if(is_error(obj))
  1486. {
  1487. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1488. }
  1489. else
  1490. {
  1491. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1492. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1493. )
  1494. {
  1495. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1496. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1497. )
  1498. {
  1499. struct tm tmFrom, tmTo;
  1500. struct timeb tbFrom, tbTo;
  1501. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1502. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1503. {
  1504. tmFrom.tm_year -= 1900;
  1505. tmFrom.tm_mon -= 1;
  1506. tbFrom.time = mktime(&tmFrom);
  1507. tmTo.tm_year -= 1900;
  1508. tmTo.tm_mon -= 1;
  1509. tbTo.time = mktime(&tmTo);
  1510. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1511. {
  1512. if(maxProfile.ChargingProfileId == -1)
  1513. DEBUG_INFO("MaxProfile found.\n");
  1514. else
  1515. DEBUG_INFO("MaxProfile updated.\n");
  1516. // Required item
  1517. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1518. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1519. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1520. if(isUnitA)
  1521. {
  1522. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1523. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1524. {
  1525. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1526. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1527. 3:
  1528. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1529. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1530. }
  1531. }
  1532. else
  1533. {
  1534. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1535. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1536. {
  1537. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1538. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1539. 3:
  1540. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1541. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1542. }
  1543. }
  1544. // Optional item
  1545. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1546. {
  1547. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1548. }
  1549. else
  1550. {
  1551. sprintf((char*)maxProfile.ValidFrom, " ");
  1552. }
  1553. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1554. {
  1555. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1556. }
  1557. else
  1558. {
  1559. sprintf((char*)maxProfile.ValidTo, " ");
  1560. }
  1561. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1562. {
  1563. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1564. }
  1565. else
  1566. {
  1567. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1568. }
  1569. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1570. {
  1571. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1572. }
  1573. else
  1574. {
  1575. maxProfile.TransactionId = -1;
  1576. }
  1577. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1578. {
  1579. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1580. }
  1581. else
  1582. {
  1583. maxProfile.ChargingSchedule.Duration = 86400;
  1584. }
  1585. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1586. {
  1587. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1588. }
  1589. else
  1590. {
  1591. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1592. }
  1593. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1594. {
  1595. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1596. }
  1597. else
  1598. {
  1599. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1600. }
  1601. }
  1602. }
  1603. }
  1604. else
  1605. {
  1606. if(maxProfile.ChargingProfileId == -1)
  1607. DEBUG_INFO("MaxProfile found.\n");
  1608. else
  1609. DEBUG_INFO("MaxProfile updated.\n");
  1610. // Required item
  1611. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1612. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1613. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1614. if(isUnitA)
  1615. {
  1616. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1617. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1618. {
  1619. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1620. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1621. 3:
  1622. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1623. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1624. }
  1625. }
  1626. else
  1627. {
  1628. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1629. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1630. {
  1631. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1632. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1633. 3:
  1634. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1635. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1636. }
  1637. }
  1638. // Optional item
  1639. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1640. {
  1641. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1642. }
  1643. else
  1644. {
  1645. sprintf((char*)maxProfile.ValidFrom, " ");
  1646. }
  1647. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1648. {
  1649. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1650. }
  1651. else
  1652. {
  1653. sprintf((char*)maxProfile.ValidTo, " ");
  1654. }
  1655. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1656. {
  1657. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1658. }
  1659. else
  1660. {
  1661. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1662. }
  1663. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1664. {
  1665. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1666. }
  1667. else
  1668. {
  1669. maxProfile.TransactionId = -1;
  1670. }
  1671. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1672. {
  1673. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1674. }
  1675. else
  1676. {
  1677. maxProfile.ChargingSchedule.Duration = 86400;
  1678. }
  1679. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1680. {
  1681. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1682. }
  1683. else
  1684. {
  1685. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1686. }
  1687. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1688. {
  1689. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1690. }
  1691. else
  1692. {
  1693. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1694. }
  1695. }
  1696. }
  1697. }
  1698. json_object_put(obj);
  1699. }
  1700. fclose(fp);
  1701. /*
  1702. if(maxProfile.ChargingProfileId !=-1)
  1703. {
  1704. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1705. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1706. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1707. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1708. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1709. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1710. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1711. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1712. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1713. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1714. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1715. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1716. {
  1717. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1718. {
  1719. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1720. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1721. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1722. }
  1723. }
  1724. }
  1725. else
  1726. DEBUG_INFO("MaxProfile not found.\n");
  1727. DEBUG_INFO("------------------------------------\n");*/
  1728. }
  1729. /*
  1730. * Align found profile start schedule & periods
  1731. */
  1732. //DEBUG_INFO("====================================\n");
  1733. /*
  1734. // For local test usage, force modify found profile start schedule info
  1735. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1736. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1737. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1738. */
  1739. if(txProfile.ChargingProfileId != -1)
  1740. {
  1741. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1742. {
  1743. if(txProfile.ChargingSchedule.Duration != -1)
  1744. {
  1745. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1746. 0:
  1747. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1748. }
  1749. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1750. {
  1751. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1752. {
  1753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1754. 0:
  1755. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1756. if(idxPeriod > 0)
  1757. {
  1758. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1759. {
  1760. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1767. {
  1768. if(txProfile.ChargingSchedule.Duration != -1)
  1769. {
  1770. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1771. 0:
  1772. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1773. }
  1774. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1775. {
  1776. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1777. {
  1778. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1779. 0:
  1780. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1781. if(idxPeriod > 0)
  1782. {
  1783. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1784. {
  1785. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1786. }
  1787. }
  1788. }
  1789. }
  1790. }
  1791. else
  1792. {
  1793. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1794. {
  1795. if(txProfile.ChargingSchedule.Duration != -1)
  1796. {
  1797. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1798. 0:
  1799. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1800. }
  1801. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1802. {
  1803. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1804. {
  1805. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1806. 0:
  1807. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1808. if(idxPeriod > 0)
  1809. {
  1810. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1811. {
  1812. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1813. }
  1814. }
  1815. }
  1816. }
  1817. }
  1818. else
  1819. {
  1820. if(txProfile.ChargingSchedule.Duration != -1)
  1821. {
  1822. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1823. 0:
  1824. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1825. }
  1826. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1827. {
  1828. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1829. {
  1830. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1831. 0:
  1832. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1833. if(idxPeriod > 0)
  1834. {
  1835. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1836. {
  1837. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1838. }
  1839. }
  1840. }
  1841. }
  1842. }
  1843. }
  1844. /*
  1845. DEBUG_INFO("txProfile after align.\n");
  1846. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1847. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1848. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1849. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1850. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1851. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1852. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1853. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1854. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1855. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1856. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1857. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1858. {
  1859. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1860. {
  1861. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1862. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1863. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1864. }
  1865. }*/
  1866. }
  1867. if(defaultTxProfile.ChargingProfileId != -1)
  1868. {
  1869. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1870. {
  1871. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1872. {
  1873. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1874. 0:
  1875. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1876. }
  1877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1878. {
  1879. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1880. {
  1881. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1882. 0:
  1883. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1884. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1885. {
  1886. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1887. }
  1888. if(idxPeriod > 0)
  1889. {
  1890. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1891. {
  1892. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1893. }
  1894. }
  1895. }
  1896. }
  1897. }
  1898. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1899. {
  1900. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1901. {
  1902. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1903. 0:
  1904. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1905. }
  1906. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1907. {
  1908. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1909. {
  1910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1911. 0:
  1912. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1913. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1914. {
  1915. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1916. }
  1917. if(idxPeriod > 0)
  1918. {
  1919. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1920. {
  1921. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1922. }
  1923. }
  1924. }
  1925. }
  1926. }
  1927. else
  1928. {
  1929. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1930. {
  1931. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1932. {
  1933. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1934. 0:
  1935. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1936. }
  1937. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1938. {
  1939. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1940. {
  1941. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1942. 0:
  1943. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1944. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1945. {
  1946. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1947. }
  1948. if(idxPeriod > 0)
  1949. {
  1950. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1951. {
  1952. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1953. }
  1954. }
  1955. }
  1956. }
  1957. }
  1958. else
  1959. {
  1960. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1961. {
  1962. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1963. 0:
  1964. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1965. }
  1966. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1967. {
  1968. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1969. {
  1970. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1971. 0:
  1972. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1973. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1974. {
  1975. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1976. }
  1977. if(idxPeriod > 0)
  1978. {
  1979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1980. {
  1981. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1982. }
  1983. }
  1984. }
  1985. }
  1986. }
  1987. }
  1988. /*
  1989. DEBUG_INFO("defaultTxProfile after align.\n");
  1990. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1991. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1992. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1993. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1994. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1995. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1996. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1997. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1998. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1999. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2000. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2002. {
  2003. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2004. {
  2005. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2006. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2007. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2008. }
  2009. }
  2010. DEBUG_INFO("------------------------------------\n");*/
  2011. }
  2012. if(maxProfile.ChargingProfileId != -1)
  2013. {
  2014. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2015. {
  2016. if(maxProfile.ChargingSchedule.Duration != -1)
  2017. {
  2018. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2019. 0:
  2020. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2021. }
  2022. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2023. {
  2024. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2025. {
  2026. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2027. 0:
  2028. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2029. if(idxPeriod > 0)
  2030. {
  2031. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2032. {
  2033. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2034. }
  2035. }
  2036. }
  2037. }
  2038. }
  2039. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2040. {
  2041. if(maxProfile.ChargingSchedule.Duration != -1)
  2042. {
  2043. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2044. 0:
  2045. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2046. }
  2047. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2048. {
  2049. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2050. {
  2051. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2052. 0:
  2053. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2054. if(idxPeriod > 0)
  2055. {
  2056. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2057. {
  2058. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. else
  2065. {
  2066. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2067. {
  2068. if(maxProfile.ChargingSchedule.Duration != -1)
  2069. {
  2070. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2071. 0:
  2072. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2073. }
  2074. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2075. {
  2076. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2077. {
  2078. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2079. 0:
  2080. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2081. if(idxPeriod > 0)
  2082. {
  2083. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2084. {
  2085. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2086. }
  2087. }
  2088. }
  2089. }
  2090. }
  2091. else
  2092. {
  2093. if(maxProfile.ChargingSchedule.Duration != -1)
  2094. {
  2095. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2096. 0:
  2097. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2098. }
  2099. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2100. {
  2101. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2102. {
  2103. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2104. 0:
  2105. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2106. if(idxPeriod > 0)
  2107. {
  2108. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2109. {
  2110. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2111. }
  2112. }
  2113. }
  2114. }
  2115. }
  2116. }
  2117. /*
  2118. DEBUG_INFO("MaxProfile after align.\n");
  2119. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2120. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2121. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2122. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2123. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2124. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2125. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2126. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2127. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2128. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2129. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2130. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2131. {
  2132. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2133. {
  2134. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2135. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2136. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2137. }
  2138. }
  2139. DEBUG_INFO("------------------------------------\n");*/
  2140. }
  2141. /*
  2142. * Merge to conposite schedule
  2143. */
  2144. //DEBUG_INFO("====================================\n");
  2145. // Find each profile period quantity
  2146. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2147. {
  2148. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2149. limitMax = idx+1;
  2150. }
  2151. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2152. {
  2153. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2154. limitDef = idx+1;
  2155. }
  2156. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2157. {
  2158. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2159. limitTx = idx+1;
  2160. }
  2161. // TxProfile found, composite schedule based on it
  2162. if(txProfile.ChargingProfileId != -1)
  2163. {
  2164. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2165. {
  2166. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2167. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2168. (txProfile.ChargingSchedule.Duration > 0))
  2169. {
  2170. if(maxProfile.ChargingProfileId != -1)
  2171. {
  2172. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2173. {
  2174. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2175. {
  2176. if((maxProfile.ChargingSchedule.Duration > 0))
  2177. {
  2178. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2179. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2180. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2181. }
  2182. else
  2183. {
  2184. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2185. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2186. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2187. }
  2188. }
  2189. if(idxMaxPeriod == (limitMax-1))
  2190. {
  2191. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2192. {
  2193. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2194. {
  2195. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2196. compositePeriodIdx++;
  2197. }
  2198. else
  2199. {
  2200. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. else
  2207. {
  2208. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2209. {
  2210. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2211. compositePeriodIdx++;
  2212. }
  2213. else
  2214. {
  2215. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2216. }
  2217. }
  2218. }
  2219. if(idxTxPeriod == (limitTx-1))
  2220. {
  2221. if(defaultTxProfile.ChargingProfileId != -1)
  2222. {
  2223. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2224. {
  2225. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2226. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2227. (defaultTxProfile.ChargingSchedule.Duration>0))
  2228. {
  2229. if(maxProfile.ChargingProfileId != -1)
  2230. {
  2231. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2232. {
  2233. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2234. {
  2235. if((maxProfile.ChargingSchedule.Duration > 0))
  2236. {
  2237. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2238. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2239. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2240. }
  2241. else
  2242. {
  2243. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2244. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2245. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2246. }
  2247. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2248. {
  2249. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2250. {
  2251. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2252. compositePeriodIdx++;
  2253. }
  2254. else
  2255. {
  2256. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2257. }
  2258. }
  2259. // Delete duplicate period
  2260. if(compositePeriodIdx > 1)
  2261. {
  2262. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2263. {
  2264. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2265. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2266. compositePeriodIdx -= 1;
  2267. }
  2268. }
  2269. }
  2270. else
  2271. break;
  2272. }
  2273. }
  2274. else
  2275. {
  2276. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2277. {
  2278. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2279. compositePeriodIdx++;
  2280. }
  2281. else
  2282. {
  2283. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2284. }
  2285. }
  2286. }
  2287. }
  2288. }
  2289. }
  2290. }
  2291. }
  2292. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2293. else if(defaultTxProfile.ChargingProfileId != -1)
  2294. {
  2295. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2296. {
  2297. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2298. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2299. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2300. {
  2301. if(maxProfile.ChargingProfileId != -1)
  2302. {
  2303. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2304. {
  2305. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2306. {
  2307. if((maxProfile.ChargingSchedule.Duration > 0))
  2308. {
  2309. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2310. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2311. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2312. }
  2313. else
  2314. {
  2315. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2316. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2317. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2318. }
  2319. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2320. {
  2321. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2322. {
  2323. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2324. compositePeriodIdx++;
  2325. }
  2326. else
  2327. {
  2328. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2329. }
  2330. }
  2331. // Delete duplicate period
  2332. if(compositePeriodIdx > 1)
  2333. {
  2334. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2335. {
  2336. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2337. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2338. compositePeriodIdx -= 1;
  2339. }
  2340. }
  2341. }
  2342. else
  2343. break;
  2344. }
  2345. }
  2346. else
  2347. {
  2348. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2349. {
  2350. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2351. compositePeriodIdx++;
  2352. }
  2353. else
  2354. {
  2355. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2356. }
  2357. }
  2358. }
  2359. }
  2360. }
  2361. // Fill other period by MaxProfile
  2362. if(maxProfile.ChargingProfileId != -1)
  2363. {
  2364. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2365. {
  2366. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2367. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2368. (maxProfile.ChargingSchedule.Duration > 0))
  2369. {
  2370. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2371. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2372. {
  2373. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2374. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2375. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2376. }
  2377. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2378. {
  2379. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2380. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2381. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2382. }
  2383. if(tmpPeriod.Limit != -1)
  2384. {
  2385. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2386. {
  2387. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2388. {
  2389. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2390. compositePeriodIdx++;
  2391. }
  2392. else
  2393. {
  2394. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2395. }
  2396. }
  2397. // Delete duplicate period
  2398. if(compositePeriodIdx > 1)
  2399. {
  2400. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2401. {
  2402. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2403. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2404. compositePeriodIdx -= 1;
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2412. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2413. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2414. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2415. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2416. {
  2417. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2418. {
  2419. compositeProfile->ChargingProfileId = 1;
  2420. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2421. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2422. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2423. }
  2424. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2425. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2426. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2427. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2428. }
  2429. if(line)
  2430. free(line);
  2431. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2432. }
  2433. //==========================================
  2434. // Init all share memory
  2435. //==========================================
  2436. int InitShareMemory()
  2437. {
  2438. int result = PASS;
  2439. int MeterSMId;
  2440. //creat ShmSysConfigAndInfo
  2441. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2442. {
  2443. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2444. result = FAIL;
  2445. }
  2446. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2447. {
  2448. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2449. result = FAIL;
  2450. }
  2451. else
  2452. {}
  2453. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2454. {
  2455. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2456. result = FAIL;
  2457. }
  2458. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2459. {
  2460. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2461. result = FAIL;
  2462. }
  2463. else
  2464. {}
  2465. //creat ShmPsuData
  2466. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2467. {
  2468. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2469. result = FAIL;
  2470. }
  2471. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2472. {
  2473. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2474. result = FAIL;
  2475. }
  2476. else
  2477. {}
  2478. //creat ShmOCPP16Data
  2479. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2480. {
  2481. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2482. result = FAIL;
  2483. }
  2484. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2485. {
  2486. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2487. result = FAIL;
  2488. }
  2489. else
  2490. {}
  2491. /****************************** For Initial Settings************************************************/
  2492. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2493. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2494. // allocate Configuration memory address
  2495. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2496. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2497. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2498. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2499. //offline MeterValue Interval
  2500. TempMeterValueInterval = 0;
  2501. return result;
  2502. }
  2503. int ProcessShareMemory()
  2504. {
  2505. if(InitShareMemory() == FAIL)
  2506. {
  2507. DEBUG_ERROR("InitShareMemory NG\n");
  2508. if(ShmStatusCodeData!=NULL)
  2509. {
  2510. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2511. }
  2512. sleep(5);
  2513. return FAIL;
  2514. }
  2515. return PASS;
  2516. }
  2517. void CheckSystemValue(void)
  2518. {
  2519. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2520. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2521. char filenmae[100]={0};
  2522. char str[100]={0};
  2523. int tempIndex = 0;
  2524. //===============================
  2525. // send Heartbeat
  2526. //===============================
  2527. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2528. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2529. {
  2530. clientTime.Heartbeat=time((time_t*)NULL);
  2531. if(server_sign == TRUE)
  2532. {
  2533. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2534. }
  2535. else
  2536. {
  2537. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2538. }
  2539. }
  2540. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2541. {
  2542. //parameter for test
  2543. sendHeartbeatRequest(0);
  2544. //==============================================
  2545. // Reset Waiting Time
  2546. //==============================================
  2547. HeartBeatWithNOResponse += 1;
  2548. }
  2549. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2550. {
  2551. //==========================================
  2552. // csu trigger DataTransferReq
  2553. //==========================================
  2554. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2555. {
  2556. sendDataTransferRequest(gun_index);
  2557. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2558. }
  2559. //===============================
  2560. // CSU Trigger Authorize Request
  2561. //===============================
  2562. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2563. {
  2564. sendAuthorizeRequest(0);
  2565. authorizeRetryTimes = authorizeRetryTimes + 1;
  2566. if(authorizeRetryTimes < 3)
  2567. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2568. }
  2569. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2570. {
  2571. authorizeRetryTimes = 0;
  2572. SetOcppConnStatus(FALSE);
  2573. server_sign = FALSE;
  2574. }
  2575. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  2576. {
  2577. sendAuthorizeRequest(0);
  2578. }
  2579. //==============================================
  2580. // CSU Trigger Smart Charging Profilw
  2581. //==============================================
  2582. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2583. {
  2584. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2585. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2586. }
  2587. //==============================================
  2588. // Charger start transaction
  2589. //==============================================
  2590. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2591. {
  2592. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2593. sendStartTransactionRequest(gun_index);
  2594. clientTime.StartTransaction = time((time_t*)NULL);
  2595. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2596. storeTempStopTransaction(gun_index);
  2597. }
  2598. //==============================================
  2599. // Charger stop transaction
  2600. //==============================================
  2601. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2602. {
  2603. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2604. sendStopTransactionRequest(gun_index);
  2605. clientTime.StopTransaction = time((time_t*)NULL);
  2606. }
  2607. //==============================================
  2608. // Charger status report
  2609. //==============================================
  2610. //--- Check Mode Change ---//
  2611. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2612. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2613. {
  2614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2615. {
  2616. tempIndex = ((gun_index==2) ? 1: 0);
  2617. }
  2618. else
  2619. {
  2620. tempIndex = gun_index;
  2621. }
  2622. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2623. {
  2624. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2625. {
  2626. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2627. {
  2628. // Sent unplug message for California pricing logic
  2629. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2630. {
  2631. uint8_t ts[20];
  2632. getNowDatetime(ts);
  2633. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2634. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2635. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2636. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2637. }
  2638. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2639. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2640. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2641. statusModeChage[gun_index] = TRUE;
  2642. }
  2643. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2644. {
  2645. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2646. if((access(filenmae,F_OK))!=-1)
  2647. {
  2648. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2649. sprintf(str,"rm -f %s",filenmae);
  2650. system(str);
  2651. }
  2652. }
  2653. #if 1 // for TempStopTransaction
  2654. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2655. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2656. {
  2657. checkTempStopTransaction(gun_index);
  2658. }
  2659. #endif
  2660. }
  2661. }
  2662. }
  2663. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2664. {
  2665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2666. {
  2667. tempIndex = ((gun_index==2) ? 1: 0);
  2668. }
  2669. else
  2670. {
  2671. tempIndex = gun_index;
  2672. }
  2673. for (int index = 0; index < CCS_QUANTITY; index++)
  2674. {
  2675. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2676. {
  2677. 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]*/ )
  2678. {
  2679. // Sent unplug message for California pricing logic
  2680. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2681. {
  2682. uint8_t ts[20];
  2683. getNowDatetime(ts);
  2684. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2685. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2686. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2687. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2688. }
  2689. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2690. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2691. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2692. statusModeChage[gun_index] = TRUE;
  2693. }
  2694. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2695. {
  2696. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2697. if((access(filenmae,F_OK))!=-1)
  2698. {
  2699. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2700. sprintf(str,"rm -f %s",filenmae);
  2701. system(str);
  2702. }
  2703. }
  2704. #if 1 // for TempStopTransaction
  2705. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2706. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2707. {
  2708. checkTempStopTransaction(gun_index);
  2709. }
  2710. #endif
  2711. }
  2712. }
  2713. }
  2714. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2715. {
  2716. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2717. {
  2718. tempIndex = ((gun_index==2) ? 1: 0);
  2719. }
  2720. else
  2721. {
  2722. tempIndex = gun_index;
  2723. }
  2724. for (int index = 0; index < GB_QUANTITY; index++)
  2725. {
  2726. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2727. {
  2728. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2729. {
  2730. // Sent unplug message for California pricing logic
  2731. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2732. {
  2733. uint8_t ts[20];
  2734. getNowDatetime(ts);
  2735. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2736. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2737. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2738. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2739. }
  2740. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2741. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2742. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2743. statusModeChage[gun_index] = TRUE;
  2744. }
  2745. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2746. {
  2747. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2748. if((access(filenmae,F_OK))!=-1)
  2749. {
  2750. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2751. sprintf(str,"rm -f %s",filenmae);
  2752. system(str);
  2753. }
  2754. }
  2755. #if 1 // for TempStopTransaction
  2756. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2757. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2758. {
  2759. checkTempStopTransaction(gun_index);
  2760. }
  2761. #endif
  2762. }
  2763. }
  2764. }
  2765. else if(gunType[gun_index] == GUN_TYPE_DO)
  2766. {
  2767. tempIndex = gun_index;
  2768. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2769. {
  2770. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2771. {
  2772. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2773. {
  2774. // Sent unplug message for California pricing logic
  2775. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2776. {
  2777. uint8_t ts[20];
  2778. getNowDatetime(ts);
  2779. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2780. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2781. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2782. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2783. }
  2784. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2785. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2786. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2787. statusModeChage[gun_index] = TRUE;
  2788. }
  2789. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  2790. {
  2791. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2792. if((access(filenmae,F_OK))!=-1)
  2793. {
  2794. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2795. sprintf(str,"rm -f %s",filenmae);
  2796. system(str);
  2797. }
  2798. }
  2799. #if 1 // for TempStopTransaction
  2800. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  2801. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2802. {
  2803. checkTempStopTransaction(gun_index);
  2804. }
  2805. #endif
  2806. }
  2807. }
  2808. }
  2809. else
  2810. {
  2811. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2812. {
  2813. tempIndex = 2;
  2814. }
  2815. else
  2816. {
  2817. tempIndex = gun_index;
  2818. }
  2819. for (int index = 0; index < AC_QUANTITY; index++)
  2820. {
  2821. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2822. {
  2823. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2824. {
  2825. // Sent unplug message for California pricing logic
  2826. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2827. {
  2828. uint8_t ts[20];
  2829. getNowDatetime(ts);
  2830. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2831. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2832. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2833. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2834. }
  2835. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2836. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2837. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2838. statusModeChage[gun_index] = TRUE;
  2839. }
  2840. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2841. {
  2842. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2843. if((access(filenmae,F_OK))!=-1)
  2844. {
  2845. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2846. sprintf(str,"rm -f %s",filenmae);
  2847. system(str);
  2848. }
  2849. }
  2850. #if 1 // for TempStopTransaction
  2851. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2852. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2853. {
  2854. checkTempStopTransaction(gun_index);
  2855. }
  2856. #endif
  2857. }
  2858. }// END
  2859. }
  2860. if(isWebsocketSendable && (server_sign == TRUE) &&
  2861. (
  2862. (statusModeChage[gun_index] == TRUE) ||
  2863. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2864. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5))
  2865. )
  2866. )
  2867. {
  2868. if(SystemInitial > 0)
  2869. SystemInitial -= 1;
  2870. sendStatusNotificationRequest(gun_index);
  2871. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2872. statusModeChage[gun_index] = FALSE;
  2873. }
  2874. //==============================================
  2875. // Meter report
  2876. //==============================================
  2877. // Trigger MeterValue
  2878. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2879. {
  2880. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2881. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2882. }
  2883. // ClockAlign MeterValue
  2884. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2885. {
  2886. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2887. {
  2888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2889. {
  2890. tempIndex = ((gun_index==2) ? 1: 0);
  2891. }
  2892. else
  2893. {
  2894. tempIndex = gun_index;
  2895. }
  2896. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2897. {
  2898. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2899. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2900. {
  2901. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2902. {
  2903. reqClockAlignMeter[gun_index] = 1;
  2904. }
  2905. }
  2906. }// End for CHAdeMO
  2907. }
  2908. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2909. {
  2910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2911. {
  2912. tempIndex = ((gun_index==2) ? 1: 0);
  2913. }
  2914. else
  2915. {
  2916. tempIndex = gun_index;
  2917. }
  2918. for (int index = 0; index < CCS_QUANTITY; index++)
  2919. {
  2920. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2921. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2922. {
  2923. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2924. {
  2925. reqClockAlignMeter[gun_index] = 1;
  2926. }
  2927. }
  2928. } // End for CCS
  2929. }
  2930. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2931. {
  2932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2933. {
  2934. tempIndex = ((gun_index==2) ? 1: 0);
  2935. }
  2936. else
  2937. {
  2938. tempIndex = gun_index;
  2939. }
  2940. for (int index = 0; index < GB_QUANTITY; index++)
  2941. {
  2942. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2943. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2944. {
  2945. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2946. {
  2947. reqClockAlignMeter[gun_index] = 1;
  2948. }
  2949. }
  2950. }// End for GB
  2951. }
  2952. else if(gunType[gun_index] == GUN_TYPE_DO)
  2953. {
  2954. tempIndex = gun_index;
  2955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2956. {
  2957. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2958. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2959. {
  2960. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2961. {
  2962. reqClockAlignMeter[gun_index] = 1;
  2963. }
  2964. }
  2965. }
  2966. }
  2967. else
  2968. {
  2969. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2970. {
  2971. tempIndex = 2;
  2972. }
  2973. else
  2974. {
  2975. tempIndex = gun_index;
  2976. }
  2977. for (int index = 0; index < AC_QUANTITY; index++)
  2978. {
  2979. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2980. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2981. {
  2982. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2983. {
  2984. reqClockAlignMeter[gun_index] = 1;
  2985. }
  2986. }
  2987. }//End for AC
  2988. }
  2989. if(reqClockAlignMeter[gun_index] == 1)
  2990. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2991. }
  2992. // Sample period MeterValue
  2993. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2994. {
  2995. //check Transaction active
  2996. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2997. {
  2998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2999. {
  3000. tempIndex = ((gun_index==2) ? 1: 0);
  3001. }
  3002. else
  3003. {
  3004. tempIndex = gun_index;
  3005. }
  3006. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3007. {
  3008. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3009. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3010. {
  3011. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3012. {
  3013. reqSampleMeter[gun_index] = 1;
  3014. }
  3015. }
  3016. }// End for CHAdeMO
  3017. }
  3018. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3019. {
  3020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3021. {
  3022. tempIndex = ((gun_index==2) ? 1: 0);
  3023. }
  3024. else
  3025. {
  3026. tempIndex = gun_index;
  3027. }
  3028. for (int index = 0; index < CCS_QUANTITY; index++)
  3029. {
  3030. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3031. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3032. {
  3033. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3034. {
  3035. reqSampleMeter[gun_index] = 1;
  3036. }
  3037. }
  3038. } // End for CCS
  3039. }
  3040. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3041. {
  3042. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3043. {
  3044. tempIndex = ((gun_index==2) ? 1: 0);
  3045. }
  3046. else
  3047. {
  3048. tempIndex = gun_index;
  3049. }
  3050. for (int index = 0; index < GB_QUANTITY; index++)
  3051. {
  3052. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3053. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3054. {
  3055. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3056. {
  3057. reqSampleMeter[gun_index] = 1;
  3058. }
  3059. }
  3060. }// End for GB
  3061. }
  3062. else if(gunType[gun_index] == GUN_TYPE_DO)
  3063. {
  3064. tempIndex = gun_index;
  3065. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3066. {
  3067. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3068. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3069. {
  3070. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3071. {
  3072. reqSampleMeter[gun_index] = 1;
  3073. }
  3074. }
  3075. }
  3076. }
  3077. else
  3078. {
  3079. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3080. {
  3081. tempIndex = 2;
  3082. }
  3083. else
  3084. {
  3085. tempIndex = gun_index;
  3086. }
  3087. for (int index = 0; index < AC_QUANTITY; index++)
  3088. {
  3089. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3090. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3091. {
  3092. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3093. {
  3094. reqSampleMeter[gun_index] = 1;
  3095. }
  3096. }
  3097. }//End for AC
  3098. }
  3099. if(reqSampleMeter[gun_index] == 1)
  3100. {
  3101. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3102. storeTempStopTransaction(gun_index);
  3103. }
  3104. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3105. }
  3106. //==============================================
  3107. // Check Connector reserved
  3108. //==============================================
  3109. //===============================
  3110. // Check if Reserve is expired
  3111. //===============================
  3112. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3113. {
  3114. double diff_t;
  3115. struct tm tp;
  3116. // current time
  3117. time_t t = time(NULL);
  3118. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3119. tp.tm_isdst = -1;
  3120. time_t utc = mktime(&tp);
  3121. diff_t = difftime(utc, t);
  3122. if(diff_t <= 0)
  3123. {
  3124. DEBUG_INFO("reserve expired.\n");
  3125. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3126. }
  3127. }//END OF Check if Reserve is expired
  3128. //==========================================
  3129. // csu trigger FirmwareStatusNotificationReq
  3130. //==========================================
  3131. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3132. {
  3133. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3134. }
  3135. //==========================================
  3136. // csu trigger DiagnosticsStatusNotificationReq
  3137. //==========================================
  3138. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3139. {
  3140. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3141. }
  3142. //==========================================
  3143. // csu trigger CancelReservationConf
  3144. //==========================================
  3145. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3146. {
  3147. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3148. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3149. }
  3150. //==========================================
  3151. // csu trigger ChangeAvailabilityConf
  3152. //==========================================
  3153. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3154. {
  3155. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3156. }
  3157. //==========================================
  3158. // csu trigger UnlockConnectorConf
  3159. //==========================================
  3160. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3161. {
  3162. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3163. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3164. }
  3165. //==========================================
  3166. // csu trigger ReserveNowConf
  3167. //==========================================
  3168. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3169. {
  3170. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3171. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3172. }
  3173. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3174. {
  3175. sendSignCertificateRequest();
  3176. }
  3177. }
  3178. }
  3179. //==========================================
  3180. // send request routine
  3181. //==========================================
  3182. int sendAuthorizeRequest(int gun_index)
  3183. {
  3184. mtrace();
  3185. int result = FAIL;
  3186. char message[100]={0};
  3187. char guid[37];
  3188. char tempdata[65]={0};
  3189. DEBUG_INFO("sendAuthorizeRequest...\n");
  3190. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3191. //Local Authorize
  3192. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3193. {
  3194. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  3195. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3196. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3197. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3198. result = PASS;
  3199. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3200. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3201. authorizeRetryTimes = 0;
  3202. return result;
  3203. }
  3204. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  3205. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3206. {
  3207. // Query from cache
  3208. DEBUG_INFO("Authorize from cache.\n");
  3209. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3210. // Query from list
  3211. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3212. {
  3213. DEBUG_INFO("Authorize from list.\n");
  3214. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3215. }
  3216. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3217. {
  3218. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3219. {
  3220. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3221. }
  3222. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3223. {
  3224. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3225. }
  3226. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3227. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3228. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3229. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3230. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3231. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3232. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3233. authorizeRetryTimes = 0;
  3234. return result;
  3235. }
  3236. else
  3237. {
  3238. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3239. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3240. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3241. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3242. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3243. else
  3244. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3245. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3246. result = PASS;
  3247. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3248. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3249. authorizeRetryTimes = 0;
  3250. return result;
  3251. }
  3252. }
  3253. //initialize struct Authorize
  3254. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3255. //get data from shared memory
  3256. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3257. random_uuid(guid);
  3258. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3259. LWS_Send(message);
  3260. sprintf(tempdata, "Authorize,%d", gun_index);
  3261. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3262. {
  3263. result = PASS;
  3264. DEBUG_INFO("Authorize mapItem pass\n");
  3265. }
  3266. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3267. return result;
  3268. }
  3269. int sendBootNotificationRequest(void)
  3270. {
  3271. mtrace();
  3272. int result = FAIL;
  3273. char message[500]={0}, payload[700]={0};
  3274. char guid[37]={0};
  3275. char tempdata[65]={0};
  3276. // Fill BootNotification fields
  3277. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3278. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3279. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3280. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3281. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3282. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3283. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3284. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3285. ShmOCPP16Data->ChargeBoxId
  3286. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3287. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3288. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3289. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3290. ,ShmOCPP16Data->BootNotification.CpIccid
  3291. ,ShmOCPP16Data->BootNotification.CpImsi);
  3292. random_uuid(guid);
  3293. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3294. LWS_Send(message);
  3295. sprintf(tempdata, "BootNotification,0");
  3296. 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*/)
  3297. {
  3298. result = PASS;
  3299. }
  3300. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3301. strcpy(queuedata,message);
  3302. return result;
  3303. }
  3304. int sendDataTransferRequest(int gun_index)
  3305. {
  3306. mtrace();
  3307. char message[1000]={0};
  3308. char guid[37]={0};
  3309. char tempdata[65]={0};
  3310. int result = FAIL;
  3311. random_uuid(guid);
  3312. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3313. MESSAGE_TYPE_CALL,
  3314. guid,
  3315. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3316. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3317. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3318. LWS_Send(message);
  3319. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3320. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3321. {
  3322. result = PASS;
  3323. DEBUG_INFO("DataTransfer mapItem pass\n");
  3324. }
  3325. return result;
  3326. }
  3327. int sendDiagnosticsStatusNotificationRequest(char *status)
  3328. {
  3329. mtrace();
  3330. int result = FAIL;
  3331. char message[110]={0};
  3332. char guid[37]={0};
  3333. char tempdata[65]={0};
  3334. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3335. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3336. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3337. random_uuid(guid);
  3338. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3339. LWS_SendNow(message);
  3340. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3341. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3342. {
  3343. result = PASS;
  3344. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3345. }
  3346. //#ifdef SystemLogMessage
  3347. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3348. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3349. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3350. //#endif
  3351. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3352. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3353. //record status
  3354. if(strcmp(status,"Idle")==0)
  3355. {
  3356. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3357. }
  3358. else if(strcmp(status,"Uploaded")==0)
  3359. {
  3360. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3361. }
  3362. else if(strcmp(status,"UploadFailed")==0)
  3363. {
  3364. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3365. }
  3366. else if(strcmp(status,"Uploading")==0)
  3367. {
  3368. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3369. }
  3370. return result;
  3371. }
  3372. int sendFirmwareStatusNotificationRequest(char *status)
  3373. {
  3374. mtrace();
  3375. int result = FAIL;
  3376. char message[110]={0};
  3377. char guid[37]={0};
  3378. char tempdata[65]={0};
  3379. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3380. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3381. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3382. random_uuid(guid);
  3383. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3384. LWS_SendNow(message);
  3385. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3386. 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*/)
  3387. {
  3388. result = PASS;
  3389. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3390. }
  3391. //#ifdef SystemLogMessage
  3392. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3393. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3394. //#endif
  3395. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3396. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3397. //record status
  3398. if(strcmp(status,"Downloaded")==0)
  3399. {
  3400. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3401. }
  3402. else if(strcmp(status,"DownloadFailed")==0)
  3403. {
  3404. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3405. }
  3406. else if(strcmp(status,"Downloading")==0)
  3407. {
  3408. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3409. }
  3410. else if(strcmp(status,"Idle")==0)
  3411. {
  3412. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3413. }
  3414. else if(strcmp(status,"InstallationFailed")==0)
  3415. {
  3416. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3417. }
  3418. else if(strcmp(status,"Installing")==0)
  3419. {
  3420. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3421. }
  3422. else if(strcmp(status,"Installed")==0)
  3423. {
  3424. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3425. }
  3426. return result;
  3427. }
  3428. int sendHeartbeatRequest(int gun_index)
  3429. {
  3430. mtrace();
  3431. int result = FAIL;
  3432. char message[80]={0};
  3433. char guid[37]={0};
  3434. char tempdata[65]={0};
  3435. random_uuid(guid);
  3436. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3437. , MESSAGE_TYPE_CALL
  3438. , guid );
  3439. LWS_Send(message);
  3440. sprintf(tempdata, "Heartbeat,%d", 0);
  3441. 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*/)
  3442. {
  3443. result = PASS;
  3444. }
  3445. return result;
  3446. }
  3447. int sendStartTransactionRequest(int gun_index)
  3448. {
  3449. mtrace();
  3450. int result = FAIL;
  3451. char message[250]={0};
  3452. char guid[37]={0};
  3453. struct timeval tmnow;
  3454. struct tm *tm;
  3455. char buf[28];//, usec_buf[6];
  3456. char tempdata[65]={0};
  3457. int tempIndex = 0;
  3458. DEBUG_INFO("sendStartTransactionRequest...\n");
  3459. gettimeofday(&tmnow, NULL);
  3460. time_t t;
  3461. t = time(NULL);
  3462. /*UTC time and date*/
  3463. tm = gmtime(&t);
  3464. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3465. #if 0 // remove temporally
  3466. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3467. strcat(buf,".");
  3468. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3469. strcat(buf,usec_buf);
  3470. #endif
  3471. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3472. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3473. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3474. // clear StartTransaction Response
  3475. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3476. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3477. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3478. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3479. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3480. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3481. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3482. {
  3483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3484. {
  3485. tempIndex = ((gun_index==2) ? 1: 0);
  3486. }
  3487. else
  3488. {
  3489. tempIndex = gun_index;
  3490. }
  3491. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3492. {
  3493. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3494. {
  3495. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3496. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3497. }
  3498. }
  3499. }
  3500. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3501. {
  3502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3503. {
  3504. tempIndex = ((gun_index==2) ? 1: 0);
  3505. }
  3506. else
  3507. {
  3508. tempIndex = gun_index;
  3509. }
  3510. for (int index = 0; index < CCS_QUANTITY; index++)
  3511. {
  3512. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3513. {
  3514. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3515. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3516. }
  3517. }
  3518. }
  3519. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3520. {
  3521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3522. {
  3523. tempIndex = ((gun_index==2) ? 1: 0);
  3524. }
  3525. else
  3526. {
  3527. tempIndex = gun_index;
  3528. }
  3529. for (int index = 0; index < GB_QUANTITY; index++)
  3530. {
  3531. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3532. {
  3533. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3534. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3535. }
  3536. }
  3537. }
  3538. else if(gunType[gun_index] == GUN_TYPE_DO)
  3539. {
  3540. tempIndex = gun_index;
  3541. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3542. {
  3543. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3544. {
  3545. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3546. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3547. }
  3548. }
  3549. }
  3550. else
  3551. {
  3552. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3553. {
  3554. tempIndex = 2;
  3555. }
  3556. else
  3557. {
  3558. tempIndex = gun_index;
  3559. }
  3560. for (int index = 0; index < AC_QUANTITY; index++)
  3561. {
  3562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3563. {
  3564. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3565. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3566. }
  3567. }
  3568. }
  3569. random_uuid(guid);
  3570. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3571. {
  3572. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3573. , gun_index +1
  3574. , MESSAGE_TYPE_CALL
  3575. , guid
  3576. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3577. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3578. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3579. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3580. }
  3581. else
  3582. {
  3583. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3584. , gun_index +1
  3585. , MESSAGE_TYPE_CALL
  3586. , guid
  3587. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3588. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3589. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3590. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3591. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3592. }
  3593. #if 1
  3594. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3595. 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*/)
  3596. {
  3597. result = PASS;
  3598. }
  3599. #endif
  3600. strcpy(queuedata, message);
  3601. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3602. OCPP_insert_transaction_msg(YES, queuedata);
  3603. return result;
  3604. }
  3605. int sendStatusNotificationRequest(int gun_index)
  3606. {
  3607. mtrace();
  3608. int result = FAIL;
  3609. char message[600]={0};
  3610. char guid[37];
  3611. int currentStatus = 0;
  3612. struct timeval tmnow;
  3613. struct tm *tm;
  3614. char buf[28];//, usec_buf[6];
  3615. char tempdata[65]={0};
  3616. int tempIndex = 0;
  3617. uint8_t isStateChanged = TRUE;
  3618. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3619. gettimeofday(&tmnow, NULL);
  3620. time_t t;
  3621. t = time(NULL);
  3622. /*UTC time and date*/
  3623. tm = gmtime(&t);
  3624. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3625. #if 0 // remove temporally
  3626. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3627. strcat(buf,".");
  3628. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3629. strcat(buf,usec_buf);
  3630. #endif
  3631. printf("%s",buf);
  3632. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3633. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3634. // it's option
  3635. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3636. /*
  3637. enum _SYSTEM_STATUS
  3638. {
  3639. S_BOOTING = 0,
  3640. S_IDLE, = 1
  3641. S_AUTHORIZING, =2
  3642. S_REASSIGN_CHECK, =3
  3643. S_REASSIGN, =4
  3644. S_PRECHARGE, =5
  3645. S_PREPARING_FOR_EV, =6
  3646. S_PREPARING_FOR_EVSE, =7
  3647. S_CHARGING, =8
  3648. S_TERMINATING, =9
  3649. S_COMPLETE, =10
  3650. S_ALARM, =11
  3651. S_FAULT =12
  3652. }
  3653. */
  3654. //check Transaction active
  3655. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3656. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3657. {
  3658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3659. {
  3660. tempIndex = ((gun_index==2) ? 1: 0);
  3661. }
  3662. else
  3663. {
  3664. tempIndex = gun_index;
  3665. }
  3666. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3667. {
  3668. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3669. {
  3670. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3671. {
  3672. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3673. {
  3674. currentStatus = Preparing; //OCPP Status: Preparing
  3675. }
  3676. else
  3677. {
  3678. currentStatus = Available; //OCPP Status: Available
  3679. }
  3680. }
  3681. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3682. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3683. ) //S_PRECHARGE
  3684. {
  3685. currentStatus = Preparing; //OCPP Status: Preparing
  3686. }
  3687. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3688. {
  3689. currentStatus = Charging; //OCPP Status: Charging
  3690. }
  3691. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3692. {
  3693. currentStatus = Finishing; //OCPP Status: Finishing
  3694. }
  3695. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3696. {
  3697. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3698. }
  3699. 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
  3700. {
  3701. currentStatus = Unavailable; //OCPP Status: Unavailable
  3702. }
  3703. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3704. {
  3705. currentStatus = Faulted; //OCPP Status: Faulted
  3706. }
  3707. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3708. {
  3709. currentStatus = Reserved; //OCPP Status: Reserved
  3710. }
  3711. } //end of the same index
  3712. }//end of for CHAdeMO_QUANTITY
  3713. }
  3714. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3715. {
  3716. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3717. {
  3718. tempIndex = ((gun_index==2) ? 1: 0);
  3719. }
  3720. else
  3721. {
  3722. tempIndex = gun_index;
  3723. }
  3724. for (int index = 0; index < CCS_QUANTITY; index++)
  3725. {
  3726. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3727. {
  3728. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3729. {
  3730. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3731. {
  3732. currentStatus = Preparing; //OCPP Status: Preparing
  3733. }
  3734. else
  3735. {
  3736. currentStatus = Available; //OCPP Status: Available
  3737. }
  3738. }
  3739. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3740. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3741. ) //S_PRECHARGE
  3742. {
  3743. currentStatus = Preparing; //OCPP Status: Preparing
  3744. }
  3745. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3746. {
  3747. currentStatus = Charging; //OCPP Status: Charging
  3748. }
  3749. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3750. {
  3751. currentStatus = Finishing; //OCPP Status: Finishing
  3752. }
  3753. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3754. {
  3755. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3756. }
  3757. 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
  3758. {
  3759. currentStatus = Unavailable; //OCPP Status : Unavailable
  3760. }
  3761. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3762. {
  3763. currentStatus = Faulted; //OCPP Status: Faulted
  3764. }
  3765. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3766. {
  3767. currentStatus = Reserved; //OCPP Status: Reserved
  3768. }
  3769. } //end of the same index
  3770. } // end of for CCS_QUANTITY
  3771. }
  3772. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3773. {
  3774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3775. {
  3776. tempIndex = ((gun_index==2) ? 1: 0);
  3777. }
  3778. else
  3779. {
  3780. tempIndex = gun_index;
  3781. }
  3782. for (int index = 0; index < GB_QUANTITY; index++)
  3783. {
  3784. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3785. {
  3786. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3787. {
  3788. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3789. {
  3790. currentStatus = Preparing; //OCPP Status: Preparing
  3791. }
  3792. else
  3793. {
  3794. currentStatus = Available; //OCPP Status: Available
  3795. }
  3796. }
  3797. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3798. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3799. ) //S_PRECHARGE
  3800. {
  3801. currentStatus = Preparing; //OCPP Status: Preparing
  3802. }
  3803. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3804. {
  3805. currentStatus = Charging; //OCPP Status: Charging
  3806. }
  3807. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3808. {
  3809. currentStatus = Finishing; //OCPP Status: Finishing
  3810. }
  3811. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3812. {
  3813. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3814. }
  3815. 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
  3816. {
  3817. currentStatus = Unavailable; //OCPP Status: Unavailable
  3818. }
  3819. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3820. {
  3821. currentStatus = Faulted; //OCPP Status: Faulted
  3822. }
  3823. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3824. {
  3825. currentStatus = Reserved; //OCPP Status: Reserved
  3826. }
  3827. } //end of the same index
  3828. } // end of for GB_QUANTITY
  3829. }
  3830. else if(gunType[gun_index] == GUN_TYPE_DO)
  3831. {
  3832. tempIndex = gun_index;
  3833. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3834. {
  3835. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3836. {
  3837. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3838. {
  3839. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3840. {
  3841. currentStatus = Preparing; //OCPP Status: Preparing
  3842. }
  3843. else
  3844. {
  3845. currentStatus = Available; //OCPP Status: Available
  3846. }
  3847. }
  3848. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3849. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3850. ) //S_PRECHARGE
  3851. {
  3852. currentStatus = Preparing; //OCPP Status: Preparing
  3853. }
  3854. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3855. {
  3856. currentStatus = Charging; //OCPP Status: Charging
  3857. }
  3858. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3859. {
  3860. currentStatus = Finishing; //OCPP Status: Finishing
  3861. }
  3862. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3863. {
  3864. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3865. }
  3866. 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
  3867. {
  3868. currentStatus = Unavailable; //OCPP Status: Unavailable
  3869. }
  3870. 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
  3871. {
  3872. currentStatus = Faulted; //OCPP Status: Faulted
  3873. }
  3874. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3875. {
  3876. currentStatus = Reserved; //OCPP Status: Reserved
  3877. }
  3878. } //end of the same index
  3879. }
  3880. }
  3881. else
  3882. {
  3883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3884. {
  3885. tempIndex = 2;
  3886. }
  3887. else
  3888. {
  3889. tempIndex = gun_index;
  3890. }
  3891. for (int index = 0; index < AC_QUANTITY; index++)
  3892. {
  3893. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3894. {
  3895. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3896. {
  3897. 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))
  3898. {
  3899. currentStatus = Preparing; //OCPP Status: Preparing
  3900. }
  3901. else
  3902. {
  3903. currentStatus = Available; //OCPP Status: Available
  3904. }
  3905. }
  3906. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3907. {
  3908. currentStatus = Preparing; //OCPP Status: Preparing
  3909. }
  3910. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3911. {
  3912. currentStatus = Charging; //OCPP Status: Charging
  3913. }
  3914. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3915. {
  3916. currentStatus = Finishing; //OCPP Status: Finishing
  3917. }
  3918. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3919. {
  3920. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3921. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3922. else
  3923. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3924. }
  3925. 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
  3926. {
  3927. currentStatus = Unavailable; //OCPP Status: Unavailable
  3928. }
  3929. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3930. {
  3931. currentStatus = Faulted; //OCPP Status: Faulted
  3932. }
  3933. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3934. {
  3935. currentStatus = Reserved; //OCPP Status: Reserved
  3936. }
  3937. }//end of the same index
  3938. }//end of for AC_QUANTITY
  3939. }
  3940. //it's option
  3941. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3942. !ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq)
  3943. {
  3944. isStateChanged = FALSE;
  3945. }
  3946. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3947. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3948. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3949. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3950. random_uuid(guid);
  3951. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3952. , MESSAGE_TYPE_CALL
  3953. , guid
  3954. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3955. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3956. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3957. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3958. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3959. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3960. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3961. if((server_sign == TRUE) && isStateChanged)
  3962. {
  3963. LWS_Send(message);
  3964. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3965. 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*/)
  3966. {
  3967. //DEBUG_ERROR("statusNotification mapitem pass");
  3968. result = PASS;
  3969. }
  3970. }
  3971. else
  3972. {
  3973. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3974. result = PASS;
  3975. }
  3976. return result;
  3977. }
  3978. int sendStopTransactionRequest(int gun_index)
  3979. {
  3980. mtrace();
  3981. int result = FAIL;
  3982. //char message[1500]={0};
  3983. char guid[37]={0};
  3984. char tempdata[65]={0};
  3985. int tempIndex = 0;
  3986. char TempStopTransaction[256];
  3987. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3988. //int idx_sample=0;
  3989. DEBUG_INFO("sendStopTransactionRequest \n");
  3990. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3991. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3992. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3993. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3994. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3995. {
  3996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3997. {
  3998. tempIndex = ((gun_index==2) ? 1: 0);
  3999. }
  4000. else
  4001. {
  4002. tempIndex = gun_index;
  4003. }
  4004. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4005. {
  4006. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4007. {
  4008. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4009. }
  4010. }// END OF CHAdeMO_QUANTITY
  4011. }
  4012. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4013. {
  4014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4015. {
  4016. tempIndex = ((gun_index==2) ? 1: 0);
  4017. }
  4018. else
  4019. {
  4020. tempIndex = gun_index;
  4021. }
  4022. for (int index = 0; index < CCS_QUANTITY; index++)
  4023. {
  4024. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4025. {
  4026. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4027. }
  4028. }// END OF CCS_QUANTITY
  4029. }
  4030. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4031. {
  4032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4033. {
  4034. tempIndex = ((gun_index==2) ? 1: 0);
  4035. }
  4036. else
  4037. {
  4038. tempIndex = gun_index;
  4039. }
  4040. for (int index = 0; index < GB_QUANTITY; index++)
  4041. {
  4042. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4043. {
  4044. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4045. }
  4046. }// END OF GB_QUANTITY
  4047. }
  4048. else if(gunType[gun_index] == GUN_TYPE_DO)
  4049. {
  4050. tempIndex = gun_index;
  4051. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4052. {
  4053. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4054. {
  4055. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4056. }
  4057. }// END OF GB_QUANTITY
  4058. }
  4059. else
  4060. {
  4061. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4062. {
  4063. tempIndex = 2;
  4064. }
  4065. else
  4066. {
  4067. tempIndex = gun_index;
  4068. }
  4069. for (int index = 0; index < AC_QUANTITY; index++)
  4070. {
  4071. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4072. {
  4073. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4074. }
  4075. }// END OF AC_QUANTITY
  4076. }
  4077. //====================================== Stop Transaction Time =====================================================
  4078. struct timeval tmnow;
  4079. struct tm *tm;
  4080. char buf[28];//, usec_buf[6];
  4081. gettimeofday(&tmnow, NULL);
  4082. time_t t;
  4083. t = time(NULL);
  4084. /*UTC time and date*/
  4085. tm = gmtime(&t);
  4086. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4088. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4089. random_uuid(guid);
  4090. /***********************************transactionData******************************************************/
  4091. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4093. //=================================
  4094. // Transaction_Begin
  4095. //=================================
  4096. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4097. {
  4098. //============================================ Energy.Active.Import.Interval ================================
  4099. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  4103. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4104. 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))
  4105. {
  4106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4107. }
  4108. else
  4109. {
  4110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4111. }
  4112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4114. }
  4115. //=================================
  4116. // Transaction_End
  4117. //=================================
  4118. // ================================= Current.Import L1 ===============================================
  4119. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4120. {
  4121. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4122. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4123. {
  4124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4125. {
  4126. tempIndex = ((gun_index==2) ? 1: 0);
  4127. }
  4128. else
  4129. {
  4130. tempIndex = gun_index;
  4131. }
  4132. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4133. {
  4134. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4135. {
  4136. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4137. }
  4138. }// End of for CHAdeMO_QUANTITY
  4139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4140. }
  4141. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4142. {
  4143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4144. {
  4145. tempIndex = ((gun_index==2) ? 1: 0);
  4146. }
  4147. else
  4148. {
  4149. tempIndex = gun_index;
  4150. }
  4151. for (int index = 0; index < CCS_QUANTITY; index++)
  4152. {
  4153. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4154. {
  4155. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4156. }
  4157. }// End of for CCS_QUANTITY
  4158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4159. }
  4160. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4161. {
  4162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4163. {
  4164. tempIndex = ((gun_index==2) ? 1: 0);
  4165. }
  4166. else
  4167. {
  4168. tempIndex = gun_index;
  4169. }
  4170. for (int index = 0; index < GB_QUANTITY; index++)
  4171. {
  4172. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4173. {
  4174. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4175. }
  4176. }// End of for GB_QUANTITY
  4177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4178. }
  4179. else if(gunType[gun_index] == GUN_TYPE_DO)
  4180. {
  4181. tempIndex = gun_index;
  4182. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4183. {
  4184. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4185. {
  4186. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4187. }
  4188. }
  4189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4190. }
  4191. else
  4192. {
  4193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4194. {
  4195. tempIndex = 2;
  4196. }
  4197. else
  4198. {
  4199. tempIndex = gun_index;
  4200. }
  4201. for (int index = 0; index < AC_QUANTITY; index++)
  4202. {
  4203. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4204. {
  4205. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4206. }
  4207. }// End of for AC_QUANTITY
  4208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4209. }
  4210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4215. }
  4216. // ================================= Energy.Active.Import.Interval ==============================================
  4217. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4218. {
  4219. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4220. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4221. {
  4222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4223. {
  4224. tempIndex = ((gun_index==2) ? 1: 0);
  4225. }
  4226. else
  4227. {
  4228. tempIndex = gun_index;
  4229. }
  4230. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4231. {
  4232. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4233. {
  4234. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4235. }
  4236. }// END OF CHAdeMO_QUANTITY
  4237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4238. }
  4239. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4240. {
  4241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4242. {
  4243. tempIndex = ((gun_index==2) ? 1: 0);
  4244. }
  4245. else
  4246. {
  4247. tempIndex = gun_index;
  4248. }
  4249. for (int index = 0; index < CCS_QUANTITY; index++)
  4250. {
  4251. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4252. {
  4253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4254. }
  4255. }// END OF CCS_QUANTITY
  4256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4257. }
  4258. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4259. {
  4260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4261. {
  4262. tempIndex = ((gun_index==2) ? 1: 0);
  4263. }
  4264. else
  4265. {
  4266. tempIndex = gun_index;
  4267. }
  4268. for (int index = 0; index < GB_QUANTITY; index++)
  4269. {
  4270. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4271. {
  4272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4273. }
  4274. }// END OF GB_QUANTITY
  4275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4276. }
  4277. else if(gunType[gun_index] == GUN_TYPE_DO)
  4278. {
  4279. tempIndex = gun_index;
  4280. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4281. {
  4282. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4283. {
  4284. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4285. }
  4286. }
  4287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4288. }
  4289. else
  4290. {
  4291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4292. {
  4293. tempIndex = 2;
  4294. }
  4295. else
  4296. {
  4297. tempIndex = gun_index;
  4298. }
  4299. for (int index = 0; index < AC_QUANTITY; index++)
  4300. {
  4301. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4302. {
  4303. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4304. }
  4305. }// END OF AC_QUANTITY
  4306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4307. }
  4308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4313. }
  4314. //=================================== Power.Active.Import ==================================================
  4315. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4316. {
  4317. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4318. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4319. {
  4320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4321. {
  4322. tempIndex = ((gun_index==2) ? 1: 0);
  4323. }
  4324. else
  4325. {
  4326. tempIndex = gun_index;
  4327. }
  4328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4329. {
  4330. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4331. {
  4332. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4333. }
  4334. } // End for CHAdeMO_QUANTITY
  4335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4336. }
  4337. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4338. {
  4339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4340. {
  4341. tempIndex = ((gun_index==2) ? 1: 0);
  4342. }
  4343. else
  4344. {
  4345. tempIndex = gun_index;
  4346. }
  4347. for (int index = 0; index < CCS_QUANTITY; index++)
  4348. {
  4349. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4350. {
  4351. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4352. }
  4353. } // END for CCS_QUANTITY
  4354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4355. }
  4356. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4357. {
  4358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4359. {
  4360. tempIndex = ((gun_index==2) ? 1: 0);
  4361. }
  4362. else
  4363. {
  4364. tempIndex = gun_index;
  4365. }
  4366. for (int index = 0; index < GB_QUANTITY; index++)
  4367. {
  4368. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4369. {
  4370. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4371. }
  4372. }// END for GB_QUANTITY
  4373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4374. }
  4375. else if(gunType[gun_index] == GUN_TYPE_DO)
  4376. {
  4377. tempIndex = gun_index;
  4378. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4379. {
  4380. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4381. {
  4382. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4383. }
  4384. }
  4385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4386. }
  4387. else
  4388. {
  4389. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4390. {
  4391. tempIndex = 2;
  4392. }
  4393. else
  4394. {
  4395. tempIndex = gun_index;
  4396. }
  4397. for (int index = 0; index < AC_QUANTITY; index++)
  4398. {
  4399. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4400. {
  4401. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4402. }
  4403. } // END for AC_QUANTITY
  4404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4405. }
  4406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4411. }
  4412. //============================ Voltage L1 ====================================
  4413. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4414. {
  4415. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4416. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4417. {
  4418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4419. {
  4420. tempIndex = ((gun_index==2) ? 1: 0);
  4421. }
  4422. else
  4423. {
  4424. tempIndex = gun_index;
  4425. }
  4426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4427. {
  4428. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4429. {
  4430. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4431. }
  4432. } // END OF FOR CHAdeMO_QUANTITY
  4433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4434. }
  4435. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4436. {
  4437. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4438. {
  4439. tempIndex = ((gun_index==2) ? 1: 0);
  4440. }
  4441. else
  4442. {
  4443. tempIndex = gun_index;
  4444. }
  4445. for (int index = 0; index < CCS_QUANTITY; index++)
  4446. {
  4447. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4448. {
  4449. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4450. }
  4451. } // END OF FOR CCS_QUANTITY
  4452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4453. }
  4454. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4455. {
  4456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4457. {
  4458. tempIndex = ((gun_index==2) ? 1: 0);
  4459. }
  4460. else
  4461. {
  4462. tempIndex = gun_index;
  4463. }
  4464. for (int index = 0; index < GB_QUANTITY; index++)
  4465. {
  4466. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4467. {
  4468. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4469. }
  4470. } // END OF FOR GB_QUANTITY
  4471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4472. }
  4473. else if(gunType[gun_index] == GUN_TYPE_DO)
  4474. {
  4475. tempIndex = gun_index;
  4476. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4477. {
  4478. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4479. {
  4480. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4481. }
  4482. }
  4483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4484. }
  4485. else
  4486. {
  4487. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4488. {
  4489. tempIndex = 2;
  4490. }
  4491. else
  4492. {
  4493. tempIndex = gun_index;
  4494. }
  4495. for (int index = 0; index < AC_QUANTITY; index++)
  4496. {
  4497. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4498. {
  4499. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4500. }
  4501. } // END OF FOR AC_QUANTITY
  4502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4503. }
  4504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4509. }
  4510. //====================== End SoC ================================
  4511. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4512. {
  4513. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4514. 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))
  4515. {
  4516. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4517. {
  4518. tempIndex = ((gun_index==2) ? 1: 0);
  4519. }
  4520. else
  4521. {
  4522. tempIndex = gun_index;
  4523. }
  4524. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4525. {
  4526. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4527. {
  4528. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4529. {
  4530. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4531. }
  4532. }
  4533. }
  4534. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4535. {
  4536. for (int index = 0; index < CCS_QUANTITY; index++)
  4537. {
  4538. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4539. {
  4540. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4541. }
  4542. }
  4543. }
  4544. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4545. {
  4546. for (int index = 0; index < GB_QUANTITY; index++)
  4547. {
  4548. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4549. {
  4550. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4551. }
  4552. }
  4553. }
  4554. else if(gunType[gun_index] == GUN_TYPE_DO)
  4555. {
  4556. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4557. {
  4558. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4559. {
  4560. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4561. }
  4562. }
  4563. }
  4564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4570. } // END FOR DC CASE
  4571. }
  4572. // ================================= Current.Import L2 ===============================================
  4573. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4574. {
  4575. // AC 3 phse L2 current
  4576. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4577. {
  4578. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4579. {
  4580. tempIndex = 2;
  4581. }
  4582. else
  4583. {
  4584. tempIndex = gun_index;
  4585. }
  4586. for (int index = 0; index < AC_QUANTITY; index++)
  4587. {
  4588. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4589. {
  4590. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4591. }
  4592. }// End of for AC_QUANTITY
  4593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4594. }
  4595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4600. }
  4601. // ================================= Current.Import L3 ===============================================
  4602. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4603. {
  4604. // AC 3 phse L3 current
  4605. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4606. {
  4607. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4608. {
  4609. tempIndex = 2;
  4610. }
  4611. else
  4612. {
  4613. tempIndex = gun_index;
  4614. }
  4615. for (int index = 0; index < AC_QUANTITY; index++)
  4616. {
  4617. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4618. {
  4619. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4620. }
  4621. }// End of for AC_QUANTITY
  4622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4623. }
  4624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4626. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4629. }
  4630. //============================ Voltage L2 ====================================
  4631. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4632. {
  4633. // AC 3 phse L2 voltage
  4634. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4635. {
  4636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4637. {
  4638. tempIndex = 2;
  4639. }
  4640. else
  4641. {
  4642. tempIndex = gun_index;
  4643. }
  4644. for (int index = 0; index < AC_QUANTITY; index++)
  4645. {
  4646. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4647. {
  4648. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4649. }
  4650. } // END OF FOR AC_QUANTITY
  4651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4652. }
  4653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4658. }
  4659. //============================ Voltage L3 ====================================
  4660. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4661. {
  4662. // AC 3 phse L3 voltage
  4663. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4664. {
  4665. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4666. {
  4667. tempIndex = 2;
  4668. }
  4669. else
  4670. {
  4671. tempIndex = gun_index;
  4672. }
  4673. for (int index = 0; index < AC_QUANTITY; index++)
  4674. {
  4675. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4676. {
  4677. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4678. }
  4679. } // END OF FOR AC_QUANTITY
  4680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4681. }
  4682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4687. }
  4688. //====================== Start SoC ================================
  4689. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4690. {
  4691. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4692. 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))
  4693. {
  4694. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4695. {
  4696. tempIndex = ((gun_index==2) ? 1: 0);
  4697. }
  4698. else
  4699. {
  4700. tempIndex = gun_index;
  4701. }
  4702. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4703. {
  4704. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4705. {
  4706. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4707. {
  4708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4709. }
  4710. }
  4711. }
  4712. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4713. {
  4714. for (int index = 0; index < CCS_QUANTITY; index++)
  4715. {
  4716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4717. {
  4718. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4719. }
  4720. }
  4721. }
  4722. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4723. {
  4724. for (int index = 0; index < GB_QUANTITY; index++)
  4725. {
  4726. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4727. {
  4728. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4729. }
  4730. }
  4731. }
  4732. else if(gunType[gun_index] == GUN_TYPE_DO)
  4733. {
  4734. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4735. {
  4736. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4737. {
  4738. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4739. }
  4740. }
  4741. }
  4742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4748. } // END FOR DC CASE
  4749. }
  4750. //================================================ Message create ====================================================
  4751. json_object *StopTransaction = json_object_new_object();
  4752. json_object *transactionDatas = json_object_new_array();
  4753. json_object *sampledValues = json_object_new_array();
  4754. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4755. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4756. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4757. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4758. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4759. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4760. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4761. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4762. {
  4763. json_object *transactionData = json_object_new_object();
  4764. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4765. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4766. {
  4767. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4768. {
  4769. json_object *sampledValue = json_object_new_object();
  4770. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4771. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4772. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4773. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4774. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4775. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4776. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4777. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4778. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4779. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4780. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4781. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4782. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4783. json_object_array_add(sampledValues, sampledValue);
  4784. }
  4785. }
  4786. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4787. json_object_array_add(transactionDatas, transactionData);
  4788. }
  4789. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4790. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4791. ,MESSAGE_TYPE_CALL
  4792. ,guid
  4793. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4794. json_object_put(StopTransaction);
  4795. #if 1 // for TempStopTransaction
  4796. //Delete TempStopTransaction
  4797. if((access(TempStopTransaction,F_OK))!=-1)
  4798. {
  4799. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4800. }
  4801. #endif
  4802. #if 1
  4803. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4804. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4805. {
  4806. result = PASS;
  4807. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4808. }
  4809. #endif
  4810. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4811. OCPP_insert_transaction_msg(NO, queuedata);
  4812. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4813. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4814. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4815. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4816. {
  4817. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4818. }
  4819. //for test
  4820. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4821. return result;
  4822. }
  4823. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4824. {
  4825. mtrace();
  4826. int result = FAIL;
  4827. char guid[37]={0};
  4828. char tempdata[65]={0};
  4829. int tempIndex = 0;
  4830. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4831. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4832. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4833. //set value
  4834. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4835. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  4836. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4837. -1);
  4838. random_uuid(guid);
  4839. //UTC Date time
  4840. struct timeval tmnow;
  4841. struct tm *tm;
  4842. char buf[28];//, usec_buf[6];
  4843. gettimeofday(&tmnow, NULL);
  4844. time_t t;
  4845. t = time(NULL);
  4846. /*UTC time and date*/
  4847. tm = gmtime(&t);
  4848. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4849. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4850. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4851. //********************************(1)Current.Import L1************************************************/
  4852. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4853. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4854. (dataType == ReadingContext_Trigger))
  4855. {
  4856. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4857. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4858. {
  4859. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4860. {
  4861. tempIndex = ((gun_index==2) ? 1: 0);
  4862. }
  4863. else
  4864. {
  4865. tempIndex = gun_index;
  4866. }
  4867. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4868. {
  4869. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4870. {
  4871. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4872. }
  4873. }
  4874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4875. }
  4876. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4877. {
  4878. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4879. {
  4880. tempIndex = ((gun_index==2) ? 1: 0);
  4881. }
  4882. else
  4883. {
  4884. tempIndex = gun_index;
  4885. }
  4886. for (int index = 0; index < CCS_QUANTITY; index++)
  4887. {
  4888. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4889. {
  4890. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4891. }
  4892. }
  4893. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4894. }
  4895. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4896. {
  4897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4898. {
  4899. tempIndex = ((gun_index==2) ? 1: 0);
  4900. }
  4901. else
  4902. {
  4903. tempIndex = gun_index;
  4904. }
  4905. for (int index = 0; index < GB_QUANTITY; index++)
  4906. {
  4907. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4908. {
  4909. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4910. }
  4911. }
  4912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4913. }
  4914. else if(gunType[gun_index] == GUN_TYPE_DO)
  4915. {
  4916. tempIndex = gun_index;
  4917. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4918. {
  4919. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4920. {
  4921. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4922. }
  4923. }
  4924. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4925. }
  4926. else
  4927. {
  4928. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4929. {
  4930. tempIndex = 2;
  4931. }
  4932. else
  4933. {
  4934. tempIndex = gun_index;
  4935. }
  4936. for (int index = 0; index < AC_QUANTITY; index++)
  4937. {
  4938. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4939. {
  4940. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4941. }
  4942. }
  4943. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4944. }
  4945. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4946. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4947. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4948. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4949. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4950. }
  4951. //********************************(2)Energy.Active.Import.Register ************************************************/
  4952. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4953. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4954. (dataType == ReadingContext_Trigger))
  4955. {
  4956. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4957. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4958. {
  4959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4960. {
  4961. tempIndex = ((gun_index==2) ? 1: 0);
  4962. }
  4963. else
  4964. {
  4965. tempIndex = gun_index;
  4966. }
  4967. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4968. {
  4969. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4970. {
  4971. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4972. }
  4973. }
  4974. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4975. }
  4976. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4977. {
  4978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4979. {
  4980. tempIndex = ((gun_index==2) ? 1: 0);
  4981. }
  4982. else
  4983. {
  4984. tempIndex = gun_index;
  4985. }
  4986. for (int index = 0; index < CCS_QUANTITY; index++)
  4987. {
  4988. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4989. {
  4990. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4991. }
  4992. }
  4993. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4994. }
  4995. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4996. {
  4997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4998. {
  4999. tempIndex = ((gun_index==2) ? 1: 0);
  5000. }
  5001. else
  5002. {
  5003. tempIndex = gun_index;
  5004. }
  5005. for (int index = 0; index < GB_QUANTITY; index++)
  5006. {
  5007. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5008. {
  5009. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5010. }
  5011. }
  5012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5013. }
  5014. else if(gunType[gun_index] == GUN_TYPE_DO)
  5015. {
  5016. tempIndex = gun_index;
  5017. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5018. {
  5019. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5020. {
  5021. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5022. }
  5023. }
  5024. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5025. }
  5026. else
  5027. {
  5028. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5029. {
  5030. tempIndex = 2;
  5031. }
  5032. else
  5033. {
  5034. tempIndex = gun_index;
  5035. }
  5036. for (int index = 0; index < AC_QUANTITY; index++)
  5037. {
  5038. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5039. {
  5040. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5041. }
  5042. }
  5043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5044. }
  5045. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5046. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5047. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5048. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5049. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5050. }
  5051. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5052. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5053. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5054. (dataType == ReadingContext_Trigger))
  5055. {
  5056. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5057. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5058. {
  5059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5060. {
  5061. tempIndex = ((gun_index==2) ? 1: 0);
  5062. }
  5063. else
  5064. {
  5065. tempIndex = gun_index;
  5066. }
  5067. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5068. {
  5069. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5070. {
  5071. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5072. }
  5073. } // END OF FOR CHAdeMO_QUANTITY
  5074. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5075. }
  5076. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5077. {
  5078. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5079. {
  5080. tempIndex = ((gun_index==2) ? 1: 0);
  5081. }
  5082. else
  5083. {
  5084. tempIndex = gun_index;
  5085. }
  5086. for (int index = 0; index < CCS_QUANTITY; index++)
  5087. {
  5088. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5089. {
  5090. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5091. }
  5092. } // END OF CCS_QUANTITY
  5093. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5094. }
  5095. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5096. {
  5097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5098. {
  5099. tempIndex = ((gun_index==2) ? 1: 0);
  5100. }
  5101. else
  5102. {
  5103. tempIndex = gun_index;
  5104. }
  5105. for (int index = 0; index < GB_QUANTITY; index++)
  5106. {
  5107. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5108. {
  5109. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5110. }
  5111. } // END OF GB_QUANTITY
  5112. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5113. }
  5114. else if(gunType[gun_index] == GUN_TYPE_DO)
  5115. {
  5116. tempIndex = gun_index;
  5117. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5118. {
  5119. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5120. {
  5121. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5122. }
  5123. }
  5124. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5125. }
  5126. else
  5127. {
  5128. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5129. {
  5130. tempIndex = 2;
  5131. }
  5132. else
  5133. {
  5134. tempIndex = gun_index;
  5135. }
  5136. for (int index = 0; index < AC_QUANTITY; index++)
  5137. {
  5138. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5139. {
  5140. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5141. }
  5142. }
  5143. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5144. }
  5145. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5146. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5147. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5148. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5149. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5150. }
  5151. //********************************(4)Power.Active.Import************************************************/
  5152. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5153. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5154. (dataType == ReadingContext_Trigger))
  5155. {
  5156. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5157. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5158. {
  5159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5160. {
  5161. tempIndex = ((gun_index==2) ? 1: 0);
  5162. }
  5163. else
  5164. {
  5165. tempIndex = gun_index;
  5166. }
  5167. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5168. {
  5169. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5170. {
  5171. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5172. }
  5173. } // END OF FOR
  5174. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5175. }
  5176. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5177. {
  5178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5179. {
  5180. tempIndex = ((gun_index==2) ? 1: 0);
  5181. }
  5182. else
  5183. {
  5184. tempIndex = gun_index;
  5185. }
  5186. for (int index = 0; index < CCS_QUANTITY; index++)
  5187. {
  5188. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5189. {
  5190. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5191. }
  5192. }
  5193. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5194. }
  5195. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5196. {
  5197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5198. {
  5199. tempIndex = ((gun_index==2) ? 1: 0);
  5200. }
  5201. else
  5202. {
  5203. tempIndex = gun_index;
  5204. }
  5205. for (int index = 0; index < GB_QUANTITY; index++)
  5206. {
  5207. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5208. {
  5209. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5210. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5211. }
  5212. }
  5213. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5214. }
  5215. else if(gunType[gun_index] == GUN_TYPE_DO)
  5216. {
  5217. tempIndex = gun_index;
  5218. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5219. {
  5220. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5221. {
  5222. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5223. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5224. }
  5225. }
  5226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5227. }
  5228. else
  5229. {
  5230. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5231. {
  5232. tempIndex = 2;
  5233. }
  5234. else
  5235. {
  5236. tempIndex = gun_index;
  5237. }
  5238. for (int index = 0; index < AC_QUANTITY; index++)
  5239. {
  5240. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5241. {
  5242. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5243. }
  5244. }
  5245. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5246. }
  5247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5251. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5252. }
  5253. //***********************************************(5)VOLTAGE L1******************************************************/
  5254. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5255. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5256. (dataType == ReadingContext_Trigger))
  5257. {
  5258. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5259. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5260. {
  5261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5262. {
  5263. tempIndex = ((gun_index==2) ? 1: 0);
  5264. }
  5265. else
  5266. {
  5267. tempIndex = gun_index;
  5268. }
  5269. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5270. {
  5271. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5272. {
  5273. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5274. }
  5275. }
  5276. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5277. }
  5278. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5279. {
  5280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5281. {
  5282. tempIndex = ((gun_index==2) ? 1: 0);
  5283. }
  5284. else
  5285. {
  5286. tempIndex = gun_index;
  5287. }
  5288. for (int index = 0; index < CCS_QUANTITY; index++)
  5289. {
  5290. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5291. {
  5292. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5293. }
  5294. }
  5295. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5296. }
  5297. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5298. {
  5299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5300. {
  5301. tempIndex = ((gun_index==2) ? 1: 0);
  5302. }
  5303. else
  5304. {
  5305. tempIndex = gun_index;
  5306. }
  5307. for (int index = 0; index < GB_QUANTITY; index++)
  5308. {
  5309. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5310. {
  5311. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5312. }
  5313. }
  5314. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5315. }
  5316. else if(gunType[gun_index] == GUN_TYPE_DO)
  5317. {
  5318. tempIndex = gun_index;
  5319. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5320. {
  5321. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5322. {
  5323. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5324. }
  5325. }
  5326. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5327. }
  5328. else
  5329. {
  5330. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5331. {
  5332. tempIndex = 2;
  5333. }
  5334. else
  5335. {
  5336. tempIndex = gun_index;
  5337. }
  5338. for (int index = 0; index < AC_QUANTITY; index++)
  5339. {
  5340. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5341. {
  5342. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5343. }
  5344. }
  5345. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5346. }
  5347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5348. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5349. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5352. }
  5353. //***********************************************(6)SOC******************************************************/
  5354. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5355. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5356. (dataType == ReadingContext_Trigger))
  5357. {
  5358. 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))
  5359. {
  5360. //idx_sample=5;
  5361. //sampledValue = NULL;
  5362. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5363. {
  5364. tempIndex = ((gun_index==2) ? 1: 0);
  5365. }
  5366. else
  5367. {
  5368. tempIndex = gun_index;
  5369. }
  5370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5371. {
  5372. //tempIndex = ((gun_index==2) ? 1: 0);
  5373. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5374. {
  5375. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5376. {
  5377. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5378. }
  5379. }
  5380. }
  5381. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5382. {
  5383. //tempIndex = ((gun_index==2) ? 1: 0);
  5384. for (int index = 0; index < CCS_QUANTITY; index++)
  5385. {
  5386. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5387. {
  5388. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5389. }
  5390. }
  5391. }
  5392. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5393. {
  5394. //tempIndex = ((gun_index==2) ? 1: 0);
  5395. for (int index = 0; index < GB_QUANTITY; index++)
  5396. {
  5397. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5398. {
  5399. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5400. }
  5401. }
  5402. }
  5403. else if(gunType[gun_index] == GUN_TYPE_DO)
  5404. {
  5405. //tempIndex = ((gun_index==2) ? 1: 0);
  5406. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5407. {
  5408. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5409. {
  5410. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5411. }
  5412. }
  5413. }
  5414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5420. }
  5421. }
  5422. //********************************(7)Current.Import L2************************************************/
  5423. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5424. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5425. (dataType == ReadingContext_Trigger))
  5426. {
  5427. // Only for AC 3 phase
  5428. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5429. {
  5430. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5431. {
  5432. tempIndex = 2;
  5433. }
  5434. else
  5435. {
  5436. tempIndex = gun_index;
  5437. }
  5438. for (int index = 0; index < AC_QUANTITY; index++)
  5439. {
  5440. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5441. {
  5442. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5443. }
  5444. }
  5445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5446. }
  5447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5452. }
  5453. //********************************(8)Current.Import L3************************************************/
  5454. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5455. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5456. (dataType == ReadingContext_Trigger))
  5457. {
  5458. // Only for AC 3 phase
  5459. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5460. {
  5461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5462. {
  5463. tempIndex = 2;
  5464. }
  5465. else
  5466. {
  5467. tempIndex = gun_index;
  5468. }
  5469. for (int index = 0; index < AC_QUANTITY; index++)
  5470. {
  5471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5472. {
  5473. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5474. }
  5475. }
  5476. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5477. }
  5478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5479. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5483. }
  5484. //***********************************************(9)VOLTAGE L2******************************************************/
  5485. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5486. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5487. (dataType == ReadingContext_Trigger))
  5488. {
  5489. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5490. {
  5491. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5492. {
  5493. tempIndex = 2;
  5494. }
  5495. else
  5496. {
  5497. tempIndex = gun_index;
  5498. }
  5499. for (int index = 0; index < AC_QUANTITY; index++)
  5500. {
  5501. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5502. {
  5503. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5504. }
  5505. }
  5506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5507. }
  5508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5513. }
  5514. //***********************************************(10)VOLTAGE L3******************************************************/
  5515. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5516. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5517. (dataType == ReadingContext_Trigger))
  5518. {
  5519. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5520. {
  5521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5522. {
  5523. tempIndex = 2;
  5524. }
  5525. else
  5526. {
  5527. tempIndex = gun_index;
  5528. }
  5529. for (int index = 0; index < AC_QUANTITY; index++)
  5530. {
  5531. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5532. {
  5533. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5534. }
  5535. }
  5536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5537. }
  5538. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5539. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5540. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5543. }
  5544. // Message create ====================================================================================================
  5545. if(TRUE)
  5546. {
  5547. json_object *MeterValueReq = json_object_new_object();
  5548. json_object *MeterValues = json_object_new_array();
  5549. json_object *sampledValues = json_object_new_array();
  5550. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5551. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5552. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5553. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5554. {
  5555. json_object *MeterValue = json_object_new_object();
  5556. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5557. {
  5558. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5559. {
  5560. json_object *sampledValue = json_object_new_object();
  5561. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5562. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5563. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5564. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5565. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5566. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5567. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5568. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5569. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5570. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5571. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5572. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5573. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5574. json_object_array_add(sampledValues, sampledValue);
  5575. }
  5576. }
  5577. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5578. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5579. json_object_array_add(MeterValues, MeterValue);
  5580. }
  5581. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5582. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5583. ,gun_index + 1
  5584. ,MESSAGE_TYPE_CALL
  5585. ,guid
  5586. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5587. json_object_put(MeterValueReq);
  5588. }
  5589. // Put request guid to hash map
  5590. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5591. 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*/)
  5592. {
  5593. result = PASS;
  5594. //DEBUG_INFO("MeterValues mapitem pass\n");
  5595. }
  5596. if((dataType != ReadingContext_Trigger) &&
  5597. (dataType != ReadingContext_Sample_Clock) &&
  5598. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5599. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5600. else
  5601. {
  5602. if(FirstHeartBeat)
  5603. LWS_Send(queuedata +2);
  5604. }
  5605. return result;
  5606. }
  5607. int sendLogStatusNotificationRequest(char *status)
  5608. {
  5609. mtrace();
  5610. int result = PASS;
  5611. char message[4096]={0};
  5612. char guid[37]={0};
  5613. char tempdata[128]={0};
  5614. json_object *LogStatusNotification = json_object_new_object();
  5615. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5616. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5617. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5618. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5619. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5620. random_uuid(guid);
  5621. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5622. json_object_put(LogStatusNotification);
  5623. LWS_Send(message);
  5624. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5625. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5626. {
  5627. result = PASS;
  5628. }
  5629. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5630. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5631. return result;
  5632. }
  5633. int sendSecurityEventNotificationRequest()
  5634. {
  5635. mtrace();
  5636. int result = PASS;
  5637. char message[4096]={0};
  5638. char guid[37]={0};
  5639. char tempdata[128]={0};
  5640. json_object *SecurityEventNotification = json_object_new_object();
  5641. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5642. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5643. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5644. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5645. random_uuid(guid);
  5646. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5647. json_object_put(SecurityEventNotification);
  5648. LWS_Send(message);
  5649. sprintf(tempdata, "SecurityEventNotification,0");
  5650. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5651. {
  5652. result = PASS;
  5653. }
  5654. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5655. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5656. return result;
  5657. }
  5658. int sendSignCertificateRequest()
  5659. {
  5660. mtrace();
  5661. int result = PASS;
  5662. char message[4096]={0};
  5663. char guid[37]={0};
  5664. char tempdata[128]={0};
  5665. json_object *SignCertificate = json_object_new_object();
  5666. DEBUG_INFO("sendSignCertificateRequest...\n");
  5667. // Read csr file content
  5668. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5669. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5670. char *line = NULL;
  5671. size_t len = 0;
  5672. while(getline(&line, &len, fp) != -1)
  5673. {
  5674. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5675. {
  5676. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5677. }
  5678. }
  5679. fclose(fp);
  5680. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5681. random_uuid(guid);
  5682. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5683. json_object_put(SignCertificate);
  5684. LWS_Send(message);
  5685. sprintf(tempdata, "SignCertificate,0");
  5686. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5687. {
  5688. result = PASS;
  5689. }
  5690. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5691. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5692. return result;
  5693. }
  5694. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5695. {
  5696. mtrace();
  5697. int result = PASS;
  5698. char message[110]={0};
  5699. char guid[37]={0};
  5700. char tempdata[65]={0};
  5701. json_object *FirmwareStatusNotification = json_object_new_object();
  5702. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5703. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5704. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5705. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5706. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5707. random_uuid(guid);
  5708. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5709. json_object_put(FirmwareStatusNotification);
  5710. LWS_Send(message);
  5711. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5712. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5713. {
  5714. result = PASS;
  5715. }
  5716. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5717. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5718. return result;
  5719. }
  5720. //==========================================
  5721. // send confirm routine
  5722. //==========================================
  5723. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5724. {
  5725. mtrace();
  5726. int result = FAIL;
  5727. char message[100]={0};
  5728. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5729. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5730. LWS_Send(message);
  5731. result = TRUE;
  5732. return result;
  5733. }
  5734. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5735. {
  5736. mtrace();
  5737. int result = FAIL;
  5738. char message[100]={0};
  5739. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5740. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5741. LWS_Send(message);
  5742. result = TRUE;
  5743. return result;
  5744. }
  5745. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5746. {
  5747. mtrace();
  5748. int result = FAIL;
  5749. char message[100]={0};
  5750. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5751. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5752. LWS_Send(message);
  5753. result = TRUE;
  5754. return result;
  5755. }
  5756. int sendClearCacheConfirmation(char *uuid,char *payload)
  5757. {
  5758. mtrace();
  5759. int result = FAIL;
  5760. char message[500]={0};
  5761. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5762. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5763. LWS_Send(message);
  5764. return result;
  5765. }
  5766. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5767. {
  5768. mtrace();
  5769. int result = FAIL;
  5770. char message[500]={0};
  5771. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5772. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5773. LWS_Send(message);
  5774. return result;
  5775. }
  5776. int sendDataTransferConfirmation(char *uuid,char *payload)
  5777. {
  5778. mtrace();
  5779. char statusStr[20]={0};
  5780. char dataStr[10]={0};
  5781. char sstr[20]={0};
  5782. int c = 0;
  5783. char *loc;
  5784. int result = FAIL;
  5785. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5786. /**********************status**************************/
  5787. loc = strstr(payload, "status");
  5788. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5789. c = 0;
  5790. while (loc[3+strlen("status")+c] != '\"')
  5791. {
  5792. sstr[c] = loc[3+strlen("status")+c];
  5793. c++;
  5794. }
  5795. sstr[c] = '\0';
  5796. strcpy(statusStr, sstr);
  5797. /**********************data**************************/
  5798. loc = strstr(payload, "data");
  5799. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5800. c = 0;
  5801. while (loc[3+strlen("data")+c] != '\"')
  5802. {
  5803. sstr[c] = loc[3+strlen("data")+c];
  5804. c++;
  5805. }
  5806. sstr[c] = '\0';
  5807. strcpy(dataStr, sstr);
  5808. return result;
  5809. }
  5810. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5811. {
  5812. mtrace();
  5813. int result = FAIL;
  5814. char message[1000]={0};
  5815. int CompositeScheduleIndex = 0;
  5816. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5817. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5818. if(nPeriod == 0)
  5819. {
  5820. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5821. {
  5822. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5823. ,MESSAGE_TYPE_CALLRESULT
  5824. ,uuid
  5825. ,payload
  5826. ,connectorIdInt);
  5827. }
  5828. else
  5829. {
  5830. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5831. ,MESSAGE_TYPE_CALLRESULT
  5832. ,uuid
  5833. ,payload
  5834. ,connectorIdInt
  5835. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5836. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5837. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5838. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5839. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5840. }
  5841. }
  5842. else
  5843. {
  5844. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5845. ,MESSAGE_TYPE_CALLRESULT
  5846. ,uuid
  5847. ,payload
  5848. ,connectorIdInt
  5849. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5850. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5851. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5852. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5853. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5854. {
  5855. if (idx_sample == 0)
  5856. {
  5857. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5858. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5859. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5860. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5861. }
  5862. else
  5863. {
  5864. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5865. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5866. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5867. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5868. }
  5869. }
  5870. sprintf(message + strlen(message), "]}}]");
  5871. }
  5872. LWS_Send(message);
  5873. result = TRUE;
  5874. return result;
  5875. }
  5876. int sendGetConfigurationConfirmation(char *uuid)
  5877. {
  5878. mtrace();
  5879. int result = FAIL;
  5880. int MaxKeySupported = 0;
  5881. int sentConfigurationNumber= 0;
  5882. int sentunConfigurationNumber= 0;
  5883. char message[4000]={0};
  5884. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5885. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5886. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5887. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5888. ,MESSAGE_TYPE_CALLRESULT
  5889. ,uuid );
  5890. //configuration key
  5891. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5892. {
  5893. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5894. {
  5895. if (sentConfigurationNumber == 0)
  5896. {
  5897. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5898. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5899. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5900. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5901. }
  5902. else
  5903. {
  5904. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5905. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5906. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5907. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5908. }
  5909. sentConfigurationNumber = sentConfigurationNumber + 1;
  5910. }
  5911. }
  5912. sprintf(message + strlen(message), "]");
  5913. if(UnknownKeynum != 0)
  5914. {
  5915. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5916. //unkown key
  5917. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5918. {
  5919. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5920. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5921. if(sentunConfigurationNumber == 0)
  5922. {
  5923. sprintf(message + strlen(message), "\"%s\""
  5924. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5925. }
  5926. else
  5927. {
  5928. sprintf(message + strlen(message), ",\"%s\""
  5929. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5930. }
  5931. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5932. }
  5933. sprintf(message + strlen(message), "]");
  5934. }
  5935. sprintf(message + strlen(message), "}]");
  5936. LWS_Send(message);
  5937. return result;
  5938. }
  5939. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5940. {
  5941. mtrace();
  5942. int result = FAIL;
  5943. char message[400]={0};
  5944. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5945. if(strcmp(payload,"")==0)
  5946. {
  5947. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5948. }
  5949. else
  5950. {
  5951. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5952. }
  5953. LWS_Send(message);
  5954. result = TRUE;
  5955. return result;
  5956. }
  5957. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5958. {
  5959. mtrace();
  5960. int result = FAIL;
  5961. char message[80]={0};
  5962. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5963. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5964. LWS_Send(message);
  5965. result = TRUE;
  5966. return result;
  5967. }
  5968. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5969. {
  5970. mtrace();
  5971. int result = FAIL;
  5972. char message[80]={0};
  5973. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5974. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5975. LWS_Send(message);
  5976. result = TRUE;
  5977. return result;
  5978. }
  5979. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5980. {
  5981. mtrace();
  5982. int result = FAIL;
  5983. char message[80]={0};
  5984. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5985. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5986. LWS_Send(message);
  5987. result = TRUE;
  5988. return result;
  5989. }
  5990. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5991. {
  5992. mtrace();
  5993. int result = FAIL;
  5994. char message[80]={0};
  5995. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5996. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5997. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5998. LWS_Send(message);
  5999. result = TRUE;
  6000. return result;
  6001. }
  6002. int sendResetConfirmation(char *uuid,char *payload)
  6003. {
  6004. mtrace();
  6005. int result = FAIL;
  6006. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6007. char message[80]={0};
  6008. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6009. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6010. LWS_Send(message);
  6011. result = TRUE;
  6012. return result;
  6013. }
  6014. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6015. {
  6016. mtrace();
  6017. int result = FAIL;
  6018. char message[500]={0};
  6019. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6020. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6021. LWS_Send(message);
  6022. result = TRUE;
  6023. return result;
  6024. }
  6025. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6026. {
  6027. mtrace();
  6028. int result = FAIL;
  6029. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6030. char message[80]={0};
  6031. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6032. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6033. LWS_Send(message);
  6034. result = TRUE;
  6035. return result;
  6036. }
  6037. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6038. {
  6039. mtrace();
  6040. int result = FAIL;
  6041. char message[80]={0};
  6042. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6043. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6044. LWS_Send(message);
  6045. result = TRUE;
  6046. return result;
  6047. }
  6048. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6049. {
  6050. mtrace();
  6051. int result = FAIL;
  6052. char message[80]={0};
  6053. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6054. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6055. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6056. LWS_Send(message);
  6057. result = TRUE;
  6058. return result;
  6059. }
  6060. int sendUpdateFirmwareConfirmation(char *uuid)
  6061. {
  6062. mtrace();
  6063. int result = FAIL;
  6064. char message[60]={0};
  6065. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6066. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6067. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6068. LWS_Send(message);
  6069. result = TRUE;
  6070. return result;
  6071. }
  6072. int sendCertificateSignedConfirmation(char *uuid)
  6073. {
  6074. mtrace();
  6075. int result = PASS;
  6076. char message[4096]={0};
  6077. json_object *CertificateSigned = json_object_new_object();
  6078. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6079. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6080. sprintf(message,"[%d,\"%s\",%s]"
  6081. ,MESSAGE_TYPE_CALLRESULT
  6082. ,uuid
  6083. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6084. json_object_put(CertificateSigned);
  6085. LWS_Send(message);
  6086. return result;
  6087. }
  6088. int sendDeleteCertificateConfirmation(char *uuid)
  6089. {
  6090. mtrace();
  6091. int result = PASS;
  6092. char message[4096]={0};
  6093. json_object *DeleteCertificate = json_object_new_object();
  6094. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6095. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6096. sprintf(message,"[%d,\"%s\",%s]"
  6097. ,MESSAGE_TYPE_CALLRESULT
  6098. ,uuid
  6099. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6100. json_object_put(DeleteCertificate);
  6101. LWS_Send(message);
  6102. return result;
  6103. }
  6104. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6105. {
  6106. mtrace();
  6107. int result = PASS;
  6108. char message[4096]={0};
  6109. json_object *ExtendedTriggerMessage = json_object_new_object();
  6110. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6111. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6112. sprintf(message,"[%d,\"%s\",%s]"
  6113. ,MESSAGE_TYPE_CALLRESULT
  6114. ,uuid
  6115. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6116. json_object_put(ExtendedTriggerMessage);
  6117. LWS_Send(message);
  6118. return result;
  6119. }
  6120. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6121. {
  6122. mtrace();
  6123. int result = PASS;
  6124. char message[4096]={0};
  6125. json_object *GetInstalledCertificateIds = json_object_new_object();
  6126. json_object *certificateHashDataDatas = json_object_new_array();
  6127. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6128. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6129. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6130. {
  6131. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6132. {
  6133. json_object *certificateHashData = json_object_new_object();
  6134. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6135. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6136. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6137. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6138. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6139. }
  6140. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6141. }
  6142. else
  6143. {
  6144. json_object_put(certificateHashDataDatas);
  6145. }
  6146. sprintf(message,"[%d,\"%s\",%s]"
  6147. ,MESSAGE_TYPE_CALLRESULT
  6148. ,uuid
  6149. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6150. json_object_put(GetInstalledCertificateIds);
  6151. LWS_Send(message);
  6152. return result;
  6153. }
  6154. int sendGetLogConfirmation(char *uuid)
  6155. {
  6156. mtrace();
  6157. int result = PASS;
  6158. char message[4096]={0};
  6159. json_object *GetLog = json_object_new_object();
  6160. DEBUG_INFO("sendGetLogConfirmation...\n");
  6161. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6162. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6163. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6164. sprintf(message,"[%d,\"%s\",%s]"
  6165. ,MESSAGE_TYPE_CALLRESULT
  6166. ,uuid
  6167. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6168. json_object_put(GetLog);
  6169. LWS_Send(message);
  6170. return result;
  6171. }
  6172. int sendInstallCertificateConfirmation(char *uuid)
  6173. {
  6174. mtrace();
  6175. int result = PASS;
  6176. char message[4096]={0};
  6177. json_object *InstallCertificate = json_object_new_object();
  6178. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6179. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6180. sprintf(message,"[%d,\"%s\",%s]"
  6181. ,MESSAGE_TYPE_CALLRESULT
  6182. ,uuid
  6183. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6184. json_object_put(InstallCertificate);
  6185. LWS_Send(message);
  6186. return result;
  6187. }
  6188. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6189. {
  6190. mtrace();
  6191. int result = PASS;
  6192. char message[4096]={0};
  6193. json_object *SignedUpdateFirmware = json_object_new_object();
  6194. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6195. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6196. sprintf(message,"[%d,\"%s\",%s]"
  6197. ,MESSAGE_TYPE_CALLRESULT
  6198. ,uuid
  6199. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6200. json_object_put(SignedUpdateFirmware);
  6201. LWS_Send(message);
  6202. return result;
  6203. }
  6204. int sendUnknownConfirmation(char *uuid)
  6205. {
  6206. mtrace();
  6207. int result = PASS;
  6208. char message[256]={0};
  6209. DEBUG_INFO("sendUnknownConfirmation...\n");
  6210. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6211. LWS_Send(message);
  6212. return result;
  6213. }
  6214. //==========================================
  6215. // Handle server request routine Start
  6216. //==========================================
  6217. int handleCancelReservationRequest(char *uuid, char *payload)
  6218. {
  6219. mtrace();
  6220. int result = FAIL;
  6221. int gunNO = 0;
  6222. int reservationIdInt = -1;
  6223. char comfirmstr[20];
  6224. DEBUG_INFO("handleCancelReservationRequest...\n");
  6225. json_object *CancelReservation;
  6226. CancelReservation = json_tokener_parse(payload);
  6227. if(!is_error(CancelReservation))
  6228. {
  6229. // Required data
  6230. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6231. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6232. }
  6233. json_object_put(CancelReservation);
  6234. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6235. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6236. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6237. if(reservationIdInt != -1)
  6238. {
  6239. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6240. //check Transaction active
  6241. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6243. {
  6244. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6245. {
  6246. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6247. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6248. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6249. {
  6250. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6251. }
  6252. else
  6253. {
  6254. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6255. }
  6256. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6257. goto end;
  6258. }
  6259. }
  6260. for (int index = 0; index < CCS_QUANTITY; index++)
  6261. {
  6262. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6263. {
  6264. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6265. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6266. if(gunType[2] == GUN_TYPE_CCS)
  6267. {
  6268. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6269. }
  6270. else
  6271. {
  6272. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6273. }
  6274. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6275. goto end;
  6276. }
  6277. }
  6278. for (int index = 0; index < GB_QUANTITY; index++)
  6279. {
  6280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6281. {
  6282. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6283. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6284. if(gunType[2] == GUN_TYPE_GBT)
  6285. {
  6286. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6287. }
  6288. else
  6289. {
  6290. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6291. }
  6292. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6293. goto end;
  6294. }
  6295. }
  6296. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6297. {
  6298. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6299. {
  6300. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6301. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6302. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6303. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6304. goto end;
  6305. }
  6306. }
  6307. for (int index = 0; index < AC_QUANTITY; index++)
  6308. {
  6309. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6310. {
  6311. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6312. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6314. {
  6315. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6316. }
  6317. else
  6318. {
  6319. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6320. }
  6321. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6322. goto end;
  6323. }
  6324. }
  6325. }
  6326. //The reservationId does NOT match the reservationId
  6327. sendCancelReservationConfirmation(uuid, comfirmstr);
  6328. end:
  6329. // Fill in ocpp packet uuid
  6330. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6331. return result;
  6332. }
  6333. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6334. {
  6335. mtrace();
  6336. int result = FAIL;
  6337. int gunIndex = 0;
  6338. char typeStr[16]={0};
  6339. char comfirmstr[20];
  6340. int specificId = FALSE;
  6341. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6342. json_object *ChangeAvailability;
  6343. ChangeAvailability = json_tokener_parse(payload);
  6344. if(!is_error(ChangeAvailability))
  6345. {
  6346. // Required data
  6347. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6348. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6349. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6350. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6351. }
  6352. json_object_put(ChangeAvailability);
  6353. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6354. {
  6355. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6356. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6357. }
  6358. else if(gunIndex == 0)
  6359. {
  6360. for(int i=0; i < gunTotalNumber; i++)
  6361. {
  6362. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6363. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6364. }
  6365. }
  6366. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6367. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6368. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6369. {
  6370. specificId = TRUE;
  6371. }
  6372. if(specificId == FALSE)
  6373. goto end;
  6374. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6375. {
  6376. //----------------------gunIndex is 0 ------------------------------------------------//
  6377. if(gunIndex == 0)
  6378. {
  6379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6380. {
  6381. for(int i=0; i < gunTotalNumber; i++)
  6382. {
  6383. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6384. {
  6385. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6386. {
  6387. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6388. {
  6389. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6390. goto end;
  6391. }
  6392. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6393. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6394. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6395. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6396. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6397. {
  6398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6399. goto end;
  6400. }
  6401. }
  6402. }//END FOR CHAdeMO_QUANTITY
  6403. for (int index = 0; index < CCS_QUANTITY; index++)
  6404. {
  6405. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6406. {
  6407. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6408. {
  6409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6410. goto end;
  6411. }
  6412. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6413. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6414. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6415. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6416. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6417. {
  6418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6419. goto end;
  6420. }
  6421. }
  6422. }//END FOR CCS_QUANTITY
  6423. for (int index = 0; index < GB_QUANTITY; index++)
  6424. {
  6425. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6426. {
  6427. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6428. {
  6429. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6430. goto end;
  6431. }
  6432. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6433. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6434. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6435. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6436. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6437. {
  6438. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6439. goto end;
  6440. }
  6441. }
  6442. }// END FOR GB_QUANTITY
  6443. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6444. {
  6445. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6446. {
  6447. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6448. {
  6449. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6450. goto end;
  6451. }
  6452. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6453. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6454. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6455. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6456. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6457. {
  6458. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6459. goto end;
  6460. }
  6461. }
  6462. }// END FOR GENERAL_GUN_QUANTITY
  6463. for (int index = 0; index < AC_QUANTITY; index++)
  6464. {
  6465. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6466. {
  6467. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6468. {
  6469. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6470. goto end;
  6471. }
  6472. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6473. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6474. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6475. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6476. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6477. {
  6478. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6479. goto end;
  6480. }
  6481. }
  6482. }//END FOR AC_QUANTITY
  6483. }// END FOR gunTotalNumber
  6484. }
  6485. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6486. {
  6487. for(int i=0; i < gunTotalNumber; i++)
  6488. {
  6489. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6490. {
  6491. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6492. goto end;
  6493. }
  6494. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6495. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6496. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6497. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6498. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6499. {
  6500. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6501. goto end;
  6502. }
  6503. }
  6504. }
  6505. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6506. goto end;
  6507. }
  6508. //----------------------gunIndex is not 0 ------------------------------------------------//
  6509. //check Transaction active
  6510. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6511. {
  6512. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6513. {
  6514. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6515. {
  6516. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6517. goto end;
  6518. }
  6519. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6520. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6521. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6522. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6523. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6524. {
  6525. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6526. goto end;
  6527. }
  6528. else
  6529. {
  6530. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6531. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6532. goto end;
  6533. }
  6534. }
  6535. }//END FOR CHAdeMO_QUANTITY
  6536. for (int index = 0; index < CCS_QUANTITY; index++)
  6537. {
  6538. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6539. {
  6540. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6541. {
  6542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6543. goto end;
  6544. }
  6545. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6546. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6547. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6548. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6549. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6550. {
  6551. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6552. goto end;
  6553. }
  6554. else
  6555. {
  6556. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6557. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6558. goto end;
  6559. }
  6560. }
  6561. }//END FOR CCS_QUANTITY
  6562. for (int index = 0; index < GB_QUANTITY; index++)
  6563. {
  6564. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6565. {
  6566. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6567. {
  6568. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6569. goto end;
  6570. }
  6571. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6572. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6573. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6574. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6575. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6576. {
  6577. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6578. goto end;
  6579. }
  6580. else
  6581. {
  6582. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6583. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6584. goto end;
  6585. }
  6586. }
  6587. }// END FOR GB_QUANTITY
  6588. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6589. {
  6590. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6591. {
  6592. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6593. {
  6594. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6595. goto end;
  6596. }
  6597. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6598. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6599. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6600. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6601. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6602. {
  6603. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6604. goto end;
  6605. }
  6606. else
  6607. {
  6608. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6610. goto end;
  6611. }
  6612. }
  6613. }// END FOR GENERAL_GUN_QUANTITY
  6614. for (int index = 0; index < AC_QUANTITY; index++)
  6615. {
  6616. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6617. {
  6618. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6619. {
  6620. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6621. goto end;
  6622. }
  6623. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6624. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6625. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6626. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6627. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6628. {
  6629. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6630. goto end;
  6631. }
  6632. else
  6633. {
  6634. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6635. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6636. goto end;
  6637. }
  6638. }
  6639. }//END FOR AC_QUANTITY
  6640. }//END FOR AvailabilityTypeStr[Inoperative]
  6641. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6642. {
  6643. //----------------------gunIndex is 0 ------------------------------------------------//
  6644. if(gunIndex == 0)
  6645. {
  6646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6647. {
  6648. for(int i=0; i < gunTotalNumber; i++)
  6649. {
  6650. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6651. {
  6652. 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
  6653. {
  6654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6655. goto end;
  6656. }
  6657. }//END FOR CHAdeMO_QUANTITY
  6658. for (int index = 0; index < CCS_QUANTITY; index++)
  6659. {
  6660. 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
  6661. {
  6662. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6663. goto end;
  6664. }
  6665. }//END FOR CCS_QUANTITY
  6666. for (int index = 0; index < GB_QUANTITY; index++)
  6667. {
  6668. 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
  6669. {
  6670. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6671. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6672. goto end;
  6673. }
  6674. }// END FOR GB_QUANTITY
  6675. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6676. {
  6677. 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
  6678. {
  6679. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6680. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6681. goto end;
  6682. }
  6683. }// END FOR GENERAL_GUN_QUANTITY
  6684. for (int index = 0; index < AC_QUANTITY; index++)
  6685. {
  6686. 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
  6687. {
  6688. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6689. goto end;
  6690. }
  6691. }//END FOR CHAdeMO_QUANTITY
  6692. }// END FOR gunTotalNumber
  6693. }
  6694. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6695. {
  6696. for(int i=0; i < gunTotalNumber; i++)
  6697. {
  6698. for (int index = 0; index < AC_QUANTITY; index++)
  6699. {
  6700. 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
  6701. {
  6702. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6703. goto end;
  6704. }
  6705. }//END FOR CHAdeMO_QUANTITY
  6706. } // END FOR gunTotalNumber
  6707. }
  6708. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6709. goto end;
  6710. }
  6711. //----------------------gunIndex is not 0 ------------------------------------------------//
  6712. //check Transaction active
  6713. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6714. {
  6715. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6716. {
  6717. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6718. goto end;
  6719. }
  6720. }//END FOR CHAdeMO_QUANTITY
  6721. for (int index = 0; index < CCS_QUANTITY; index++)
  6722. {
  6723. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6724. {
  6725. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6726. goto end;
  6727. }
  6728. }//END FOR CCS_QUANTITY
  6729. for (int index = 0; index < GB_QUANTITY; index++)
  6730. {
  6731. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6732. {
  6733. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6734. goto end;
  6735. }
  6736. }// END FOR GB_QUANTITY
  6737. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6738. {
  6739. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6740. {
  6741. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6742. goto end;
  6743. }
  6744. }// END FOR GENERAL_GUN_QUANTITY
  6745. for (int index = 0; index < AC_QUANTITY; index++)
  6746. {
  6747. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6748. {
  6749. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6750. goto end;
  6751. }
  6752. }//END FOR AC_QUANTITY
  6753. }//END FOR AvailabilityTypeStr[Operative]
  6754. end:
  6755. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6756. {
  6757. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6758. }
  6759. else
  6760. {
  6761. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6762. }
  6763. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6764. {
  6765. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6766. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6767. }
  6768. else if(gunIndex == 0)
  6769. {
  6770. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6771. {
  6772. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6773. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6774. }
  6775. }
  6776. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6777. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6778. return result;
  6779. }
  6780. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6781. {
  6782. mtrace();
  6783. int result = FAIL;
  6784. char keystr[40]={0};
  6785. char valuestr[256]={0};
  6786. char comfirmstr[20]={0};
  6787. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6788. json_object *ChangeConfiguration;
  6789. ChangeConfiguration = json_tokener_parse(payload);
  6790. if(!is_error(ChangeConfiguration))
  6791. {
  6792. // Required data
  6793. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6794. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6795. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6796. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6797. }
  6798. json_object_put(ChangeConfiguration);
  6799. if((uuid==NULL) || (payload ==NULL) )
  6800. {
  6801. DEBUG_ERROR("Payload is null\n");
  6802. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6803. }
  6804. else
  6805. {
  6806. int status = setKeyValue(keystr, valuestr);
  6807. switch(status)
  6808. {
  6809. case ConfigurationStatus_Accepted:
  6810. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6811. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6812. StoreConfigurationTable();
  6813. break;
  6814. case RebootRequired:
  6815. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6816. StoreConfigurationTable();
  6817. break;
  6818. case NotSupported:
  6819. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6820. break;
  6821. case ConfigurationStatus_Rejected:
  6822. default:
  6823. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6824. break;
  6825. }
  6826. }
  6827. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6828. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6829. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6830. {
  6831. ChageWebSocketPingInterval(atoi(valuestr));
  6832. }
  6833. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6834. {
  6835. SetOcppConnStatus(FALSE);
  6836. }
  6837. return result;
  6838. }
  6839. int handleClearCacheRequest(char *uuid, char *payload)
  6840. {
  6841. mtrace();
  6842. int result = FAIL;
  6843. char comfirmstr[20];
  6844. char rmFileCmd[100]={0};
  6845. struct stat stats;
  6846. DEBUG_INFO("handleClearCacheRequest...\n");
  6847. stat("/Storage/OCPP", &stats);
  6848. // Check for directory existence
  6849. if (S_ISDIR(stats.st_mode) == 1)
  6850. {}
  6851. else
  6852. {
  6853. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6854. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6855. system(rmFileCmd);
  6856. }
  6857. if(OCPP_cleanLocalCache())
  6858. {
  6859. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6860. }
  6861. else
  6862. {
  6863. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6864. }
  6865. sendClearCacheConfirmation(uuid, comfirmstr);
  6866. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6867. return result;
  6868. }
  6869. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6870. {
  6871. mtrace();
  6872. int result = FAIL;
  6873. int resultRename;
  6874. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6875. char chargingProfilePurposeStr[26]={0};
  6876. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6877. char tempchargingProfilePurposeStr[26]={0};
  6878. char str[100]={0};
  6879. char fname[200]={0};
  6880. char comfirmstr[20]={0};
  6881. char word[1600]={0};
  6882. int clearflag = FALSE;
  6883. int chargingProfileIdIsNULL = FALSE;
  6884. int connectorIsNULL = FALSE;
  6885. int chargingProfilePurposeIsNULL = FALSE;
  6886. int stackLevelIsNULL = FALSE;
  6887. //int GotoEnd = FALSE;
  6888. FILE *fptr1, *fptr2;
  6889. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6890. int n_chargingProfile=0;
  6891. int isEmptyFile = FALSE;
  6892. char sLineWord[1600]={0};
  6893. char chargingProfiles[10][100]={0};
  6894. int ChargeProfileCount = 0;
  6895. int ch;
  6896. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6897. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6898. json_object *ClearChargingProfile;
  6899. ClearChargingProfile = json_tokener_parse(payload);
  6900. if(!is_error(ClearChargingProfile))
  6901. {
  6902. // Optional data
  6903. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6904. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6905. else
  6906. chargingProfileIdIsNULL = TRUE;
  6907. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6908. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6909. else
  6910. connectorIsNULL = TRUE;
  6911. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6912. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6913. else
  6914. chargingProfilePurposeIsNULL = TRUE;
  6915. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6916. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6917. else
  6918. stackLevelIsNULL = TRUE;
  6919. }
  6920. json_object_put(ClearChargingProfile);
  6921. if(connectorIsNULL == FALSE)
  6922. {
  6923. switch(connectorIdInt)
  6924. {
  6925. case 0:
  6926. if(chargingProfilePurposeIsNULL == TRUE)
  6927. {
  6928. int l = 0;
  6929. strcpy(fname, ChargePointMaxProfile_JSON);
  6930. if((access(fname,F_OK))!=-1)
  6931. {
  6932. strcpy(chargingProfiles[l], fname);
  6933. l = l + 1;
  6934. }
  6935. strcpy(fname, TxDefaultProfile_0_JSON);
  6936. if((access(fname,F_OK))!=-1)
  6937. {
  6938. strcpy(chargingProfiles[l], fname);
  6939. l = l + 1;
  6940. }
  6941. ChargeProfileCount = l;
  6942. }
  6943. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6944. {
  6945. strcpy(fname, ChargePointMaxProfile_JSON);
  6946. if((access(fname,F_OK))!=-1)
  6947. {
  6948. strcpy(chargingProfiles[0], fname);
  6949. ChargeProfileCount = 1;
  6950. }
  6951. }
  6952. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6953. {
  6954. strcpy(fname, TxDefaultProfile_0_JSON);
  6955. if((access(fname,F_OK))!=-1)
  6956. {
  6957. strcpy(chargingProfiles[0], fname);
  6958. ChargeProfileCount = 1;
  6959. }
  6960. }
  6961. break;
  6962. default:
  6963. if(chargingProfilePurposeIsNULL == TRUE)
  6964. {
  6965. int m = 0;
  6966. memset(fname, 0, ARRAY_SIZE(fname));
  6967. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6968. if((access(fname,F_OK))!=-1)
  6969. {
  6970. strcpy(chargingProfiles[m], fname);
  6971. m = m + 1;
  6972. }
  6973. memset(fname, 0, ARRAY_SIZE(fname));
  6974. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6975. if((access(fname,F_OK))!=-1)
  6976. {
  6977. strcpy(chargingProfiles[m], fname);
  6978. m = m + 1;
  6979. }
  6980. ChargeProfileCount = m;
  6981. }
  6982. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6983. {
  6984. //strcpy(fname, TxDefaultProfile_1_JSON);
  6985. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6986. if((access(fname,F_OK))!=-1)
  6987. {
  6988. strcpy(chargingProfiles[0], fname);
  6989. ChargeProfileCount = 1;
  6990. }
  6991. }
  6992. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6993. {
  6994. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6995. if((access(fname,F_OK))!=-1)
  6996. {
  6997. strcpy(chargingProfiles[0], fname);
  6998. ChargeProfileCount = 1;
  6999. }
  7000. //strcpy(fname, TxProfile_1_JSON);
  7001. }
  7002. //strcpy(fname, ChargePointMaxProfile_JSON );
  7003. break;
  7004. }
  7005. }
  7006. else // Check all Charging Profiles
  7007. {
  7008. int i = 0;
  7009. char fnametemp[200]={0};
  7010. ChargeProfileCount = 0;
  7011. //Check ChargePointMaxProfile.json exit
  7012. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7013. {
  7014. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7015. i = i + 1;
  7016. }
  7017. //Check TxDefaultProfile_0.json exit
  7018. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7019. {
  7020. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7021. i = i + 1;
  7022. }
  7023. //Check TxDefaultProfile_%d.json
  7024. for(int j=1; j <= gunTotalNumber; j++)
  7025. {
  7026. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7027. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7028. if((access(fnametemp,F_OK))!=-1)
  7029. {
  7030. strcpy(chargingProfiles[i], fnametemp);
  7031. i = i + 1;
  7032. }
  7033. }
  7034. //Check TxProfile_%d.json
  7035. for(int j=1; j <= gunTotalNumber; j++)
  7036. {
  7037. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7038. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7039. if((access(fnametemp,F_OK))!=-1)
  7040. {
  7041. strcpy(chargingProfiles[i], fnametemp);
  7042. i = i + 1;
  7043. }
  7044. }
  7045. ChargeProfileCount = i;
  7046. }// End connectorIsNULL is TRUE
  7047. if(ChargeProfileCount == 0)
  7048. {
  7049. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7050. goto end;
  7051. }
  7052. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7053. {
  7054. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7055. goto end;
  7056. }
  7057. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7058. {
  7059. memset(str, 0, ARRAY_SIZE(str));
  7060. // clear temp file
  7061. sprintf(str,"rm -f %s",temp);
  7062. system(str);
  7063. for(int k=0; k < ChargeProfileCount; k++)
  7064. {
  7065. memset(str, 0, ARRAY_SIZE(str));
  7066. //clear file in C
  7067. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7068. system(str);
  7069. }
  7070. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7071. goto end;
  7072. }
  7073. else if(connectorIsNULL == TRUE)
  7074. {
  7075. for(int k=0; k < ChargeProfileCount; k++)
  7076. {
  7077. fptr1 = fopen(chargingProfiles[k], "r");
  7078. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7079. //Check Charging Profile Count
  7080. while(fscanf(fptr1, "%s", word) != EOF)
  7081. {
  7082. //DEBUG_INFO("word=%s\n",word);
  7083. if(strstr(word, "chargingProfileId")!= NULL)
  7084. {
  7085. //DEBUG_INFO("test chargingProfileId \n");
  7086. n_chargingProfile = n_chargingProfile + 1;
  7087. //DEBUG_INFO("chargingProfileId Found\n");
  7088. }
  7089. }
  7090. rewind(fptr1);
  7091. //search Charging Profile Element
  7092. //int i= 0;
  7093. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7094. {
  7095. json_object *tmpProfilee;
  7096. tmpProfilee = json_tokener_parse(sLineWord);
  7097. if(!is_error(tmpProfilee))
  7098. {
  7099. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7100. {
  7101. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7102. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7103. }
  7104. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7105. {
  7106. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7107. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7108. }
  7109. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7110. {
  7111. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7112. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7113. }
  7114. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7115. {
  7116. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7117. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7118. }
  7119. }
  7120. json_object_put(tmpProfilee);
  7121. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7122. {
  7123. //------- not write to fptr2-------//
  7124. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7125. //clearflag = TRUE;
  7126. }
  7127. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7128. {
  7129. //------- not write to fptr2-------//
  7130. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7131. }
  7132. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7133. {
  7134. //------- not write to fptr2-------//
  7135. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7136. }
  7137. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7138. {
  7139. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7140. }
  7141. else
  7142. {
  7143. fprintf(fptr2, sLineWord);//writing data into file
  7144. }
  7145. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7146. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7147. if(clearflag == TRUE)
  7148. {
  7149. fclose(fptr1);
  7150. fclose(fptr2);
  7151. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7152. system(str);
  7153. // clear temp file
  7154. sprintf(str,"rm -f %s",temp);
  7155. system(str);
  7156. }
  7157. else
  7158. {
  7159. fclose(fptr1);
  7160. fclose(fptr2);
  7161. memset(str, 0, ARRAY_SIZE(str));
  7162. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7163. system(str);
  7164. resultRename = rename(temp, chargingProfiles[k]);
  7165. if(resultRename == 0)
  7166. {
  7167. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7168. }
  7169. else
  7170. {
  7171. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7172. }
  7173. if(comfirmstr[0]== 0)
  7174. {
  7175. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7176. }
  7177. //Check chargingProfile is empty file
  7178. /*------ Read the file ----------------*/
  7179. fptr1=fopen(chargingProfiles[k],"r");
  7180. ch=fgetc(fptr1);
  7181. rewind(fptr1);
  7182. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7183. if(ch!=EOF)
  7184. {
  7185. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7186. {
  7187. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7188. if(sLineWord[0]=='\0')
  7189. {
  7190. isEmptyFile = TRUE;
  7191. break;
  7192. }
  7193. else
  7194. {
  7195. isEmptyFile = FALSE;
  7196. break;
  7197. }
  7198. }
  7199. }
  7200. else
  7201. isEmptyFile = TRUE;
  7202. fclose(fptr1);
  7203. if(isEmptyFile == TRUE)
  7204. {
  7205. memset(str, 0, ARRAY_SIZE(str));
  7206. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7207. system(str);
  7208. }
  7209. }
  7210. }// End of while(int k=0; k < ChargePointCount; k++)
  7211. }
  7212. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7213. {
  7214. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7215. for(int k=0; k < ChargeProfileCount; k++)
  7216. {
  7217. fptr1 = fopen(chargingProfiles[k], "r");
  7218. fptr2 = fopen(temp, "w+");
  7219. //Check Charging Profile Count
  7220. while(fscanf(fptr1, "%s", word) != EOF)
  7221. {
  7222. //DEBUG_INFO("word=%s\n",word);
  7223. if(strstr(word, "chargingProfileId")!= NULL)
  7224. {
  7225. n_chargingProfile = n_chargingProfile + 1;
  7226. }
  7227. }
  7228. rewind(fptr1);
  7229. //search Charging Profile Element
  7230. //int i= 0;
  7231. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7232. {
  7233. json_object *tmpProfilee;
  7234. tmpProfilee = json_tokener_parse(sLineWord);
  7235. if(!is_error(tmpProfilee))
  7236. {
  7237. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7238. {
  7239. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7240. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7241. }
  7242. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7243. {
  7244. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7245. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7246. }
  7247. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7248. {
  7249. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7250. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7251. }
  7252. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7253. {
  7254. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7255. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7256. }
  7257. }
  7258. json_object_put(tmpProfilee);
  7259. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7260. {
  7261. //------- not write to fptr2-------//
  7262. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7263. //clearflag = TRUE;
  7264. }
  7265. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7266. {
  7267. //------- not write to fptr2-------//
  7268. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7269. }
  7270. else if(stackLevelIsNULL == TRUE)
  7271. {
  7272. //Clear Whole File
  7273. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7274. clearflag = TRUE;
  7275. break;
  7276. }
  7277. else
  7278. {
  7279. fprintf(fptr2, sLineWord);//writing data into file
  7280. }
  7281. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7282. }
  7283. if(clearflag == TRUE)
  7284. {
  7285. fclose(fptr1);
  7286. fclose(fptr2);
  7287. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7288. system(str);
  7289. // clear temp file
  7290. sprintf(str,"rm -f %s",temp);
  7291. system(str);
  7292. }
  7293. else
  7294. {
  7295. fclose(fptr1);
  7296. fclose(fptr2);
  7297. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7298. system(str);
  7299. resultRename = rename(temp, chargingProfiles[k]);
  7300. if(resultRename == 0)
  7301. {
  7302. DEBUG_INFO("File ChargingProfile renamed successfully");
  7303. }
  7304. else
  7305. {
  7306. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7307. }
  7308. if(comfirmstr[0]== 0)
  7309. {
  7310. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7311. }
  7312. //Check chargingProfile is empty file
  7313. /*------ Read the file ----------------*/
  7314. fptr1=fopen(chargingProfiles[k],"r");
  7315. ch=fgetc(fptr1);
  7316. rewind(fptr1);
  7317. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7318. if(ch!=EOF)
  7319. {
  7320. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7321. {
  7322. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7323. if(sLineWord[0]=='\0')
  7324. {
  7325. isEmptyFile = TRUE;
  7326. break;
  7327. }
  7328. else
  7329. {
  7330. isEmptyFile = FALSE;
  7331. break;
  7332. }
  7333. }
  7334. }
  7335. else
  7336. isEmptyFile = TRUE;
  7337. fclose(fptr1);
  7338. if(isEmptyFile == TRUE)
  7339. {
  7340. memset(str, 0, ARRAY_SIZE(str));
  7341. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7342. system(str);
  7343. }
  7344. /*------- End of reading ---------------*/
  7345. }
  7346. } // while(int k=0; k < ChargeProfileCount; k++)
  7347. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7348. end:
  7349. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7350. {
  7351. if(connectorIdInt == 0)
  7352. {
  7353. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7354. {
  7355. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7356. }
  7357. }
  7358. else
  7359. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7360. }
  7361. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7362. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7363. return result;
  7364. }
  7365. void createFirmwareVersionByDataTransfer(void)
  7366. {
  7367. json_object *FirmwareDataTransfer = json_object_new_object();
  7368. // AC & DC model
  7369. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7370. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7371. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7372. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7373. // DC model
  7374. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7375. {
  7376. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7377. {
  7378. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7379. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7380. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7381. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7382. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7383. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7384. }
  7385. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7386. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7387. {
  7388. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7389. }
  7390. }
  7391. else
  7392. {
  7393. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7394. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7395. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7396. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7397. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7398. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7399. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7400. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7401. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7402. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7403. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7404. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7405. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7406. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7407. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7408. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7409. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7410. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7411. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7412. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7413. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7414. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7415. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7416. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7417. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7418. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7419. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7420. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7421. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7422. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7423. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7424. }
  7425. // 4G model
  7426. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7427. {
  7428. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7429. }
  7430. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7431. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7432. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7433. json_object_put(FirmwareDataTransfer);
  7434. }
  7435. int handleDataTransferRequest(char *uuid, char *payload)
  7436. {
  7437. mtrace();
  7438. json_object *response = json_object_new_object();
  7439. int result = FAIL;
  7440. char tempvendorId[255]={0};
  7441. char tempmessageId[50]={0};
  7442. char tempdata[512]={0};
  7443. char message[2048]={0};
  7444. DEBUG_INFO("handleDataTransferRequest...\n");
  7445. if((uuid != NULL) && (payload != NULL))
  7446. {
  7447. json_object *DataTransfer;
  7448. DataTransfer = json_tokener_parse(payload);
  7449. if(!is_error(DataTransfer))
  7450. {
  7451. // Required data
  7452. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7453. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7454. // Optional data
  7455. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7456. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7457. if(json_object_object_get(DataTransfer, "data") != NULL)
  7458. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7459. result = PASS;
  7460. }
  7461. json_object_put(DataTransfer);
  7462. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7463. {
  7464. // Send all moudle firmware version on EVSE
  7465. createFirmwareVersionByDataTransfer();
  7466. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7467. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7468. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7469. json_object_put(response);
  7470. }
  7471. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7472. {
  7473. system("/usr/bin/run_tmate_restart.sh &");
  7474. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7475. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7476. json_object_put(response);
  7477. }
  7478. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7479. {
  7480. json_object *data;
  7481. data = json_tokener_parse(tempdata);
  7482. if(!is_error(data))
  7483. {
  7484. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7485. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7486. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7487. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7488. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7489. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7490. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7491. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7492. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7493. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7494. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7495. }
  7496. else
  7497. {
  7498. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7499. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7500. }
  7501. json_object_put(data);
  7502. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7503. json_object_put(response);
  7504. }
  7505. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7506. {
  7507. json_object *data;
  7508. data = json_tokener_parse(tempdata);
  7509. if(!is_error(data))
  7510. {
  7511. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7512. if(json_object_object_get(data, "idToken") != NULL)
  7513. {
  7514. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7515. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7516. }
  7517. if(json_object_object_get(data, "price") != NULL)
  7518. {
  7519. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7520. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7521. }
  7522. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7523. }
  7524. else
  7525. {
  7526. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7527. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7528. }
  7529. json_object_put(data);
  7530. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7531. json_object_put(response);
  7532. }
  7533. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7534. {
  7535. json_object *data;
  7536. data = json_tokener_parse(tempdata);
  7537. if(!is_error(data))
  7538. {
  7539. if(json_object_object_get(data, "txId") != NULL)
  7540. {
  7541. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7542. for(int idx = 0;idx<gunTotalNumber;idx++)
  7543. {
  7544. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7545. {
  7546. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7547. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7548. if(json_object_object_get(data, "description") != NULL)
  7549. {
  7550. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7551. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7552. }
  7553. }
  7554. }
  7555. }
  7556. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7557. }
  7558. else
  7559. {
  7560. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7561. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7562. }
  7563. json_object_put(data);
  7564. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7565. json_object_put(response);
  7566. }
  7567. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7568. {
  7569. json_object *data;
  7570. data = json_tokener_parse(tempdata);
  7571. if(!is_error(data))
  7572. {
  7573. if(json_object_object_get(data, "txId") != NULL)
  7574. {
  7575. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7576. for(int idx = 0;idx<gunTotalNumber;idx++)
  7577. {
  7578. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7579. {
  7580. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7581. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7582. if(json_object_object_get(data, "description") != NULL)
  7583. {
  7584. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7585. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7586. }
  7587. }
  7588. }
  7589. }
  7590. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7591. }
  7592. else
  7593. {
  7594. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7595. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7596. }
  7597. json_object_put(data);
  7598. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7599. json_object_put(response);
  7600. }
  7601. else
  7602. {
  7603. // Can not find valid message id
  7604. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7605. }
  7606. }
  7607. else
  7608. {
  7609. // Payload is null
  7610. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7611. }
  7612. LWS_Send(message);
  7613. return result;
  7614. }
  7615. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7616. {
  7617. mtrace();
  7618. int result = FAIL;
  7619. int connectorIdInt, durationInt;
  7620. char chargingRateUnitStr[4]={0};
  7621. char comfirmstr[20];
  7622. int confirmPeriods = 0;
  7623. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7624. json_object *GetCompositeSchedule;
  7625. GetCompositeSchedule = json_tokener_parse(payload);
  7626. if(!is_error(GetCompositeSchedule))
  7627. {
  7628. // Required data
  7629. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7630. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7631. else
  7632. connectorIdInt = -1;
  7633. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7634. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7635. else
  7636. durationInt = 86400;
  7637. // Optional data
  7638. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7639. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7640. }
  7641. json_object_put(GetCompositeSchedule);
  7642. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7643. if((connectorIdInt == 0) ||
  7644. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7645. {
  7646. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7647. struct StructChargingProfile tmpProfile[1];
  7648. if(strstr(chargingRateUnitStr, "W") != NULL)
  7649. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7650. else
  7651. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7652. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7653. {
  7654. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7655. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7656. }
  7657. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7658. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7659. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7660. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7661. {
  7662. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7663. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7664. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7665. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7666. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7667. {
  7668. confirmPeriods = idx;
  7669. break;
  7670. }
  7671. }
  7672. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7673. {
  7674. confirmPeriods += 1;
  7675. }
  7676. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7677. }
  7678. else
  7679. {
  7680. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7681. }
  7682. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7683. return result;
  7684. }
  7685. int handleGetConfigurationRequest(char *uuid, char *payload)
  7686. {
  7687. mtrace();
  7688. int result = FAIL;
  7689. int MaxKeySupported = 0;
  7690. int n_keys = 0;
  7691. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7692. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7693. json_object *GetConfiguration;
  7694. GetConfiguration = json_tokener_parse(payload);
  7695. if(!is_error(GetConfiguration))
  7696. {
  7697. // Optional data
  7698. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7699. {
  7700. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7701. {
  7702. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7703. n_keys = idx + 1;
  7704. }
  7705. }
  7706. }
  7707. json_object_put(GetConfiguration);
  7708. UnknownKeynum = 0;
  7709. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7710. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7711. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7712. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7713. if(n_keys != 0)
  7714. {
  7715. for(int i=0;i<n_keys;i++)
  7716. {
  7717. getKeyValue(requestKey[i]);
  7718. }
  7719. }
  7720. else
  7721. {
  7722. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7723. getKeyValue("");
  7724. }
  7725. processUnkownKey();
  7726. sendGetConfigurationConfirmation(uuid);
  7727. return result;
  7728. }
  7729. static char fnamePlusPath[100]={0};
  7730. static char fnamePWithNoPath[60]={0};
  7731. void checkUploadLog(void)
  7732. {
  7733. FILE *fp;
  7734. /* Open the command for reading. */
  7735. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7736. if (fp == NULL) {
  7737. printf("Failed to run command\n" );
  7738. exit(1);
  7739. }
  7740. int ftppathlen = 0;
  7741. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7742. int i = 0;
  7743. /* Read the output a line at a time - output it. */
  7744. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7745. if(i==0)
  7746. {
  7747. ftppathlen = strlen(fnamePlusPath);
  7748. printf("%s\n", fnamePlusPath);
  7749. fnamePlusPath[ftppathlen]='\0';
  7750. break;
  7751. }
  7752. i= i+1;
  7753. }
  7754. /* close */
  7755. pclose(fp);
  7756. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7757. {
  7758. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7759. {
  7760. fnamePlusPath[k]='\0';
  7761. }
  7762. }
  7763. i=1;
  7764. //char fname[60]={0};
  7765. while(i < ftppathlen)
  7766. {
  7767. int len=ftppathlen-i;
  7768. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7769. {
  7770. printf("compare '/' all right\n");
  7771. break;
  7772. }
  7773. i=i+1;
  7774. }
  7775. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7776. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7777. fnamePWithNoPath[i+1] = '\0';
  7778. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7779. {
  7780. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7781. {
  7782. fnamePWithNoPath[j]='\0';
  7783. }
  7784. }
  7785. FILE* fp1 = fopen(fnamePlusPath, "r");
  7786. if (fp1)
  7787. {
  7788. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7789. // file exists
  7790. fclose(fp1);
  7791. }
  7792. else
  7793. {
  7794. // file doesn't exist
  7795. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7796. }
  7797. }
  7798. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7799. {
  7800. mtrace();
  7801. int result = FAIL;
  7802. time_t CurrentTime;
  7803. struct tm *tm;
  7804. pthread_t th_Status;
  7805. CurrentTime = time(NULL);
  7806. tm = localtime(&CurrentTime);
  7807. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7808. sprintf((char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  7809. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7810. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7811. return result;
  7812. }
  7813. void* GetDiagnosticsProcess(void* data)
  7814. {
  7815. pthread_detach(pthread_self());
  7816. mtrace();
  7817. int retriesInt=0, retryIntervalInt=0;
  7818. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7819. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  7820. int port=0;
  7821. int isSuccess = FALSE;
  7822. char cmdBuf[2048];
  7823. struct tm *tmNow;
  7824. time_t CurrentTime;
  7825. struct tm tmStart;
  7826. struct tm tmStop;
  7827. CurrentTime = time(NULL);
  7828. tmNow=localtime(&CurrentTime);
  7829. uint16_t targetYear, targetMonth;
  7830. json_object *GetDiagnostics;
  7831. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7832. GetDiagnostics = json_tokener_parse(data);
  7833. if(!is_error(GetDiagnostics))
  7834. {
  7835. // Required data
  7836. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7837. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7838. // Optional data
  7839. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7840. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7841. else
  7842. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7843. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7844. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7845. else
  7846. retryIntervalInt = 30;
  7847. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7848. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7849. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7850. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7851. }
  7852. json_object_put(GetDiagnostics);
  7853. // Pack log to compress file
  7854. 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) &&
  7855. (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))
  7856. {
  7857. // Pack system log
  7858. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7859. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7860. targetYear = tmStart.tm_year;
  7861. targetMonth = tmStart.tm_mon;
  7862. do
  7863. {
  7864. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7865. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7866. if(targetMonth+1>=13)
  7867. {
  7868. targetYear += 1;
  7869. targetMonth = 1;
  7870. }
  7871. else
  7872. {
  7873. targetMonth += 1;
  7874. }
  7875. }while((targetYear < (tmNow->tm_year+1900)) ||
  7876. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7877. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7878. system(cmdBuf);
  7879. // Pack charging & event log
  7880. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7881. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7882. targetYear = tmStart.tm_year;
  7883. targetMonth = tmStart.tm_mon;
  7884. do
  7885. {
  7886. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7887. if(targetMonth+1>=13)
  7888. {
  7889. targetYear += 1;
  7890. targetMonth = 1;
  7891. }
  7892. else
  7893. {
  7894. targetMonth += 1;
  7895. }
  7896. }while((targetYear < (tmNow->tm_year+1900)) ||
  7897. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7898. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7899. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7900. system(cmdBuf);
  7901. // Combine log file
  7902. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7903. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7904. }
  7905. else
  7906. {
  7907. system("exec /root/logPackTools 'log' 6");
  7908. }
  7909. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7910. system(cmdBuf);
  7911. checkUploadLog();
  7912. //****************location*******************/
  7913. if(strcmp(locationstr,"")==0)
  7914. {
  7915. DEBUG_INFO("location is <Empty>!\n");
  7916. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7917. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7918. goto end;
  7919. }
  7920. memset(protocol, 0, ARRAY_SIZE(protocol));
  7921. memset(user, 0, ARRAY_SIZE(user) );
  7922. memset(password, 0, ARRAY_SIZE(password));
  7923. memset(host, 0, ARRAY_SIZE(host));
  7924. memset(path, 0, ARRAY_SIZE(path));
  7925. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7926. memset(host1, 0, ARRAY_SIZE(host1));
  7927. memset(path1, 0, ARRAY_SIZE(path1));
  7928. /*location: ftp://user:password@host:port/path*/
  7929. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7930. if((access(fnamePlusPath,F_OK))!=-1)
  7931. {
  7932. DEBUG_INFO("fnamePlusPath exist.\n");
  7933. }
  7934. else
  7935. {
  7936. DEBUG_INFO("fnamePlusPath not exist!\n");
  7937. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7938. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7939. goto end;
  7940. }
  7941. if(strchr(locationstr,'@')==NULL)
  7942. {
  7943. sscanf(locationstr,
  7944. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7945. protocol, host, &port, path);
  7946. strcpy(user,"anonymous");
  7947. strcpy(password,"");
  7948. }
  7949. else
  7950. {
  7951. //DEBUG_INFO("pch=%s\n", pch);
  7952. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7953. protocol, user, password, host, &port, path);
  7954. }
  7955. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  7956. {
  7957. DEBUG_INFO("protocol is not ftp/http ! \n");
  7958. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7959. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7960. goto end;
  7961. }
  7962. if(strncmp(locationstr,"http", 4) == 0)
  7963. {
  7964. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7965. sprintf(ftppath,"/%s", path);
  7966. do
  7967. {
  7968. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7969. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7970. sleep(3);
  7971. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7972. if(!isSuccess)
  7973. {
  7974. DEBUG_INFO("Diagnostics fail.\n");
  7975. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7976. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7977. sleep(retryIntervalInt);
  7978. }
  7979. else
  7980. {
  7981. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7982. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7983. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7984. }
  7985. retriesInt--;
  7986. }while((isSuccess == 0)&&(retriesInt >= 0));
  7987. }
  7988. else
  7989. {
  7990. sscanf(host,"%[^/]%s",host1, path1);
  7991. if(strlen(path) > 0)
  7992. sprintf(ftppath,"/%s", path);
  7993. else
  7994. sprintf(ftppath,"/%s", path1);
  7995. int ftppathlen=strlen(ftppath);
  7996. int i=1;
  7997. char filenametemp[50];
  7998. while(i < ftppathlen)
  7999. {
  8000. int len=ftppathlen-i;
  8001. if(ftppath[len]== 47) // '/' ascll code: 47
  8002. {
  8003. DEBUG_INFO("find '/' all right\n");
  8004. break;
  8005. }
  8006. i=i+1;
  8007. }
  8008. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8009. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8010. filenametemp[i+1] = 0;
  8011. if(port == 0)
  8012. port = 21;
  8013. do
  8014. {
  8015. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8016. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8017. sleep(3);
  8018. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8019. if(!isSuccess)
  8020. {
  8021. DEBUG_INFO("Diagnostics fail.\n");
  8022. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8023. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8024. sleep(retryIntervalInt);
  8025. }
  8026. else
  8027. {
  8028. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8029. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8030. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8031. }
  8032. retriesInt--;
  8033. }while((!isSuccess)&&(retriesInt >= 0));
  8034. }
  8035. end:
  8036. system("rm -f /mnt/*");
  8037. sleep(5);
  8038. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8039. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8040. pthread_exit(NULL);
  8041. }
  8042. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8043. {
  8044. mtrace();
  8045. int result = FAIL;
  8046. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8047. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8048. {
  8049. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8050. localversion = -1;
  8051. }
  8052. else
  8053. {
  8054. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8055. OCPP_getListVerion();
  8056. }
  8057. //from db.OCPP_getListVerion
  8058. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  8059. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  8060. sendGetLocalListVersionConfirmation(uuid,"");
  8061. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  8062. return result;
  8063. }
  8064. int handleRemoteStartRequest(char *uuid, char *payload)
  8065. {
  8066. mtrace();
  8067. int result = FAIL;
  8068. int connectorIdInt=0;
  8069. int tempIndex = 0;
  8070. int connectorIdIsNULL, chargingProfileIsNULL;
  8071. char comfirmstr[20]={0};
  8072. char cmdBuf[512];
  8073. json_object *RemoteStartTransaction;
  8074. FILE *fp;
  8075. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8076. if(server_pending == TRUE)
  8077. {
  8078. return 0;
  8079. }
  8080. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8081. RemoteStartTransaction = json_tokener_parse(payload);
  8082. if(!is_error(RemoteStartTransaction))
  8083. {
  8084. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8085. {
  8086. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8087. if(connectorIdInt <= gunTotalNumber)
  8088. {
  8089. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8090. // Required data
  8091. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8092. // Optional data
  8093. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8094. {
  8095. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8096. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8097. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8098. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8099. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8100. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8101. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8102. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8103. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8104. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8105. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8106. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8107. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8108. {
  8109. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  8110. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8111. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  8112. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8113. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  8114. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8115. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  8116. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8117. {
  8118. 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++)
  8119. {
  8120. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  8121. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  8122. 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)
  8123. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  8124. }
  8125. }
  8126. }
  8127. }
  8128. else
  8129. chargingProfileIsNULL = TRUE;
  8130. }
  8131. }
  8132. else
  8133. connectorIdIsNULL = TRUE;
  8134. }
  8135. else
  8136. connectorIdIsNULL = TRUE;
  8137. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8138. {
  8139. DEBUG_WARN("Connector id is NULL\n.");
  8140. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8141. goto end;
  8142. }
  8143. /*
  8144. enum _SYSTEM_STATUS
  8145. {
  8146. S_BOOTING = 0,
  8147. S_IDLE, = 1
  8148. S_AUTHORIZING, = 2
  8149. S_REASSIGN_CHECK, = 3
  8150. S_REASSIGN, = 4
  8151. S_PRECHARGE, = 5
  8152. S_PREPARING_FOR_EV, = 6
  8153. S_PREPARING_FOR_EVSE, = 7
  8154. S_CHARGING, = 8
  8155. S_TERMINATING, = 9
  8156. S_COMPLETE, = 10
  8157. S_ALARM, = 11
  8158. S_FAULT = 12
  8159. }
  8160. */
  8161. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8162. {
  8163. //check Transaction active
  8164. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8165. {
  8166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8167. {
  8168. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8169. }
  8170. else
  8171. {
  8172. tempIndex = connectorIdInt -1;
  8173. }
  8174. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8175. {
  8176. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8177. {
  8178. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8179. {
  8180. //Reserved
  8181. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8182. }
  8183. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8184. {
  8185. //Reserved
  8186. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8187. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8188. goto end;
  8189. }
  8190. else
  8191. {
  8192. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8193. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8194. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8195. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8196. {
  8197. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8198. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8199. goto end;
  8200. }
  8201. }//END FOR ELSE
  8202. }
  8203. }// END FOR CHAdeMO_QUANTITY
  8204. }
  8205. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8206. {
  8207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8208. {
  8209. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8210. }
  8211. else
  8212. {
  8213. tempIndex = connectorIdInt -1;
  8214. }
  8215. for (int index = 0; index < CCS_QUANTITY; index++)
  8216. {
  8217. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8218. {
  8219. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8220. {
  8221. //Reserved
  8222. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8223. }
  8224. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8225. {
  8226. //Reserved
  8227. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8228. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8229. goto end;
  8230. }
  8231. else
  8232. {
  8233. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8234. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8235. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8236. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8237. {
  8238. DEBUG_WARN("CCS connector not allow start\n.");
  8239. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8240. goto end;
  8241. }
  8242. }// END FOR ELSE
  8243. }
  8244. }// END FOR CCS_QUANTITY
  8245. }
  8246. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8247. {
  8248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8249. {
  8250. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8251. }
  8252. else
  8253. {
  8254. tempIndex = connectorIdInt -1;
  8255. }
  8256. for (int index = 0; index < GB_QUANTITY; index++)
  8257. {
  8258. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8259. {
  8260. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8261. {
  8262. //Reserved
  8263. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8264. }
  8265. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8266. {
  8267. //Reserved
  8268. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8269. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8270. goto end;
  8271. }
  8272. else
  8273. {
  8274. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8275. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8276. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8277. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8278. {
  8279. DEBUG_WARN("GB connector not allow start\n.");
  8280. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8281. goto end;
  8282. }
  8283. }// END FOR ELSE
  8284. }
  8285. } // END FOR GB_QUANTITY
  8286. }
  8287. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8288. {
  8289. tempIndex = connectorIdInt -1;
  8290. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8291. {
  8292. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8293. {
  8294. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8295. {
  8296. //Reserved
  8297. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8298. }
  8299. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8300. {
  8301. //Reserved
  8302. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8303. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8304. goto end;
  8305. }
  8306. else
  8307. {
  8308. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8309. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8310. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8311. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8312. {
  8313. DEBUG_WARN("GB connector not allow start\n.");
  8314. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8315. goto end;
  8316. }
  8317. }// END FOR ELSE
  8318. }
  8319. } // END FOR GB_QUANTITY
  8320. }
  8321. else
  8322. {
  8323. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8324. {
  8325. tempIndex = 2;
  8326. }
  8327. else
  8328. {
  8329. tempIndex = connectorIdInt -1;
  8330. }
  8331. for (int index = 0; index < AC_QUANTITY; index++)
  8332. {
  8333. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8334. {
  8335. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8336. {
  8337. //Reserved
  8338. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8339. }
  8340. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8341. {
  8342. //Reserved
  8343. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8344. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8345. goto end;
  8346. }
  8347. else
  8348. {
  8349. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8350. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8351. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8352. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8353. {
  8354. DEBUG_WARN("AC connector not allow start\n.");
  8355. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8356. goto end;
  8357. }
  8358. }//END FOR ELSE
  8359. }
  8360. }// END FOR AC_QUANTITY
  8361. }
  8362. if(chargingProfileIsNULL == FALSE)
  8363. {
  8364. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8365. {
  8366. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8367. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8368. //memset idTag
  8369. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8370. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8371. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8372. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8373. // Save profile to file
  8374. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8375. system(cmdBuf);
  8376. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8377. fp = fopen(cmdBuf, "w");
  8378. 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));
  8379. fclose(fp);
  8380. }
  8381. else
  8382. {
  8383. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8384. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8385. }
  8386. }
  8387. else
  8388. {
  8389. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8390. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8391. //memset idTag
  8392. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8393. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8394. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8395. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8396. }
  8397. }
  8398. else
  8399. {
  8400. DEBUG_WARN("Connector id over\n.");
  8401. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8402. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8403. }
  8404. end:
  8405. json_object_put(RemoteStartTransaction);
  8406. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8407. {
  8408. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8409. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8410. }
  8411. //OCPP send RemoteStartConfirmation by first.
  8412. sendRemoteStartConfirmation(uuid, comfirmstr);
  8413. return result;
  8414. }
  8415. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8416. {
  8417. mtrace();
  8418. int result = FAIL;
  8419. int match = FALSE;
  8420. int GunNO = 0;
  8421. int tempIndex = 0;
  8422. int transactionIdInt=0;
  8423. int transactionIdIsNULL= TRUE;
  8424. char comfirmstr[20];
  8425. json_object *RemoteStopTransaction;
  8426. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8427. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8428. if(server_pending == TRUE)
  8429. {
  8430. return 0;
  8431. }
  8432. RemoteStopTransaction = json_tokener_parse(payload);
  8433. if(!is_error(RemoteStopTransaction))
  8434. {
  8435. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8436. {
  8437. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8438. transactionIdIsNULL = FALSE;
  8439. }
  8440. }
  8441. json_object_put(RemoteStopTransaction);
  8442. if(transactionIdIsNULL == FALSE)
  8443. {
  8444. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8445. {
  8446. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8447. {
  8448. //check Transaction active
  8449. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8450. {
  8451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8452. {
  8453. tempIndex = ((gun_index==2) ? 1: 0);
  8454. }
  8455. else
  8456. {
  8457. tempIndex = gun_index;
  8458. }
  8459. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8460. {
  8461. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8462. {
  8463. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8464. {
  8465. match = TRUE;
  8466. GunNO = gun_index;
  8467. }
  8468. }
  8469. }// END FOR CHAdeMO_QUANTITY
  8470. }
  8471. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8472. {
  8473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8474. {
  8475. tempIndex = ((gun_index==2) ? 1: 0);
  8476. }
  8477. else
  8478. {
  8479. tempIndex = gun_index;
  8480. }
  8481. for (int index = 0; index < CCS_QUANTITY; index++)
  8482. {
  8483. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8484. {
  8485. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8486. {
  8487. match = TRUE;
  8488. GunNO = gun_index;
  8489. }
  8490. }
  8491. }// END FOR CCS_QUANTITY
  8492. }
  8493. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8494. {
  8495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8496. {
  8497. tempIndex = ((gun_index==2) ? 1: 0);
  8498. }
  8499. else
  8500. {
  8501. tempIndex = gun_index;
  8502. }
  8503. for (int index = 0; index < GB_QUANTITY; index++)
  8504. {
  8505. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8506. {
  8507. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8508. {
  8509. match = TRUE;
  8510. GunNO = gun_index;
  8511. }
  8512. }
  8513. }// END FOR GB_QUANTITY
  8514. }
  8515. else if(gunType[gun_index] == GUN_TYPE_DO)
  8516. {
  8517. tempIndex = gun_index;
  8518. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8519. {
  8520. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8521. {
  8522. 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
  8523. {
  8524. match = TRUE;
  8525. GunNO = gun_index;
  8526. }
  8527. }
  8528. }// END FOR GB_QUANTITY
  8529. }
  8530. else
  8531. {
  8532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8533. {
  8534. tempIndex = 2;
  8535. }
  8536. else
  8537. {
  8538. tempIndex = gun_index;
  8539. }
  8540. for (int index = 0; index < AC_QUANTITY; index++)
  8541. {
  8542. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8543. {
  8544. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8545. {
  8546. match = TRUE;
  8547. GunNO = gun_index;
  8548. }
  8549. }
  8550. }// END FOR CHAdeMO_QUANTITY
  8551. } // END FOR AC ELSE
  8552. }// CHECK IF ResponseTransactionId == transactionIdInt
  8553. }//END FOR
  8554. if( match == TRUE)
  8555. {
  8556. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8557. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8558. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8559. }
  8560. else
  8561. {
  8562. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8563. }
  8564. }
  8565. else
  8566. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8567. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8568. return result;
  8569. }
  8570. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8571. {
  8572. mtrace();
  8573. int result = FAIL;
  8574. int connectorIdInt=0, reservationIdInt=0;
  8575. int tempIndex = 0;
  8576. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8577. char comfirmstr[20]={0};
  8578. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8579. int c = 0;
  8580. char *loc;
  8581. //char *ptr;
  8582. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8583. strcpy(sstrtemp, stringtrimspace(payload));
  8584. //***(1)connectorId ****/
  8585. c=0;
  8586. loc = strstr(sstrtemp, "connectorId");
  8587. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8588. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8589. {
  8590. sstr[c] = loc[strlen("connectorId")+2+c];
  8591. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8592. c++;
  8593. }
  8594. sstr[c] = '\0';
  8595. connectorIdInt = atoi(sstr);
  8596. //***(2)expiryDate ****/
  8597. loc = strstr(sstrtemp, "expiryDate");
  8598. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8599. c = 0;
  8600. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8601. {
  8602. sstr[c] = loc[3+strlen("expiryDate")+c];
  8603. c++;
  8604. }
  8605. sstr[c] = '\0';
  8606. strcpy(expiryDatestr, sstr);
  8607. //***(3)idTag ****/
  8608. loc = strstr(sstrtemp, "idTag");
  8609. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8610. c = 0;
  8611. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8612. {
  8613. sstr[c] = loc[3+strlen("idTag")+c];
  8614. c++;
  8615. }
  8616. sstr[c] = '\0';
  8617. strcpy(idTagstr, sstr);
  8618. //***(4)parentIdTag ****/
  8619. loc = strstr(sstrtemp, "parentIdTag");
  8620. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8621. c = 0;
  8622. if(loc == NULL)
  8623. {
  8624. strcpy(parentIdTagstr, "");
  8625. }
  8626. else
  8627. {
  8628. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8629. {
  8630. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8631. c++;
  8632. }
  8633. sstr[c] = '\0';
  8634. strcpy(parentIdTagstr, sstr);
  8635. }
  8636. //***(5)reservationId ****/
  8637. c=0;
  8638. loc = strstr(sstrtemp, "reservationId");
  8639. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8640. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8641. {
  8642. sstr[c] = loc[strlen("reservationId")+2+c];
  8643. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8644. c++;
  8645. }
  8646. sstr[c] = '\0';
  8647. reservationIdInt = atoi(sstr);
  8648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8649. /*
  8650. enum SYSTEM_STATUS
  8651. {
  8652. SYS_MODE_BOOTING = 0,
  8653. SYS_MODE_IDLE = 1,
  8654. SYS_MODE_AUTHORIZING = 2,
  8655. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8656. SYS_MODE_REASSIGN = 4,
  8657. SYS_MODE_PREPARING = 5,
  8658. SYS_MODE_PREPARE_FOR_EV = 6,
  8659. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8660. SYS_MODE_CHARGING = 8,
  8661. SYS_MODE_TERMINATING = 9,
  8662. SYS_MODE_COMPLETE = 10,
  8663. SYS_MODE_ALARM = 11,
  8664. SYS_MODE_FAULT = 12,
  8665. SYS_MODE_RESERVATION = 13,
  8666. SYS_MODE_BOOKING = 14,
  8667. SYS_MODE_MAINTAIN = 15,
  8668. SYS_MODE_DEBUG = 16,
  8669. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8670. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8671. SYS_MODE_UPDATE = 19
  8672. };
  8673. */
  8674. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8675. {
  8676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8677. goto end;
  8678. }
  8679. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8680. {
  8681. //check Transaction active
  8682. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8683. {
  8684. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8685. {
  8686. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8687. }
  8688. else
  8689. {
  8690. tempIndex = connectorIdInt -1;
  8691. }
  8692. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8693. {
  8694. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8695. {
  8696. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8697. {
  8698. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8699. {
  8700. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8701. {
  8702. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8703. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8704. }
  8705. 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'))
  8706. {
  8707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8708. }
  8709. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8710. {
  8711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8712. }
  8713. else
  8714. {
  8715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8716. }
  8717. }
  8718. 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
  8719. {
  8720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8721. }
  8722. }
  8723. else
  8724. {
  8725. //replace reservation
  8726. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8727. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8728. }
  8729. }
  8730. } // END FOR CHAdeMO_QUANTITY
  8731. }
  8732. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8733. {
  8734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8735. {
  8736. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8737. }
  8738. else
  8739. {
  8740. tempIndex = connectorIdInt -1;
  8741. }
  8742. for (int index = 0; index < CCS_QUANTITY; index++)
  8743. {
  8744. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8745. {
  8746. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8747. {
  8748. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8749. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8750. {
  8751. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8752. {
  8753. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8754. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8755. }
  8756. 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'))
  8757. {
  8758. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8759. }
  8760. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8761. {
  8762. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8763. }
  8764. else
  8765. {
  8766. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8767. }
  8768. }
  8769. 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
  8770. {
  8771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8772. }
  8773. }
  8774. else
  8775. {
  8776. //replace reservation
  8777. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8778. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8779. }
  8780. }
  8781. } // END FOR CCS_QUANTITY
  8782. }
  8783. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8784. {
  8785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8786. {
  8787. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8788. }
  8789. else
  8790. {
  8791. tempIndex = connectorIdInt -1;
  8792. }
  8793. for (int index = 0; index < GB_QUANTITY; index++)
  8794. {
  8795. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8796. {
  8797. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8798. {
  8799. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8800. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8801. {
  8802. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8803. {
  8804. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8805. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8806. }
  8807. 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'))
  8808. {
  8809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8810. }
  8811. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8812. {
  8813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8814. }
  8815. else
  8816. {
  8817. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8818. }
  8819. }
  8820. 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
  8821. {
  8822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8823. }
  8824. }
  8825. else
  8826. {
  8827. //replace reservation
  8828. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8830. }
  8831. }
  8832. }// END FOR GB_QUANTITY
  8833. }
  8834. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8835. {
  8836. tempIndex = connectorIdInt -1;
  8837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8838. {
  8839. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8840. {
  8841. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8842. {
  8843. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8844. 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
  8845. {
  8846. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8847. {
  8848. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8849. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8850. }
  8851. 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'))
  8852. {
  8853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8854. }
  8855. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8856. {
  8857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8858. }
  8859. else
  8860. {
  8861. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8862. }
  8863. }
  8864. 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
  8865. {
  8866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8867. }
  8868. }
  8869. else
  8870. {
  8871. //replace reservation
  8872. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8874. }
  8875. }
  8876. }// END FOR GB_QUANTITY
  8877. }
  8878. else
  8879. {
  8880. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8881. {
  8882. tempIndex = 2;
  8883. }
  8884. else
  8885. {
  8886. tempIndex = (connectorIdInt -1);
  8887. }
  8888. for (int index = 0; index < AC_QUANTITY; index++)
  8889. {
  8890. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8891. {
  8892. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8893. {
  8894. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8895. {
  8896. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8897. {
  8898. 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))
  8899. {
  8900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8901. }
  8902. else
  8903. {
  8904. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8906. }
  8907. }
  8908. 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'))
  8909. {
  8910. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8911. }
  8912. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8913. {
  8914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8915. }
  8916. else
  8917. {
  8918. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8919. }
  8920. }
  8921. 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
  8922. {
  8923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8924. }
  8925. }
  8926. else
  8927. {
  8928. //replace reservation
  8929. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8931. }
  8932. }
  8933. } // END FOR AC_QUANTITY
  8934. }
  8935. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8936. }
  8937. else if(connectorIdInt == 0)
  8938. {
  8939. //check Transaction active
  8940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8941. {
  8942. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8943. {
  8944. 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'))
  8945. {
  8946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8947. goto end;
  8948. }
  8949. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8950. {
  8951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8952. goto end;
  8953. }
  8954. 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
  8955. {
  8956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8957. goto end;
  8958. }
  8959. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8960. {
  8961. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8962. goto end;
  8963. }
  8964. }
  8965. }// END FOR CHAdeMO_QUANTITY
  8966. for (int index = 0; index < CCS_QUANTITY; index++)
  8967. {
  8968. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8969. {
  8970. 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'))
  8971. {
  8972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8973. goto end;
  8974. }
  8975. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8976. {
  8977. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8978. goto end;
  8979. }
  8980. 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
  8981. {
  8982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8983. goto end;
  8984. }
  8985. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8986. {
  8987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8988. goto end;
  8989. }
  8990. }
  8991. } // END FOR CCS_QUANTITY
  8992. for (int index = 0; index < GB_QUANTITY; index++)
  8993. {
  8994. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8995. {
  8996. 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'))
  8997. {
  8998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8999. goto end;
  9000. }
  9001. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9002. {
  9003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9004. goto end;
  9005. }
  9006. 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
  9007. {
  9008. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9009. goto end;
  9010. }
  9011. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9012. {
  9013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9014. goto end;
  9015. }
  9016. }
  9017. } // END FOR GB_QUANTITY
  9018. for (int index = 0; index < AC_QUANTITY; index++)
  9019. {
  9020. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9021. {
  9022. 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'))
  9023. {
  9024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9025. goto end;
  9026. }
  9027. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9028. {
  9029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9030. goto end;
  9031. }
  9032. 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
  9033. {
  9034. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9035. goto end;
  9036. }
  9037. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9038. {
  9039. 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))
  9040. {
  9041. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9042. goto end;
  9043. }
  9044. }
  9045. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9046. {
  9047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9048. goto end;
  9049. }
  9050. }
  9051. }// END FOR AC_QUANTITY
  9052. //The connectorId is 0
  9053. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  9054. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9055. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9056. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  9057. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9058. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  9059. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9060. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  9061. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  9062. result = TRUE;
  9063. return result;
  9064. }
  9065. else
  9066. {
  9067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9068. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9069. }
  9070. if(strcmp(comfirmstr,"Accepted") == 0)
  9071. {
  9072. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9073. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9074. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9075. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9076. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9077. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  9078. result = TRUE;
  9079. return result;
  9080. }
  9081. end:
  9082. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9083. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9084. return result;
  9085. }
  9086. int handleResetRequest(char *uuid, char *payload)
  9087. {
  9088. mtrace();
  9089. int result = FAIL;
  9090. char sstr[10]={0},sstrtemp[30]={ 0 };
  9091. char typestr[10]={0};
  9092. char comfirmstr[20]={0};
  9093. int c = 0;
  9094. char *loc;
  9095. DEBUG_INFO("handleResetRequest...\n");
  9096. strcpy(sstrtemp, stringtrimspace(payload));
  9097. loc = strstr(sstrtemp, "type");
  9098. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9099. c = 0;
  9100. while (loc[3+strlen("type")+c] != '\"')
  9101. {
  9102. sstr[c] = loc[3+strlen("type")+c];
  9103. c++;
  9104. }
  9105. sstr[c] = '\0';
  9106. strcpy(typestr,sstr);
  9107. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  9108. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9109. {
  9110. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  9111. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  9112. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9113. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9114. }
  9115. else
  9116. {
  9117. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9118. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9119. result = PASS;
  9120. }
  9121. sendResetConfirmation(uuid, comfirmstr);
  9122. return result;
  9123. }
  9124. int handleSendLocalListRequest(char *uuid, char *payload)
  9125. {
  9126. mtrace();
  9127. int result = FAIL;
  9128. int listVersionInt;
  9129. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9130. char listsearch[]="listVersion";
  9131. char updateTypesearch[]="updateType";
  9132. char localAuthorizationListsearch[]="localAuthorizationList";
  9133. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9134. char CardList[500][160]={0};
  9135. char updateTypestr[15]={0};
  9136. char idTagstr[20]={0};
  9137. char parentIdTag[20]={0};
  9138. char expiryDate[30]={0};
  9139. char idTagstatus[16]={0};
  9140. int c = 0;
  9141. int i = 0;
  9142. char *delim1 = "}";
  9143. char * pch;
  9144. char *loc;
  9145. //char *ptr;
  9146. char comfirmstr[20];
  9147. //int n_localAuthorizations = 0;
  9148. int checkState_Faulted = FALSE;
  9149. DEBUG_INFO("handleSendLocalListRequest...\n");
  9150. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9151. {
  9152. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9153. goto end;
  9154. }
  9155. //check Charge Point state
  9156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9157. {
  9158. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9159. {
  9160. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9161. }
  9162. }
  9163. for (int index = 0; index < CCS_QUANTITY; index++)
  9164. {
  9165. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9166. {
  9167. checkState_Faulted = TRUE; //OCPP Status
  9168. }
  9169. }
  9170. for (int index = 0; index < GB_QUANTITY; index++)
  9171. {
  9172. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9173. {
  9174. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9175. }
  9176. }
  9177. //check Charge Point state
  9178. for (int index = 0; index < AC_QUANTITY; index++)
  9179. {
  9180. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9181. {
  9182. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9183. }
  9184. }
  9185. if(checkState_Faulted == TRUE)
  9186. {
  9187. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9188. goto end;
  9189. }
  9190. //Filter payload space
  9191. strcpy(sstrtemp, stringtrimspace(payload));
  9192. //listVersion
  9193. c = 0;
  9194. loc = strstr(sstrtemp, listsearch);
  9195. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9196. {
  9197. sstr[c] = loc[strlen("listVersion")+2+c];
  9198. c++;
  9199. }
  9200. sstr[c] = '\0';
  9201. listVersionInt = atoi(sstr);
  9202. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9203. //updateType
  9204. loc = strstr(sstrtemp, updateTypesearch);
  9205. c = 0;
  9206. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9207. {
  9208. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9209. c++;
  9210. }
  9211. sstr[c] = '\0';
  9212. strcpy(updateTypestr, sstr);
  9213. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9214. //localAuthorizationList
  9215. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9216. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9217. if(loc != NULL) // localAuthorizationList is not NULL
  9218. {
  9219. //Check UpdateType
  9220. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9221. {
  9222. //Local list full update
  9223. printf("Local list full update.\n");
  9224. OCPP_getListVerion();
  9225. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9226. {
  9227. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9228. goto end;
  9229. }
  9230. OCPP_cleanLocalList();
  9231. }
  9232. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9233. {
  9234. //Local list different update
  9235. printf("Local list different update.\n");
  9236. OCPP_getListVerion();
  9237. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9238. {
  9239. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9240. goto end;
  9241. }
  9242. }
  9243. else
  9244. {
  9245. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9246. goto end;
  9247. }
  9248. c = 0;
  9249. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9250. {
  9251. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9252. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9253. c++;
  9254. }
  9255. sstr[c] = '\0';
  9256. //DEBUG_INFO("sstr=%s\n", sstr);
  9257. //parsing strings to words
  9258. i = 0;
  9259. pch = strtok(sstr,delim1);
  9260. while (pch != NULL)
  9261. {
  9262. strcpy(CardList[i], pch);
  9263. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9264. pch = strtok (NULL, delim1);
  9265. i = i + 1;
  9266. }
  9267. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9268. //local Authorizations List Numbers
  9269. //n_localAuthorizations = i;
  9270. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9271. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9272. c= 0;
  9273. while(c < i) // i is CardList Number
  9274. {
  9275. //Search "IdToken"
  9276. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9277. loc = strstr(CardList[c], "idTag");
  9278. int j = 0;
  9279. while (loc[3+strlen("idTag")+j] != '\"')
  9280. {
  9281. sstr[j] = loc[3+strlen("idTag")+j];
  9282. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9283. j++;
  9284. }
  9285. sstr[j] = '\0';
  9286. strcpy(idTagstr, sstr);
  9287. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9288. //Search "expiryDate"
  9289. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9290. loc = strstr(CardList[c], "expiryDate");
  9291. j = 0;
  9292. if(loc != NULL)
  9293. {
  9294. while (loc[3+strlen("expiryDate")+j] != '\"')
  9295. {
  9296. sstr[j] = loc[3+strlen("expiryDate")+j];
  9297. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9298. j++;
  9299. }
  9300. sstr[j] = '\0';
  9301. strcpy(expiryDate, sstr);
  9302. }
  9303. else
  9304. {
  9305. strcpy(expiryDate, "");
  9306. }
  9307. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9308. //Search "parentIdTag"
  9309. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9310. loc = strstr(CardList[c], "parentIdTag");
  9311. j = 0;
  9312. if(loc != NULL)
  9313. {
  9314. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9315. {
  9316. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9317. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9318. j++;
  9319. }
  9320. sstr[j] = '\0';
  9321. strcpy(parentIdTag, sstr);
  9322. }
  9323. else
  9324. {
  9325. strcpy(parentIdTag, "");
  9326. }
  9327. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9328. //Search "status"
  9329. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9330. loc = strstr(CardList[c], "status");
  9331. j = 0;
  9332. while (loc[3+strlen("status")+j] != '\"')
  9333. {
  9334. sstr[j] = loc[3+strlen("status")+j];
  9335. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9336. j++;
  9337. }
  9338. sstr[j] = '\0';
  9339. strcpy(idTagstatus, sstr);
  9340. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9341. OCPP_getIdTagFromLocalList(idTagstr);
  9342. //OCPP_getIdTagFromLocalList("test"); For Test
  9343. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9344. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9345. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9346. {
  9347. //Local list full update
  9348. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9349. // update list
  9350. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9351. //DEBUG_INFO("Local list full update. 1\n");
  9352. //OCPP_get_TableAuthlocalAllData();
  9353. //DEBUG_INFO("Local list full update. 2\n");
  9354. }
  9355. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9356. {
  9357. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9358. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9359. }
  9360. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9361. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9362. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9363. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9364. c++;
  9365. }
  9366. }
  9367. else
  9368. {
  9369. //Check UpdateType
  9370. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9371. {
  9372. //Local list full update
  9373. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9374. OCPP_cleanLocalList();
  9375. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9376. goto end;
  9377. }
  9378. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9379. {
  9380. //Local list different update
  9381. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9382. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9383. goto end;
  9384. }
  9385. }
  9386. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9387. end:
  9388. sendSendLocalListConfirmation(uuid, comfirmstr);
  9389. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9390. return result;
  9391. }
  9392. #define MAX 200
  9393. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9394. {
  9395. mtrace();
  9396. int result = FAIL;
  9397. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9398. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9399. char chargingProfilePurposeStr[30]={0};
  9400. char chargingProfileKindStr[16]={0};
  9401. char recurrencyKindStr[10]={0};
  9402. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9403. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9404. int chargingSchedulePeriodCount = 0;
  9405. char comfirmstr[20]={0};
  9406. int meet= FALSE;
  9407. FILE *fptr1;
  9408. char filename[MAX]={0};
  9409. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9410. char rmFileCmd[50]={0};
  9411. char tempchargingProfilePurposeStr[30]={0};
  9412. char word[1600]={0};
  9413. int n_chargingProfile = 0;
  9414. json_object *SetChargingProfile;
  9415. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9416. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9417. SetChargingProfile = json_tokener_parse(payload);
  9418. if(!is_error(SetChargingProfile))
  9419. {
  9420. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9421. {
  9422. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9423. if(connectorIdInt == 0)
  9424. {
  9425. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9426. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9427. }
  9428. else
  9429. {
  9430. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9431. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9432. }
  9433. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9434. }
  9435. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9436. {
  9437. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9438. {
  9439. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9440. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9441. {
  9442. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9443. }
  9444. else
  9445. {
  9446. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9447. }
  9448. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9449. }
  9450. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9451. {
  9452. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9453. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9454. {
  9455. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9456. }
  9457. else
  9458. {
  9459. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9460. }
  9461. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9462. }
  9463. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9464. {
  9465. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9466. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9467. {
  9468. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9469. }
  9470. else
  9471. {
  9472. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9473. }
  9474. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9475. }
  9476. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9477. {
  9478. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9479. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9480. {
  9481. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9482. }
  9483. else
  9484. {
  9485. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9486. }
  9487. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9488. }
  9489. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9490. {
  9491. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9492. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9493. {
  9494. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9495. }
  9496. else
  9497. {
  9498. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9499. }
  9500. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9501. }
  9502. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9503. {
  9504. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9505. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9506. {
  9507. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9508. }
  9509. else
  9510. {
  9511. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9512. }
  9513. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9514. }
  9515. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9516. {
  9517. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9518. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9519. {
  9520. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9521. }
  9522. else
  9523. {
  9524. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9525. }
  9526. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9527. }
  9528. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9529. {
  9530. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9531. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9532. {
  9533. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9534. }
  9535. else
  9536. {
  9537. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9538. }
  9539. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9540. }
  9541. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9542. {
  9543. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9544. {
  9545. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9546. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9547. {
  9548. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9549. }
  9550. else
  9551. {
  9552. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9553. }
  9554. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9555. }
  9556. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9557. {
  9558. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9559. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9560. {
  9561. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9562. }
  9563. else
  9564. {
  9565. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9566. }
  9567. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9568. }
  9569. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9570. {
  9571. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9572. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9573. {
  9574. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9575. }
  9576. else
  9577. {
  9578. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9579. }
  9580. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9581. }
  9582. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9583. {
  9584. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9585. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9586. {
  9587. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9588. }
  9589. else
  9590. {
  9591. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9592. }
  9593. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9594. }
  9595. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9596. {
  9597. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9598. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9599. if(chargingSchedulePeriodCount <= 10)
  9600. {
  9601. 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++)
  9602. {
  9603. 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)
  9604. {
  9605. startPeriodInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  9606. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9607. {
  9608. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9609. }
  9610. else
  9611. {
  9612. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9613. }
  9614. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9615. }
  9616. 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)
  9617. {
  9618. limitflaot[idxPeriod] = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  9619. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9620. {
  9621. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9622. }
  9623. else
  9624. {
  9625. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9626. }
  9627. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9628. }
  9629. 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)
  9630. {
  9631. numberPhasesInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  9632. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9633. {
  9634. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9635. }
  9636. else
  9637. {
  9638. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9639. }
  9640. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9641. }
  9642. }
  9643. }
  9644. }
  9645. }
  9646. }
  9647. }
  9648. json_object_put(SetChargingProfile);
  9649. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9650. {
  9651. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9652. goto end;
  9653. }
  9654. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9655. {
  9656. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9657. if(connectorIdInt != 0)
  9658. {
  9659. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9660. goto end;
  9661. }
  9662. strcpy(filename, ChargePointMaxProfile_JSON );
  9663. fptr1 = fopen(filename, "r");
  9664. if (!fptr1)
  9665. {
  9666. //file not exist
  9667. DEBUG_INFO("Unable to open the input file!!\n");
  9668. fptr1 = fopen(filename, "w+");
  9669. }
  9670. else
  9671. {
  9672. //Check Charging Profile Count
  9673. while(fscanf(fptr1, "%s", word) != EOF)
  9674. {
  9675. //DEBUG_INFO("word=%s\n",word);
  9676. if(strstr(word, "chargingProfileId")!= NULL)
  9677. {
  9678. //DEBUG_INFO("test chargingProfileId \n");
  9679. n_chargingProfile = n_chargingProfile + 1;
  9680. //DEBUG_INFO("chargingProfileId Found\n");
  9681. }
  9682. }
  9683. }
  9684. fclose(fptr1);
  9685. }
  9686. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9687. {
  9688. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9689. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9690. {
  9691. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9692. goto end;
  9693. }
  9694. memset(filename, 0, ARRAY_SIZE(filename));
  9695. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9696. fptr1 = fopen(filename, "r");
  9697. if (!fptr1)
  9698. {
  9699. //file not exist
  9700. //DEBUG_INFO("Unable to open the input file!!\n");
  9701. fptr1 = fopen(filename, "w+");
  9702. }
  9703. else
  9704. {
  9705. //Check Charging Profile Count
  9706. while(fscanf(fptr1, "%s", word) != EOF)
  9707. {
  9708. //DEBUG_INFO("word=%s\n",word);
  9709. if(strstr(word, "chargingProfileId")!= NULL)
  9710. {
  9711. //DEBUG_INFO("test chargingProfileId \n");
  9712. n_chargingProfile = n_chargingProfile + 1;
  9713. //DEBUG_INFO("chargingProfileId Found\n");
  9714. }
  9715. }
  9716. }
  9717. fclose(fptr1);
  9718. }
  9719. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9720. {
  9721. //printf("set chargingProfile 1-4\n");
  9722. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9723. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9724. if(connectorIdInt == 0)
  9725. {
  9726. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9727. goto end;
  9728. }
  9729. int tempIndex = 0;
  9730. //check Transaction active
  9731. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9732. {
  9733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9734. {
  9735. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9736. }
  9737. else
  9738. {
  9739. tempIndex = connectorIdInt -1;
  9740. }
  9741. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9742. {
  9743. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9744. {
  9745. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9746. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9747. {
  9748. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9749. {
  9750. meet = TRUE;
  9751. break;
  9752. }
  9753. }
  9754. }
  9755. }
  9756. }
  9757. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9758. {
  9759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9760. {
  9761. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9762. }
  9763. else
  9764. {
  9765. tempIndex = connectorIdInt -1;
  9766. }
  9767. for (int index = 0; index < CCS_QUANTITY; index++)
  9768. {
  9769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9770. {
  9771. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9772. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9773. {
  9774. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9775. {
  9776. meet = TRUE;
  9777. break;
  9778. }
  9779. }
  9780. }
  9781. }
  9782. }
  9783. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9784. {
  9785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9786. {
  9787. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9788. }
  9789. else
  9790. {
  9791. tempIndex = connectorIdInt -1;
  9792. }
  9793. for (int index = 0; index < GB_QUANTITY; index++)
  9794. {
  9795. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9796. {
  9797. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9798. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9799. {
  9800. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9801. {
  9802. meet = TRUE;
  9803. break;
  9804. }
  9805. }
  9806. }
  9807. }
  9808. }
  9809. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9810. {
  9811. tempIndex = connectorIdInt -1;
  9812. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9813. {
  9814. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9815. {
  9816. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9817. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9818. {
  9819. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9820. {
  9821. meet = TRUE;
  9822. break;
  9823. }
  9824. }
  9825. }
  9826. }
  9827. }
  9828. else
  9829. {
  9830. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9831. {
  9832. tempIndex = 2;
  9833. }
  9834. else
  9835. {
  9836. tempIndex = (connectorIdInt -1);
  9837. }
  9838. for (int index = 0; index < AC_QUANTITY; index++)
  9839. {
  9840. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9841. {
  9842. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9843. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9844. {
  9845. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9846. {
  9847. meet = TRUE;
  9848. break;
  9849. }
  9850. }
  9851. }
  9852. }
  9853. }
  9854. //check Transaction active
  9855. if(meet == FALSE)
  9856. {
  9857. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9858. goto end;
  9859. }
  9860. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9861. {
  9862. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9863. goto end;
  9864. }
  9865. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9866. fptr1 = fopen(filename, "r");
  9867. if (!fptr1)
  9868. {
  9869. //file not exist
  9870. DEBUG_INFO("Unable to open the input file!!\n");
  9871. fptr1 = fopen(filename, "w+");
  9872. }
  9873. else
  9874. {
  9875. //Check Charging Profile Count
  9876. while(fscanf(fptr1, "%s", word) != EOF)
  9877. {
  9878. //DEBUG_INFO("word=%s\n",word);
  9879. if(strstr(word, "chargingProfileId")!= NULL)
  9880. {
  9881. //DEBUG_INFO("test chargingProfileId \n");
  9882. n_chargingProfile = n_chargingProfile + 1;
  9883. //DEBUG_INFO("chargingProfileId Found\n");
  9884. }
  9885. }
  9886. }
  9887. fclose(fptr1);
  9888. }
  9889. // Check ChargeProfileMaxStackLevel
  9890. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9891. {
  9892. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9893. goto end;
  9894. }
  9895. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9896. {
  9897. int i = 0;
  9898. char fnametemp[200]={0};
  9899. n_chargingProfile = 0;
  9900. //Check ChargePointMaxProfile.json exit
  9901. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9902. {
  9903. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9904. //Check Charging Profile Count
  9905. while(fscanf(fptr1, "%s", word) != EOF)
  9906. {
  9907. //DEBUG_INFO("word=%s\n",word);
  9908. if(strstr(word, "chargingProfileId")!= NULL)
  9909. {
  9910. //DEBUG_INFO("test chargingProfileId \n");
  9911. n_chargingProfile = n_chargingProfile + 1;
  9912. i = i + 1;
  9913. //DEBUG_INFO("chargingProfileId Found\n");
  9914. }
  9915. memset(word, 0, ARRAY_SIZE(word));
  9916. }
  9917. fclose(fptr1);
  9918. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9919. }
  9920. //Check TxDefaultProfile_0.json exit
  9921. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9922. {
  9923. i = 0;
  9924. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9925. //Check Charging Profile Count
  9926. while(fscanf(fptr1, "%s", word) != EOF)
  9927. {
  9928. //DEBUG_INFO("word=%s\n",word);
  9929. if(strstr(word, "chargingProfileId")!= NULL)
  9930. {
  9931. //DEBUG_INFO("test chargingProfileId \n");
  9932. n_chargingProfile = n_chargingProfile + 1;
  9933. i = i + 1;
  9934. //DEBUG_INFO("chargingProfileId Found\n");
  9935. }
  9936. memset(word, 0, ARRAY_SIZE(word));
  9937. }
  9938. fclose(fptr1);
  9939. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9940. }
  9941. //Check TxDefaultProfile_%d.json
  9942. for(int j=1; j <= gunTotalNumber; j++)
  9943. {
  9944. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9945. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9946. if((access(fnametemp,F_OK))!=-1)
  9947. {
  9948. i = 0;
  9949. fptr1 = fopen(fnametemp, "r");
  9950. //Check Charging Profile Count
  9951. while(fscanf(fptr1, "%s", word) != EOF)
  9952. {
  9953. //DEBUG_INFO("word=%s\n",word);
  9954. if(strstr(word, "chargingProfileId")!= NULL)
  9955. {
  9956. //DEBUG_INFO("test chargingProfileId \n");
  9957. n_chargingProfile = n_chargingProfile + 1;
  9958. i = i + 1;
  9959. //DEBUG_INFO("chargingProfileId Found\n");
  9960. }
  9961. memset(word, 0, ARRAY_SIZE(word));
  9962. }
  9963. fclose(fptr1);
  9964. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9965. }
  9966. }
  9967. //Check TxProfile_%d.json
  9968. for(int j=1; j <= gunTotalNumber; j++)
  9969. {
  9970. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9971. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9972. if((access(fnametemp,F_OK))!=-1)
  9973. {
  9974. i = 0;
  9975. fptr1 = fopen(fnametemp, "r");
  9976. //Check Charging Profile Count
  9977. while(fscanf(fptr1, "%s", word) != EOF)
  9978. {
  9979. //DEBUG_INFO("word=%s\n",word);
  9980. if(strstr(word, "chargingProfileId")!= NULL)
  9981. {
  9982. //DEBUG_INFO("test chargingProfileId \n");
  9983. n_chargingProfile = n_chargingProfile + 1;
  9984. i = i + 1;
  9985. //DEBUG_INFO("chargingProfileId Found\n");
  9986. }
  9987. memset(word, 0, ARRAY_SIZE(word));
  9988. }
  9989. fclose(fptr1);
  9990. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9991. }
  9992. }
  9993. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9994. {
  9995. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9996. goto end;
  9997. }
  9998. }
  9999. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10000. //**********************************Write to File********************************************************/
  10001. FILE *infile;
  10002. FILE *outfile;
  10003. infile = fopen (filename, "r");
  10004. outfile = fopen (tempfile, "w");
  10005. int d =0;
  10006. d = fgetc(infile);
  10007. rewind(infile);
  10008. if(d == EOF)
  10009. {
  10010. // Profile is empty
  10011. fprintf(outfile,"%s\n",payload);
  10012. fclose(infile);
  10013. fclose(outfile);
  10014. sprintf(rmFileCmd,"rm -f %s",filename);
  10015. system(rmFileCmd);
  10016. rename(tempfile, filename);
  10017. }
  10018. else
  10019. {
  10020. // Profile is not empty
  10021. char buf[2048]={0};
  10022. int ChargingProfileAdded = FALSE;
  10023. while (fgets(buf, sizeof(buf), infile) != NULL)
  10024. {
  10025. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10026. json_object *tmpChargingProfile;
  10027. tmpChargingProfile = json_tokener_parse(buf);
  10028. if(!is_error(SetChargingProfile))
  10029. {
  10030. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10031. {
  10032. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10033. }
  10034. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10035. {
  10036. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10037. {
  10038. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10039. }
  10040. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10041. {
  10042. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10043. }
  10044. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10045. {
  10046. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10047. }
  10048. }
  10049. }
  10050. json_object_put(tmpChargingProfile);
  10051. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10052. {
  10053. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10054. {
  10055. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10056. if(ChargingProfileAdded == FALSE)
  10057. {
  10058. fprintf(outfile,"%s\n",payload);
  10059. ChargingProfileAdded = TRUE;
  10060. }
  10061. }
  10062. else
  10063. {
  10064. if(tempstackLevelInt < stackLevelInt)
  10065. {
  10066. if(ChargingProfileAdded == FALSE)
  10067. {
  10068. fprintf(outfile,"%s\n",buf);
  10069. fprintf(outfile,"%s\n",payload);
  10070. ChargingProfileAdded = TRUE;
  10071. }
  10072. else
  10073. {
  10074. fprintf(outfile,"%s\n",buf);
  10075. }
  10076. }
  10077. else
  10078. {
  10079. if(ChargingProfileAdded == FALSE)
  10080. {
  10081. fprintf(outfile,"%s\n",buf);
  10082. fprintf(outfile,"%s\n",payload);
  10083. ChargingProfileAdded = TRUE;
  10084. }
  10085. else
  10086. {
  10087. fprintf(outfile,"%s\n",buf);
  10088. }
  10089. }
  10090. }
  10091. }
  10092. else
  10093. {
  10094. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10095. {
  10096. if(ChargingProfileAdded == FALSE)
  10097. {
  10098. fprintf(outfile,"%s\n",buf);
  10099. fprintf(outfile,"%s\n",payload);
  10100. ChargingProfileAdded = TRUE;
  10101. }
  10102. else
  10103. {
  10104. fprintf(outfile,"%s\n",buf);
  10105. }
  10106. }
  10107. else if(tempstackLevelInt < stackLevelInt)
  10108. {
  10109. if(ChargingProfileAdded == FALSE)
  10110. {
  10111. fprintf(outfile,"%s\n",buf);
  10112. fprintf(outfile,"%s\n",payload);
  10113. ChargingProfileAdded = TRUE;
  10114. }
  10115. else
  10116. {
  10117. fprintf(outfile,"%s\n",buf);
  10118. }
  10119. }
  10120. else
  10121. {
  10122. if(ChargingProfileAdded == FALSE)
  10123. {
  10124. fprintf(outfile,"%s\n",buf);
  10125. fprintf(outfile,"%s\n",payload);
  10126. ChargingProfileAdded = TRUE;
  10127. }
  10128. else
  10129. {
  10130. fprintf(outfile,"%s\n",buf);
  10131. }
  10132. }
  10133. }
  10134. } // end of while loop
  10135. fclose(infile);
  10136. fclose(outfile);
  10137. sprintf(rmFileCmd,"rm -f %s",filename);
  10138. system(rmFileCmd);
  10139. rename(tempfile, filename);
  10140. }
  10141. sleep(1);
  10142. result = TRUE;
  10143. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10144. end:
  10145. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10146. {
  10147. if(connectorIdInt == 0)
  10148. {
  10149. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10150. {
  10151. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10152. }
  10153. }
  10154. else
  10155. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10156. }
  10157. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10158. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10159. return result;
  10160. }
  10161. int handleTriggerMessageRequest(char *uuid, char *payload)
  10162. {
  10163. mtrace();
  10164. int result = FAIL;
  10165. int connectorIdIsNULL = FALSE;
  10166. int connectorIdInt =0;
  10167. char sstr[40]={0},sstrtemp[100]={ 0 };
  10168. char requestedMessagestr[40]={0};
  10169. char comfirmstr[20]={0};
  10170. int c = 0;
  10171. char *loc;
  10172. DEBUG_INFO("handleTriggerMessageRequest\n");
  10173. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10174. strcpy(sstrtemp, stringtrimspace(payload));
  10175. c = 0;
  10176. loc = strstr(sstrtemp, "requestedMessage");
  10177. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10178. {
  10179. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10180. c++;
  10181. }
  10182. sstr[c] = '\0';
  10183. strcpy(requestedMessagestr, sstr);
  10184. c = 0;
  10185. loc = strstr(sstrtemp, "connectorId");
  10186. if(loc == NULL)
  10187. {
  10188. connectorIdIsNULL = TRUE;
  10189. }
  10190. else
  10191. {
  10192. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10193. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10194. {
  10195. sstr[c] = loc[strlen("connectorId")+2+c];
  10196. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10197. c++;
  10198. }
  10199. sstr[c] = '\0';
  10200. connectorIdInt = atoi(sstr);
  10201. }
  10202. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10203. {
  10204. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10205. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10206. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10207. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10208. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10209. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10210. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10211. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10212. {
  10213. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10214. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10215. return TRUE;
  10216. }
  10217. else
  10218. {
  10219. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10220. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10221. }
  10222. }
  10223. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10224. {
  10225. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10226. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10227. return TRUE;
  10228. }
  10229. //==========================
  10230. // Trigger message
  10231. //==========================
  10232. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10233. {
  10234. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10235. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10236. {
  10237. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10238. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10239. }
  10240. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10241. }
  10242. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10243. {
  10244. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10245. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10246. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10247. }
  10248. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10249. {
  10250. //sendBootNotificationRequest();
  10251. server_sign = FALSE;
  10252. }
  10253. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10254. {
  10255. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10256. }
  10257. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10258. {
  10259. if(connectorIdIsNULL == FALSE)
  10260. {
  10261. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10262. {
  10263. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10264. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10265. }
  10266. }
  10267. else
  10268. {
  10269. for(int idx=0;idx< gunTotalNumber;idx++)
  10270. {
  10271. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10272. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10273. }
  10274. }
  10275. }
  10276. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10277. {
  10278. if(connectorIdIsNULL == FALSE)
  10279. {
  10280. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10281. {
  10282. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10283. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10284. }
  10285. }
  10286. else
  10287. {
  10288. for(int idx=0;idx< gunTotalNumber;idx++)
  10289. {
  10290. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10291. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10292. }
  10293. }
  10294. }
  10295. return result;
  10296. }
  10297. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10298. {
  10299. mtrace();
  10300. int result = FAIL;
  10301. int connectorIdInt =0;
  10302. char comfirmstr[20]={0};
  10303. int tempIndex = 0;
  10304. json_object *UnlockConnector;
  10305. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10306. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10307. UnlockConnector = json_tokener_parse(payload);
  10308. if(!is_error(UnlockConnector))
  10309. {
  10310. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10311. {
  10312. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10313. }
  10314. }
  10315. json_object_put(UnlockConnector);
  10316. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10317. if(gunTotalNumber == 0)
  10318. {
  10319. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10320. goto end;
  10321. }
  10322. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10323. {
  10324. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10325. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10326. goto end;
  10327. }
  10328. else
  10329. {
  10330. //check Transaction active
  10331. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10332. {
  10333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10334. {
  10335. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10336. }
  10337. else
  10338. {
  10339. tempIndex = connectorIdInt -1;
  10340. }
  10341. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10342. {
  10343. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10344. {
  10345. //stop Transaction
  10346. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10347. }
  10348. }
  10349. }
  10350. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10351. {
  10352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10353. {
  10354. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10355. }
  10356. else
  10357. {
  10358. tempIndex = connectorIdInt -1;
  10359. }
  10360. for (int index = 0; index < CCS_QUANTITY; index++)
  10361. {
  10362. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10363. {
  10364. //stop Transaction
  10365. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10366. }
  10367. }
  10368. }
  10369. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10370. {
  10371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10372. {
  10373. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10374. }
  10375. else
  10376. {
  10377. tempIndex = connectorIdInt -1;
  10378. }
  10379. for (int index = 0; index < GB_QUANTITY; index++)
  10380. {
  10381. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10382. {
  10383. //stop Transaction
  10384. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10385. }
  10386. }
  10387. }
  10388. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10389. {
  10390. tempIndex = connectorIdInt -1;
  10391. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10392. {
  10393. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  10394. {
  10395. //stop Transaction
  10396. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10397. }
  10398. }
  10399. }
  10400. else
  10401. {
  10402. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10403. {
  10404. tempIndex = 2;
  10405. }
  10406. else
  10407. {
  10408. tempIndex = connectorIdInt-1;
  10409. }
  10410. for (int index = 0; index < AC_QUANTITY; index++)
  10411. {
  10412. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10413. {
  10414. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10415. }
  10416. }
  10417. }
  10418. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10419. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10420. result = TRUE;
  10421. return result;
  10422. }
  10423. end:
  10424. //json_object_put(obj); --- remove temporally
  10425. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10426. return result;
  10427. }
  10428. static char UpdateFirmwarepayloadData[300]={0};
  10429. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10430. {
  10431. mtrace();
  10432. int result = FAIL;
  10433. pthread_t t;
  10434. sendUpdateFirmwareConfirmation(uuid);
  10435. memset(UpdateFirmwarepayloadData, 0, 300);
  10436. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10437. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10438. ////pthread_join(t, NULL); //
  10439. //pthread_detach(t);
  10440. //sendUpdateFirmwareConfirmation(uuid);
  10441. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10442. return result;
  10443. }
  10444. void *UpdateFirmwareProcess(void *data)
  10445. {
  10446. pthread_detach(pthread_self());
  10447. mtrace();
  10448. int retriesInt =0, retryIntervalInt=0;
  10449. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  10450. int port=0;
  10451. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  10452. int isSuccess = 0;
  10453. char ftpbuf[1024];
  10454. char temp[1024];
  10455. char * pch;
  10456. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10457. json_object *UpdateFirmware;
  10458. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10459. if(!is_error(UpdateFirmware))
  10460. {
  10461. // Required data
  10462. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10463. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10464. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10465. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10466. // Optional data
  10467. if(json_object_object_get(UpdateFirmware, "retries"))
  10468. {
  10469. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10470. }
  10471. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10472. {
  10473. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10474. }
  10475. }
  10476. json_object_put(UpdateFirmware);
  10477. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10478. memset(path, 0, ARRAY_SIZE(path));
  10479. // Wait retrieveData
  10480. if(strlen(retrieveDatestr) > 10)
  10481. {
  10482. do
  10483. {
  10484. sleep(1);
  10485. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10486. }
  10487. // Ready to download
  10488. system("rm -f /mnt/*");
  10489. if(strncmp(locationstr,"http", 4) == 0)
  10490. {
  10491. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10492. sprintf(ftppath,"/%s", path);
  10493. DEBUG_INFO("locationstr: %s\n", locationstr);
  10494. DEBUG_INFO("protocol: %s\n",protocol);
  10495. DEBUG_INFO("host: %s\n",host);
  10496. DEBUG_INFO("path: %s\n",path);
  10497. DEBUG_INFO("ftppath: %s\n",ftppath);
  10498. int ftppathlen=strlen(ftppath);
  10499. int i=1;
  10500. char filenametemp[50];
  10501. while(i < ftppathlen)
  10502. {
  10503. int len=ftppathlen-i;
  10504. if(ftppath[len]== 47) // '/' ascll code: 47
  10505. {
  10506. DEBUG_INFO("compare '/' all right\n");
  10507. break;
  10508. }
  10509. i=i+1;
  10510. }
  10511. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10512. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10513. filenametemp[i+1] = 0;
  10514. do
  10515. {
  10516. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10517. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10518. sleep(1);
  10519. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10520. if(!isSuccess)
  10521. {
  10522. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10523. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10524. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10525. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10526. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10527. }
  10528. else
  10529. {
  10530. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10531. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10532. }
  10533. retriesInt--;
  10534. }while((isSuccess == 0)&&(retriesInt >= 0));
  10535. }
  10536. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10537. {
  10538. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10539. memset(temp, 0, ARRAY_SIZE(temp));
  10540. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10541. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10542. int ftppathlen=strlen(ftpbuf);
  10543. int i=1;
  10544. char filenametemp[50];
  10545. while(i < ftppathlen)
  10546. {
  10547. int len=ftppathlen-i;
  10548. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10549. {
  10550. DEBUG_INFO(" compare '/' all right\n");
  10551. break;
  10552. }
  10553. i=i+1;
  10554. }
  10555. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10556. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10557. filenametemp[i+1] = 0;
  10558. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10559. pch=strchr(temp,'@');
  10560. if(pch==NULL)
  10561. {
  10562. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10563. protocol, host, &port, path);
  10564. strcpy(user,"anonymous");
  10565. strcpy(password,"");
  10566. }
  10567. else
  10568. {
  10569. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10570. protocol, user, password, host, &port, path);
  10571. }
  10572. sscanf(host,"%[^/]%s",host1, path1);
  10573. sprintf(ftppath,"%s", path1);
  10574. //DEBUG_INFO("protocol =%s\n",protocol);
  10575. //DEBUG_INFO("user =%s\n",user);
  10576. //DEBUG_INFO("password =%s\n",password);
  10577. //DEBUG_INFO("host1 =%s\n",host1);
  10578. //DEBUG_INFO("port =%d\n",port);
  10579. //DEBUG_INFO("path1 =%s\n",path1);
  10580. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10581. //ftpFile(host, user, password, port, ftppath, fname);
  10582. //download firmware pthred
  10583. if(port == 0)
  10584. {
  10585. port = 21;
  10586. }
  10587. do
  10588. {
  10589. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10590. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10591. sleep(1);
  10592. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10593. if(!isSuccess)
  10594. {
  10595. //BulldogUtil.sleepMs(interval*1000);
  10596. DEBUG_INFO("Update firmware request and download file fail.\n");
  10597. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10598. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10599. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10600. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10601. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10602. }
  10603. else
  10604. {
  10605. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10606. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10607. }
  10608. retriesInt--;
  10609. }while((!isSuccess)&&(retriesInt >= 0));
  10610. }
  10611. else
  10612. {
  10613. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10614. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10615. sleep(1);
  10616. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10617. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10618. }
  10619. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10620. pthread_exit(NULL);
  10621. }
  10622. int handleCertificateSignedRequest(char *uuid, char *payload)
  10623. {
  10624. mtrace();
  10625. int result = PASS;
  10626. json_object *CertificateSigned;
  10627. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10628. CertificateSigned = json_tokener_parse(payload);
  10629. if(!is_error(CertificateSigned))
  10630. {
  10631. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10632. }
  10633. json_object_put(CertificateSigned);
  10634. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10635. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10636. fclose(fp);
  10637. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10638. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10639. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10640. sendCertificateSignedConfirmation(uuid);
  10641. return result;
  10642. }
  10643. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10644. {
  10645. mtrace();
  10646. int result = PASS;
  10647. json_object *DeleteCertificate;
  10648. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10649. DeleteCertificate = json_tokener_parse(payload);
  10650. if(!is_error(DeleteCertificate))
  10651. {
  10652. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10653. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10654. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10655. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10656. }
  10657. json_object_put(DeleteCertificate);
  10658. /*
  10659. * TODO: Delete certificateSigned process
  10660. */
  10661. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10662. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10663. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10664. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10665. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10666. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10667. sendDeleteCertificateConfirmation(uuid);
  10668. return result;
  10669. }
  10670. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10671. {
  10672. mtrace();
  10673. int result = PASS;
  10674. json_object *ExtendedTriggerMessage;
  10675. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10676. ExtendedTriggerMessage = json_tokener_parse(payload);
  10677. if(!is_error(ExtendedTriggerMessage))
  10678. {
  10679. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10680. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10681. {
  10682. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10683. }
  10684. else
  10685. {
  10686. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10687. }
  10688. }
  10689. json_object_put(ExtendedTriggerMessage);
  10690. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10691. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10692. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10693. {
  10694. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10695. }
  10696. else
  10697. {
  10698. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10699. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10700. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10701. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10702. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10703. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10704. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10705. {
  10706. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10707. }
  10708. else
  10709. {
  10710. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10711. }
  10712. }
  10713. sendExtendedTriggerMessageConfirmation(uuid);
  10714. //==========================
  10715. // Trigger message
  10716. //==========================
  10717. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10718. {
  10719. //sendBootNotificationRequest();
  10720. server_sign = FALSE;
  10721. }
  10722. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10723. {
  10724. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10725. }
  10726. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10727. {
  10728. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10729. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10730. {
  10731. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10732. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10733. }
  10734. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10735. }
  10736. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10737. {
  10738. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10739. }
  10740. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10741. {
  10742. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10743. {
  10744. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10745. }
  10746. else
  10747. {
  10748. for(int idx=0;idx< gunTotalNumber;idx++)
  10749. {
  10750. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10751. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10752. }
  10753. }
  10754. }
  10755. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10756. {
  10757. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10758. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10759. {
  10760. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  10761. }
  10762. }
  10763. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10764. {
  10765. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10766. {
  10767. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10768. }
  10769. else
  10770. {
  10771. for(int idx=0;idx< gunTotalNumber;idx++)
  10772. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10773. }
  10774. }
  10775. return result;
  10776. }
  10777. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10778. {
  10779. mtrace();
  10780. int result = PASS;
  10781. json_object *GetInstalledCertificateIds;
  10782. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10783. GetInstalledCertificateIds = json_tokener_parse(payload);
  10784. if(!is_error(GetInstalledCertificateIds))
  10785. {
  10786. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10787. }
  10788. json_object_put(GetInstalledCertificateIds);
  10789. /*
  10790. * TODO: Return installed certificate process
  10791. */
  10792. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10793. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10794. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10795. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10796. sendGetInstalledCertificateIdsConfirmation(uuid);
  10797. return result;
  10798. }
  10799. int handleGetLogRequest(char *uuid, char *payload)
  10800. {
  10801. mtrace();
  10802. int result = PASS;
  10803. json_object *GetLog;
  10804. DEBUG_INFO("handleGetLogRequest...\n");
  10805. GetLog = json_tokener_parse(payload);
  10806. if(!is_error(GetLog))
  10807. {
  10808. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10809. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10810. if(json_object_object_get(GetLog, "retries") != NULL)
  10811. {
  10812. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10813. }
  10814. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10815. {
  10816. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10817. }
  10818. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10819. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10820. {
  10821. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10822. }
  10823. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10824. {
  10825. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10826. }
  10827. }
  10828. json_object_put(GetLog);
  10829. /*
  10830. * TODO: Upload log process
  10831. */
  10832. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10833. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10834. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10835. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10836. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10837. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10838. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10839. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10840. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10841. sendGetLogConfirmation(uuid);
  10842. return result;
  10843. }
  10844. int handleInstallCertificateRequest(char *uuid, char *payload)
  10845. {
  10846. mtrace();
  10847. int result = PASS;
  10848. json_object *InstallCertificate;
  10849. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10850. InstallCertificate = json_tokener_parse(payload);
  10851. if(!is_error(InstallCertificate))
  10852. {
  10853. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10854. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10855. /*
  10856. * TODO: Install certificate process
  10857. */
  10858. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10859. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10860. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10861. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10862. sendInstallCertificateConfirmation(uuid);
  10863. }
  10864. json_object_put(InstallCertificate);
  10865. return result;
  10866. }
  10867. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10868. {
  10869. mtrace();
  10870. int result = PASS;
  10871. json_object *SignedUpdateFirmware;
  10872. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10873. SignedUpdateFirmware = json_tokener_parse(payload);
  10874. if(!is_error(SignedUpdateFirmware))
  10875. {
  10876. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10877. {
  10878. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10879. }
  10880. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10881. {
  10882. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10883. }
  10884. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10885. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10886. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10887. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10888. {
  10889. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10890. }
  10891. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10892. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10893. }
  10894. json_object_put(SignedUpdateFirmware);
  10895. /*
  10896. * TODO: Upgrade firmware process
  10897. */
  10898. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10899. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10900. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10901. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10902. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10903. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10904. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10905. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10906. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10907. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10908. sendInstallCertificateConfirmation(uuid);
  10909. return result;
  10910. }
  10911. int handleUnknownRequest(char *uuid, char *payload)
  10912. {
  10913. mtrace();
  10914. int result = PASS;
  10915. DEBUG_INFO("handleUnknownRequest...\n");
  10916. sendUnknownConfirmation(uuid);
  10917. result = PASS;
  10918. return result;
  10919. }
  10920. //==========================================
  10921. // Handle server response routine
  10922. //==========================================
  10923. void handleAuthorizeResponse(char *payload, int gun_index)
  10924. {
  10925. mtrace();
  10926. char expiryDatestr[30]={0};
  10927. char parentIdTagstr[20]={0};
  10928. char statusstr[20]={0};
  10929. int expiryDateISNULL=FALSE;
  10930. int parentIdTagISNULL=FALSE;
  10931. DEBUG_INFO("handleAuthorizeResponse...\n");
  10932. json_object *Authorize;
  10933. Authorize = json_tokener_parse(payload);
  10934. if(!is_error(Authorize))
  10935. {
  10936. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10937. {
  10938. // Required data
  10939. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10940. // Optional data
  10941. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10942. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10943. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10944. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10945. }
  10946. }
  10947. json_object_put(Authorize);
  10948. if(expiryDateISNULL == FALSE)
  10949. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10950. if(parentIdTagISNULL == FALSE)
  10951. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10952. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10953. //Update idTag information to authorization cache if supproted
  10954. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10955. {
  10956. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10957. }
  10958. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10959. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10960. authorizeRetryTimes = 0;
  10961. }
  10962. void handleBootNotificationResponse(char *payload, int gun_index)
  10963. {
  10964. mtrace();
  10965. char statusStr[12]={0};
  10966. char currentTimeStr[30]={0};
  10967. int intervalInt = 0;
  10968. DEBUG_INFO("handleBootNotificationResponse...\n");
  10969. json_object *BootNotification;
  10970. BootNotification = json_tokener_parse(payload);
  10971. if(!is_error(BootNotification))
  10972. {
  10973. // Required data
  10974. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10975. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10976. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10977. }
  10978. json_object_put(BootNotification);
  10979. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10980. BootNotificationInterval = intervalInt;
  10981. HeartBeatWaitTime = intervalInt;
  10982. //write back to ShmOCPP16Data->BootNotification
  10983. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10984. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10985. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10986. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10987. {
  10988. server_sign = TRUE;
  10989. server_pending =FALSE;
  10990. }
  10991. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10992. {
  10993. server_pending = TRUE;
  10994. }
  10995. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  10996. srand(time(NULL));
  10997. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10998. SetOcppConnStatus(TRUE);
  10999. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11000. }
  11001. void handleDataTransferResponse(char *payload, int gun_index)
  11002. {
  11003. char sstr[160]={0};//sstr[200]={ 0 };
  11004. int c = 0;
  11005. char *loc;
  11006. DEBUG_INFO("handleDataTransferResponse ...\n");
  11007. loc = strstr(payload, "status");
  11008. printf("loc=%s\n",loc);
  11009. c = 0;
  11010. while (loc[3+strlen("status")+c] != '\"')
  11011. {
  11012. sstr[c] = loc[3+strlen("status")+c];
  11013. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11014. c++;
  11015. }
  11016. sstr[c] = '\0';
  11017. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11018. }
  11019. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11020. {
  11021. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11022. //struct json_object *obj;
  11023. // obj = json_tokener_parse(payload);
  11024. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11025. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11026. //No fields are defined.
  11027. }
  11028. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11029. {
  11030. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11031. //struct json_object *obj;
  11032. // obj = json_tokener_parse(payload);
  11033. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11034. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11035. //No fields are defined.
  11036. }
  11037. void handleHeartbeatResponse(char *payload, int gun_index)
  11038. {
  11039. mtrace();
  11040. DEBUG_INFO("handleHeartbeatResponse...\n");
  11041. json_object *Heartbeat;
  11042. Heartbeat = json_tokener_parse(payload);
  11043. if(!is_error(Heartbeat))
  11044. {
  11045. // Required data
  11046. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11047. }
  11048. json_object_put(Heartbeat);
  11049. if(FirstHeartBeat == 0)
  11050. {
  11051. FirstHeartBeat = 1;
  11052. DEBUG_INFO("FirstHeartBeat \n");
  11053. }
  11054. HeartBeatWithNOResponse = 0;
  11055. clientTime.Heartbeat=time((time_t*)NULL);
  11056. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11057. }
  11058. void handleMeterValuesResponse(char *payload, int gun_index)
  11059. {
  11060. mtrace();
  11061. DEBUG_INFO("handleMeterValuesResponse...\n");
  11062. }
  11063. void handleStartTransactionResponse(char *payload, int gun_index)
  11064. {
  11065. mtrace();
  11066. //int transactionIdInt = 0;
  11067. FILE *outfile;
  11068. char data[100]={0};
  11069. DEBUG_INFO("handleStartTransactionResponse...\n");
  11070. json_object *StartTransaction;
  11071. StartTransaction = json_tokener_parse(payload);
  11072. if(!is_error(StartTransaction))
  11073. {
  11074. // Required data
  11075. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11076. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11077. // Optional data
  11078. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11079. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11080. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11081. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11082. }
  11083. json_object_put(StartTransaction);
  11084. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11085. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11086. //-----------Start : write to the Queue TransactionId file -----------------//
  11087. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11088. {}
  11089. else
  11090. {
  11091. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11092. if(log == NULL)
  11093. {
  11094. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11095. return ;
  11096. }
  11097. else
  11098. {
  11099. fclose(log);
  11100. }
  11101. }
  11102. // open file for writing
  11103. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11104. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11105. {
  11106. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11107. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11108. fputs(data, outfile);
  11109. fclose (outfile);
  11110. }
  11111. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11112. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11113. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11114. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11115. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11116. }
  11117. void handleStatusNotificationResponse(char *payload, int gun_index)
  11118. {
  11119. mtrace();
  11120. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11121. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11122. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11123. }
  11124. void handleStopTransactionnResponse(char *payload, int gun_index)
  11125. {
  11126. mtrace();
  11127. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11128. json_object *StopTransaction;
  11129. StopTransaction = json_tokener_parse(payload);
  11130. if(!is_error(StopTransaction))
  11131. {
  11132. // Optional data
  11133. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11134. {
  11135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11136. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11137. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11138. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11139. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11140. }
  11141. }
  11142. json_object_put(StopTransaction);
  11143. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11144. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11145. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11146. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11147. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11148. }
  11149. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11150. {
  11151. mtrace();
  11152. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11153. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11154. }
  11155. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11156. {
  11157. mtrace();
  11158. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11159. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11160. }
  11161. void handleSignCertificateResponse(char *payload, int gun_index)
  11162. {
  11163. mtrace();
  11164. DEBUG_INFO("handleSignCertificateResponse...\n");
  11165. json_object *SignCertificate;
  11166. SignCertificate = json_tokener_parse(payload);
  11167. if(!is_error(SignCertificate))
  11168. {
  11169. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11170. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11171. }
  11172. json_object_put(SignCertificate);
  11173. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11174. }
  11175. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11176. {
  11177. mtrace();
  11178. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11179. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11180. }
  11181. //==========================================
  11182. // Handle Error routine
  11183. //==========================================
  11184. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11185. {
  11186. mtrace();
  11187. #ifdef SystemLogMessage
  11188. DEBUG_INFO("errorCode: %s\n", errorCode);
  11189. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11190. DEBUG_INFO("errorDetails: %s\n", payload);
  11191. #endif
  11192. }
  11193. //===============================================
  11194. // Common routine
  11195. //===============================================
  11196. int initialConfigurationTable(void)
  11197. {
  11198. //clock_t start_t, end_t, total_t;
  11199. FILE *fp;
  11200. FILE *outfile;
  11201. char str[512]={0};
  11202. char sstr[256]={0};
  11203. int c = 0;
  11204. char *loc;
  11205. int confVersion = 2;
  11206. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11207. //start_t = clock();
  11208. //printf("Starting of the program, start_t = %ld\n", start_t);
  11209. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11210. // Check configuration file size is correct
  11211. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11212. {
  11213. struct stat st;
  11214. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11215. if(st.st_size < 3100)
  11216. {
  11217. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11218. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11219. }
  11220. }
  11221. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11222. {
  11223. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11224. if(outfile == NULL)
  11225. {
  11226. DEBUG_INFO("Error opening file\n");
  11227. return FALSE;
  11228. }
  11229. /*Core Profile*/
  11230. //AllowOfflineTxForUnknownId
  11231. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11235. //AuthorizationCacheEnabled
  11236. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11240. //AuthorizeRemoteTxRequests
  11241. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11245. //BlinkRepeat
  11246. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11250. //ClockAlignedDataInterval
  11251. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11255. //ConnectionTimeOut
  11256. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11260. //GetConfigurationMaxKeys
  11261. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11265. // HeartbeatInterval
  11266. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11270. // LightIntensity
  11271. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11275. // LocalAuthorizeOffline
  11276. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11280. // LocalPreAuthorize
  11281. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11285. // MaxEnergyOnInvalidId
  11286. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11290. // MeterValuesAlignedData
  11291. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11293. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11295. else
  11296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11298. // MeterValuesAlignedDataMaxLength
  11299. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11301. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11303. else
  11304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11306. // MeterValuesSampledData
  11307. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11309. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11311. else
  11312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11314. // MeterValuesSampledDataMaxLength
  11315. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11317. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11319. else
  11320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11322. // MeterValueSampleInterval
  11323. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11327. // MinimumStatusDuration
  11328. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11331. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11333. // NumberOfConnectors
  11334. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11336. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11337. {
  11338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11339. }
  11340. else
  11341. {
  11342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11343. }
  11344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11345. // ResetRetries
  11346. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11350. // ConnectorPhaseRotation
  11351. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11355. // ConnectorPhaseRotationMaxLength
  11356. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11360. // StopTransactionOnEVSideDisconnect
  11361. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11365. // StopTransactionOnInvalidId
  11366. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11370. // StopTxnAlignedData
  11371. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11375. // StopTxnAlignedDataMaxLength
  11376. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11380. // StopTxnSampledData
  11381. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11383. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11385. else
  11386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11388. // StopTxnSampledDataMaxLength
  11389. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11391. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11392. {
  11393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11394. }
  11395. else
  11396. {
  11397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11398. }
  11399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11400. // SupportedFeatureProfiles
  11401. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11405. // SupportedFeatureProfilesMaxLength
  11406. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11410. // TransactionMessageAttempts
  11411. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11414. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11416. // TransactionMessageRetryInterval
  11417. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11420. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11422. // UnlockConnectorOnEVSideDisconnect
  11423. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11427. // WebSocketPingInterval
  11428. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11432. // QueueOffLineStartTransactionMessage
  11433. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11437. // AuthorizationKey
  11438. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11442. // SecurityProfile
  11443. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11447. // DefaultPrice
  11448. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11452. // CustomDisplayCostAndPrice
  11453. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11457. // CustomIdleFeeAfterStop
  11458. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11462. // Configuration Version
  11463. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11467. //* Local Auth List Management Profile*/
  11468. #if 0
  11469. //For OCTT Test Case
  11470. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11473. #endif
  11474. #if 1
  11475. //LocalAuthListEnabled
  11476. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11480. #endif
  11481. //LocalAuthListMaxLength
  11482. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11486. //SendLocalListMaxLength
  11487. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11491. //ReserveConnectorZeroSupported
  11492. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11496. //* Smart Charging Profile */
  11497. //ChargeProfileMaxStackLevel
  11498. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11502. // ChargingScheduleAllowedChargingRateUnit
  11503. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11507. // ChargingScheduleMaxPeriods
  11508. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11512. // ConnectorSwitch3to1PhaseSupported
  11513. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11517. // MaxChargingProfilesInstalled
  11518. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11522. fclose(outfile);
  11523. }
  11524. else
  11525. {
  11526. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11527. char keystr[60]={0};
  11528. char readonlystr[10]={0};
  11529. char valuestr[256]={0};
  11530. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11531. if(fp == NULL) {
  11532. DEBUG_INFO("Error opening file");
  11533. return FALSE;
  11534. }
  11535. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11536. {
  11537. //DEBUG_INFO("Get Configuration \n");
  11538. if(strlen(str) > 0)
  11539. {
  11540. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11541. //*************************key*********************************/
  11542. if(strstr(str, "key") != NULL)
  11543. {
  11544. loc = strstr(str, "key");
  11545. c = 0;
  11546. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11547. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11548. {
  11549. sstr[c] = loc[strlen("key")+3+c];
  11550. c++;
  11551. }
  11552. sstr[c] = '\0';
  11553. strcpy(keystr,sstr);
  11554. }
  11555. //*************************readonly*********************************/
  11556. if(strstr(str, "readonly") != NULL)
  11557. {
  11558. loc = strstr(str, "readonly");
  11559. c = 0;
  11560. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11561. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11562. {
  11563. sstr[c] = loc[strlen("readonly")+2+c];
  11564. c++;
  11565. }
  11566. sstr[c] = '\0';
  11567. strcpy(readonlystr,sstr);
  11568. }
  11569. //*************************value*********************************/
  11570. if(strstr(str, "value") != NULL)
  11571. {
  11572. loc = strstr(str, "value");
  11573. c = 0;
  11574. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11575. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11576. {
  11577. sstr[c] = loc[strlen("value")+3+c];
  11578. c++;
  11579. }
  11580. sstr[c] = '\0';
  11581. strcpy(valuestr,sstr);
  11582. }
  11583. // DEBUG_INFO("keystr=%s\n",keystr);
  11584. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11585. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11586. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11587. {
  11588. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11589. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11591. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11592. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11593. }
  11594. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11595. {
  11596. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11597. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11599. }
  11600. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11601. {
  11602. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11604. }
  11605. if(strcmp(keystr, "BlinkRepeat") == 0)
  11606. {
  11607. //Charger.BlinkRepeat = Integer.parseInt(value);
  11608. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11610. }
  11611. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11612. {
  11613. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11615. }
  11616. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11617. {
  11618. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11620. }
  11621. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11622. {
  11623. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11625. }
  11626. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11627. {
  11628. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11630. HeartBeatWaitTime = atoi(valuestr);
  11631. }
  11632. if(strcmp(keystr, "LightIntensity") == 0)
  11633. {
  11634. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11636. }
  11637. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11638. {
  11639. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11641. }
  11642. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11643. {
  11644. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11646. }
  11647. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11648. {
  11649. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11651. }
  11652. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11653. {
  11654. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11656. }
  11657. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11658. {
  11659. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11661. }
  11662. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11663. {
  11664. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11666. }
  11667. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11668. {
  11669. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11671. }
  11672. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11673. {
  11674. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11676. }
  11677. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11678. {
  11679. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11681. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11682. }
  11683. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11684. {
  11685. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11687. }
  11688. if(strcmp(keystr, "ResetRetries") == 0)
  11689. {
  11690. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11692. }
  11693. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11694. {
  11695. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11697. }
  11698. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11699. {
  11700. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11702. }
  11703. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11704. {
  11705. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11707. }
  11708. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11709. {
  11710. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11712. }
  11713. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11714. {
  11715. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11717. }
  11718. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11719. {
  11720. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11722. }
  11723. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11724. {
  11725. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11727. }
  11728. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11729. {
  11730. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11732. }
  11733. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11734. {
  11735. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11737. }
  11738. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11739. {
  11740. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11742. }
  11743. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11744. {
  11745. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11746. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11747. TransactionMessageAttemptsValue = atoi(valuestr);
  11748. }
  11749. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11750. {
  11751. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11753. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11754. }
  11755. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11756. {
  11757. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11759. }
  11760. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11761. {
  11762. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11764. }
  11765. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11766. {
  11767. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11769. }
  11770. if(strcmp(keystr, "AuthorizationKey") == 0)
  11771. {
  11772. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11773. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11775. }
  11776. if(strcmp(keystr, "SecurityProfile") == 0)
  11777. {
  11778. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11780. }
  11781. if(strcmp(keystr, "DefaultPrice") == 0)
  11782. {
  11783. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11785. }
  11786. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11787. {
  11788. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11790. }
  11791. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11792. {
  11793. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11795. }
  11796. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11797. {
  11798. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11800. }
  11801. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11802. {
  11803. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11805. }
  11806. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11807. {
  11808. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11810. }
  11811. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11812. {
  11813. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11815. }
  11816. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11817. {
  11818. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11820. }
  11821. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11822. {
  11823. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11825. }
  11826. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11827. {
  11828. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11830. }
  11831. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11832. {
  11833. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11835. }
  11836. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11837. {
  11838. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11840. }
  11841. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11842. {
  11843. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11845. }
  11846. }
  11847. }
  11848. fclose(fp);
  11849. }
  11850. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11851. {
  11852. return PASS;
  11853. }
  11854. else
  11855. {
  11856. return FAIL;
  11857. }
  11858. }
  11859. void StoreConfigurationTable(void)
  11860. {
  11861. FILE *outfile;
  11862. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11863. if(outfile == NULL)
  11864. {
  11865. DEBUG_INFO("Error opening file");
  11866. return ;
  11867. }
  11868. /*Core Profile*/
  11869. //AllowOfflineTxForUnknownId
  11870. /*
  11871. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11872. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11875. */
  11876. //DEBUG_INFO("data=%s\n",data);
  11877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11878. //AuthorizationCacheEnabled
  11879. /*
  11880. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11883. */
  11884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11885. //AuthorizeRemoteTxRequests
  11886. /*
  11887. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11890. */
  11891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11892. //BlinkRepeat
  11893. /*
  11894. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11897. */
  11898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11899. //ClockAlignedDataInterval
  11900. /*
  11901. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11904. */
  11905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11906. //ConnectionTimeOut
  11907. /*
  11908. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11911. */
  11912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11913. //GetConfigurationMaxKeys
  11914. /*
  11915. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11918. */
  11919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11920. // HeartbeatInterval
  11921. /*
  11922. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11925. */
  11926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11927. // LightIntensity
  11928. /*
  11929. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11932. */
  11933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11934. // LocalAuthorizeOffline
  11935. /*
  11936. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11939. */
  11940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11941. // LocalPreAuthorize
  11942. /*
  11943. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11946. */
  11947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11948. // MaxEnergyOnInvalidId
  11949. /*
  11950. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11953. */
  11954. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11956. // MeterValuesAlignedData
  11957. /*
  11958. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11961. */
  11962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11963. // MeterValuesAlignedDataMaxLength
  11964. /*
  11965. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11968. */
  11969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11970. // MeterValuesSampledData
  11971. /*
  11972. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11975. */
  11976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11977. // MeterValuesSampledDataMaxLength
  11978. /*
  11979. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11982. */
  11983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11984. // MeterValueSampleInterval
  11985. /*
  11986. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11989. */
  11990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11991. // MinimumStatusDuration
  11992. /*
  11993. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11996. */
  11997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11998. // NumberOfConnectors
  11999. /*
  12000. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12002. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12003. {
  12004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12005. }
  12006. else
  12007. {
  12008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12009. }
  12010. */
  12011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12012. // ResetRetries
  12013. /*
  12014. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12017. */
  12018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12019. // ConnectorPhaseRotation
  12020. /*
  12021. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12024. */
  12025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12026. // ConnectorPhaseRotationMaxLength
  12027. /*
  12028. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12031. */
  12032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12033. // StopTransactionOnEVSideDisconnect
  12034. /*
  12035. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12038. */
  12039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12040. // StopTransactionOnInvalidId
  12041. /*
  12042. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12045. */
  12046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12047. // StopTxnAlignedData
  12048. /*
  12049. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12052. */
  12053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12054. // StopTxnAlignedDataMaxLength
  12055. /*
  12056. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12059. */
  12060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12061. // StopTxnSampledData
  12062. /*
  12063. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12066. */
  12067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12068. // StopTxnSampledDataMaxLength
  12069. /*
  12070. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12073. */
  12074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12075. // SupportedFeatureProfiles
  12076. /*
  12077. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12080. */
  12081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12082. // SupportedFeatureProfilesMaxLength
  12083. /*
  12084. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12087. */
  12088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12089. // TransactionMessageAttempts
  12090. /*
  12091. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12094. */
  12095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12096. // TransactionMessageRetryInterval
  12097. /*
  12098. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12101. */
  12102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12103. // UnlockConnectorOnEVSideDisconnect
  12104. /*
  12105. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12108. */
  12109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12110. // WebSocketPingInterval
  12111. /*
  12112. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12115. */
  12116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12117. // QueueOffLineStartTransactionMessage
  12118. /*
  12119. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12122. */
  12123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12124. // AuthorizationKey
  12125. /*
  12126. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12129. */
  12130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12131. // SecurityProfile
  12132. /*
  12133. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12136. */
  12137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12138. // DefaultPrice
  12139. /*
  12140. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12143. */
  12144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12145. // CustomDisplayCostAndPrice
  12146. /*
  12147. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12150. */
  12151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12152. // CustomIdleFeeAfterStop
  12153. /*
  12154. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12157. */
  12158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12159. // ConfigurationVersion
  12160. /*
  12161. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12164. */
  12165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12166. //* Local Auth List Management Profile*/
  12167. //LocalAuthListEnabled
  12168. /*
  12169. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12172. */
  12173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12174. //LocalAuthListMaxLength
  12175. /*
  12176. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12179. */
  12180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12181. //SendLocalListMaxLength
  12182. /*
  12183. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12186. */
  12187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12188. //ReserveConnectorZeroSupported
  12189. /*
  12190. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12193. */
  12194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12195. //* Smart Charging Profile */
  12196. //ChargeProfileMaxStackLevel
  12197. /*
  12198. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12201. */
  12202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12203. // ChargingScheduleAllowedChargingRateUnit
  12204. /*
  12205. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12208. */
  12209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12210. // ChargingScheduleMaxPeriods
  12211. /*
  12212. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12215. */
  12216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12217. // ConnectorSwitch3to1PhaseSupported
  12218. /*
  12219. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12222. */
  12223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12224. // MaxChargingProfilesInstalled
  12225. /*
  12226. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12229. */
  12230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12231. fclose(outfile);
  12232. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12233. }
  12234. void getKeyValue(char *keyReq)
  12235. {
  12236. int isEmpty = FALSE;
  12237. int isKnowKey = FALSE;
  12238. DEBUG_INFO("keyReq = %s\n", keyReq);
  12239. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12240. isEmpty = TRUE;
  12241. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12242. {
  12243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12246. {
  12247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12248. }
  12249. else
  12250. {
  12251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12252. }
  12253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12254. isKnowKey = TRUE;
  12255. }
  12256. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12257. {
  12258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12261. {
  12262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12263. }
  12264. else
  12265. {
  12266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12267. }
  12268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12269. isKnowKey = TRUE;
  12270. }
  12271. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12272. {
  12273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12276. {
  12277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12278. }
  12279. else
  12280. {
  12281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12282. }
  12283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12284. isKnowKey = TRUE;
  12285. }
  12286. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12287. {
  12288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12291. {
  12292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12293. }
  12294. else
  12295. {
  12296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12297. }
  12298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12299. isKnowKey = TRUE;
  12300. }
  12301. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12302. {
  12303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12306. {
  12307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12308. }
  12309. else
  12310. {
  12311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12312. }
  12313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12314. isKnowKey = TRUE;
  12315. }
  12316. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12317. {
  12318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12321. {
  12322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12323. }
  12324. else
  12325. {
  12326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12327. }
  12328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12329. isKnowKey = TRUE;
  12330. }
  12331. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12332. {
  12333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12336. {
  12337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12338. }
  12339. else
  12340. {
  12341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12342. }
  12343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12344. isKnowKey = TRUE;
  12345. }
  12346. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12347. {
  12348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12351. {
  12352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12353. }
  12354. else
  12355. {
  12356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12357. }
  12358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12359. isKnowKey = TRUE;
  12360. }
  12361. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12362. {
  12363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12366. {
  12367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12368. }
  12369. else
  12370. {
  12371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12372. }
  12373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12374. isKnowKey = TRUE;
  12375. }
  12376. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12377. {
  12378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12381. {
  12382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12383. }
  12384. else
  12385. {
  12386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12387. }
  12388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12389. isKnowKey = TRUE;
  12390. }
  12391. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12392. {
  12393. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12396. {
  12397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12398. }
  12399. else
  12400. {
  12401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12402. }
  12403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12404. isKnowKey = TRUE;
  12405. }
  12406. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12407. {
  12408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12411. {
  12412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12413. }
  12414. else
  12415. {
  12416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12417. }
  12418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12419. isKnowKey = TRUE;
  12420. }
  12421. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12422. {
  12423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12426. {
  12427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12428. }
  12429. else
  12430. {
  12431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12432. }
  12433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12434. isKnowKey = TRUE;
  12435. }
  12436. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12437. {
  12438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12441. {
  12442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12443. }
  12444. else
  12445. {
  12446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12447. }
  12448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12449. isKnowKey = TRUE;
  12450. }
  12451. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12452. {
  12453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12456. {
  12457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12458. }
  12459. else
  12460. {
  12461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12462. }
  12463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12464. isKnowKey = TRUE;
  12465. }
  12466. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12467. {
  12468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12471. {
  12472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12473. }
  12474. else
  12475. {
  12476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12477. }
  12478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12479. isKnowKey = TRUE;
  12480. }
  12481. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12482. {
  12483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12486. {
  12487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12488. }
  12489. else
  12490. {
  12491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12492. }
  12493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12494. isKnowKey = TRUE;
  12495. }
  12496. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12497. {
  12498. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12501. {
  12502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12503. }
  12504. else
  12505. {
  12506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12507. }
  12508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12509. isKnowKey = TRUE;
  12510. }
  12511. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12512. {
  12513. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12516. {
  12517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12518. }
  12519. else
  12520. {
  12521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12522. }
  12523. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12525. isKnowKey = TRUE;
  12526. }
  12527. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12528. {
  12529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12532. {
  12533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12534. }
  12535. else
  12536. {
  12537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12538. }
  12539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12540. isKnowKey = TRUE;
  12541. }
  12542. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12543. {
  12544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12547. {
  12548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12549. }
  12550. else
  12551. {
  12552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12553. }
  12554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12555. isKnowKey = TRUE;
  12556. }
  12557. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12558. {
  12559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12562. {
  12563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12564. }
  12565. else
  12566. {
  12567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12568. }
  12569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12570. isKnowKey = TRUE;
  12571. }
  12572. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12573. {
  12574. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12577. {
  12578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12579. }
  12580. else
  12581. {
  12582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12583. }
  12584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12585. isKnowKey = TRUE;
  12586. }
  12587. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12588. {
  12589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12592. {
  12593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12594. }
  12595. else
  12596. {
  12597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12598. }
  12599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12600. isKnowKey = TRUE;
  12601. }
  12602. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12603. {
  12604. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12607. {
  12608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12609. }
  12610. else
  12611. {
  12612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12613. }
  12614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12615. isKnowKey = TRUE;
  12616. }
  12617. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12618. {
  12619. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12622. {
  12623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12624. }
  12625. else
  12626. {
  12627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12628. }
  12629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12630. isKnowKey = TRUE;
  12631. }
  12632. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12633. {
  12634. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12637. {
  12638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12639. }
  12640. else
  12641. {
  12642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12643. }
  12644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12645. isKnowKey = TRUE;
  12646. }
  12647. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12648. {
  12649. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12652. {
  12653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12654. }
  12655. else
  12656. {
  12657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12658. }
  12659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12660. isKnowKey = TRUE;
  12661. }
  12662. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12663. {
  12664. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12667. {
  12668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12669. }
  12670. else
  12671. {
  12672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12673. }
  12674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12675. isKnowKey = TRUE;
  12676. }
  12677. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12678. {
  12679. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12682. {
  12683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12684. }
  12685. else
  12686. {
  12687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12688. }
  12689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12690. isKnowKey = TRUE;
  12691. }
  12692. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12693. {
  12694. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12697. {
  12698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12699. }
  12700. else
  12701. {
  12702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12703. }
  12704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12705. isKnowKey = TRUE;
  12706. }
  12707. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12708. {
  12709. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12712. {
  12713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12714. }
  12715. else
  12716. {
  12717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12718. }
  12719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12720. isKnowKey = TRUE;
  12721. }
  12722. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12723. {
  12724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12727. {
  12728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12729. }
  12730. else
  12731. {
  12732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12733. }
  12734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12735. isKnowKey = TRUE;
  12736. }
  12737. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12738. {
  12739. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12742. {
  12743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12744. }
  12745. else
  12746. {
  12747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12748. }
  12749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12750. isKnowKey = TRUE;
  12751. }
  12752. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12753. {
  12754. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12757. {
  12758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12759. }
  12760. else
  12761. {
  12762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12763. }
  12764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12765. isKnowKey = TRUE;
  12766. }
  12767. /*
  12768. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12769. {
  12770. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12773. {
  12774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12775. }
  12776. else
  12777. {
  12778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12779. }
  12780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12781. isKnowKey = TRUE;
  12782. }*/
  12783. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12784. {
  12785. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12788. {
  12789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12790. }
  12791. else
  12792. {
  12793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12794. }
  12795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12796. isKnowKey = TRUE;
  12797. }
  12798. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12799. {
  12800. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12803. {
  12804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12805. }
  12806. else
  12807. {
  12808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12809. }
  12810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12811. isKnowKey = TRUE;
  12812. }
  12813. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12814. {
  12815. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12818. {
  12819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12820. }
  12821. else
  12822. {
  12823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12824. }
  12825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12826. isKnowKey = TRUE;
  12827. }
  12828. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12829. {
  12830. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12833. {
  12834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12835. }
  12836. else
  12837. {
  12838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12839. }
  12840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12841. isKnowKey = TRUE;
  12842. }
  12843. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12844. {
  12845. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12848. {
  12849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12850. }
  12851. else
  12852. {
  12853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12854. }
  12855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12856. isKnowKey = TRUE;
  12857. }
  12858. #if 1
  12859. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12860. {
  12861. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12863. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12864. {
  12865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12866. }
  12867. else
  12868. {
  12869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12870. }
  12871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12872. isKnowKey = TRUE;
  12873. }
  12874. #endif
  12875. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12876. {
  12877. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12879. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12880. {
  12881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12882. }
  12883. else
  12884. {
  12885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12886. }
  12887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12888. isKnowKey = TRUE;
  12889. }
  12890. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12891. {
  12892. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12894. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12895. {
  12896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12897. }
  12898. else
  12899. {
  12900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12901. }
  12902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12903. isKnowKey = TRUE;
  12904. }
  12905. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12906. {
  12907. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12909. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12910. {
  12911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12912. }
  12913. else
  12914. {
  12915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12916. }
  12917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12918. isKnowKey = TRUE;
  12919. }
  12920. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12921. {
  12922. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12924. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12925. {
  12926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12927. }
  12928. else
  12929. {
  12930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12931. }
  12932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12933. isKnowKey = TRUE;
  12934. }
  12935. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12936. {
  12937. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12939. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12940. {
  12941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12942. }
  12943. else
  12944. {
  12945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12946. }
  12947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12948. isKnowKey = TRUE;
  12949. }
  12950. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12951. {
  12952. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12954. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12955. {
  12956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12957. }
  12958. else
  12959. {
  12960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12961. }
  12962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12963. isKnowKey = TRUE;
  12964. }
  12965. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12966. {
  12967. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12969. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12970. {
  12971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12972. }
  12973. else
  12974. {
  12975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12976. }
  12977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12978. isKnowKey = TRUE;
  12979. }
  12980. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12981. {
  12982. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12984. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12985. {
  12986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12987. }
  12988. else
  12989. {
  12990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12991. }
  12992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12993. isKnowKey = TRUE;
  12994. }
  12995. //=========================================================
  12996. if(!isEmpty && !isKnowKey)
  12997. {
  12998. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12999. strcpy(unknownkey[UnknownKeynum], keyReq);
  13000. UnknownKeynum = UnknownKeynum + 1;
  13001. }
  13002. }
  13003. void processUnkownKey(void)
  13004. {
  13005. DEBUG_INFO("processUnkownKey...\n");
  13006. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13007. for(int index=0; index < UnknownKeynum; index++)
  13008. {
  13009. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13010. {
  13011. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13012. }
  13013. }
  13014. }
  13015. int setKeyValue(char *key, char *value)
  13016. {
  13017. int isSuccess = NotSupported;
  13018. int check_ascii=0;
  13019. char str[256]={0};
  13020. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13021. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13022. {
  13023. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13025. {
  13026. strcpy(str, (const char*)value);
  13027. for(int i = 0; str[i]; i++){
  13028. str[i] = tolower(str[i]);
  13029. }
  13030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13031. isSuccess = ConfigurationStatus_Accepted;
  13032. }
  13033. else
  13034. {
  13035. isSuccess = ConfigurationStatus_Rejected;
  13036. }
  13037. }
  13038. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13039. {
  13040. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13042. {
  13043. strcpy(str, (const char*)value);
  13044. for(int i = 0; str[i]; i++){
  13045. str[i] = tolower(str[i]);
  13046. }
  13047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13048. isSuccess = ConfigurationStatus_Accepted;
  13049. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  13050. }
  13051. else
  13052. {
  13053. isSuccess = ConfigurationStatus_Rejected;
  13054. }
  13055. }
  13056. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13057. {
  13058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13059. {
  13060. strcpy(str, (const char*)value);
  13061. for(int i = 0; str[i]; i++)
  13062. {
  13063. str[i] = tolower(str[i]);
  13064. }
  13065. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13067. isSuccess = ConfigurationStatus_Accepted;
  13068. }
  13069. else
  13070. {
  13071. isSuccess = ConfigurationStatus_Rejected;
  13072. }
  13073. }
  13074. if(strcmp(key, "BlinkRepeat") == 0)
  13075. {
  13076. //Charger.BlinkRepeat = Integer.parseInt(value);
  13077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13078. {
  13079. check_ascii = value[0];
  13080. if( (check_ascii < 48) || (check_ascii > 57) )
  13081. {
  13082. isSuccess = ConfigurationStatus_Rejected;
  13083. }
  13084. else
  13085. {
  13086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13087. isSuccess = ConfigurationStatus_Accepted;
  13088. }
  13089. }
  13090. else
  13091. {
  13092. isSuccess = ConfigurationStatus_Rejected;
  13093. }
  13094. }
  13095. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13096. {
  13097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13098. {
  13099. check_ascii = value[0];
  13100. if( (check_ascii < 48) || (check_ascii > 57) )
  13101. {
  13102. isSuccess = ConfigurationStatus_Rejected;
  13103. }
  13104. else
  13105. {
  13106. if((atoi(value) == 0) || (atoi(value) >= 10))
  13107. {
  13108. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13110. isSuccess = ConfigurationStatus_Accepted;
  13111. }
  13112. else
  13113. isSuccess = ConfigurationStatus_Rejected;
  13114. }
  13115. }
  13116. else
  13117. {
  13118. isSuccess = ConfigurationStatus_Rejected;
  13119. }
  13120. }
  13121. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13122. {
  13123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13124. {
  13125. check_ascii = value[0];
  13126. if( (check_ascii < 48) || (check_ascii > 57) )
  13127. {
  13128. isSuccess = ConfigurationStatus_Rejected;
  13129. }
  13130. else
  13131. {
  13132. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13134. isSuccess = ConfigurationStatus_Accepted;
  13135. }
  13136. }
  13137. else
  13138. {
  13139. isSuccess = ConfigurationStatus_Rejected;
  13140. }
  13141. }
  13142. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13143. {
  13144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13145. {
  13146. check_ascii = value[0];
  13147. if( (check_ascii < 48) || (check_ascii > 57) )
  13148. {
  13149. isSuccess = ConfigurationStatus_Rejected;
  13150. }
  13151. else
  13152. {
  13153. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13155. isSuccess = ConfigurationStatus_Accepted;
  13156. }
  13157. }
  13158. else
  13159. {
  13160. isSuccess = ConfigurationStatus_Rejected;
  13161. }
  13162. }
  13163. if(strcmp(key, "HeartbeatInterval") == 0)
  13164. {
  13165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13166. {
  13167. check_ascii = value[0];
  13168. if( (check_ascii < 48) || (check_ascii > 57) )
  13169. {
  13170. isSuccess = ConfigurationStatus_Rejected;
  13171. }
  13172. else
  13173. {
  13174. if((atoi(value) == 0) || (atoi(value) >= 10))
  13175. {
  13176. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13178. HeartBeatWaitTime = atoi(value);
  13179. isSuccess = ConfigurationStatus_Accepted;
  13180. }
  13181. else
  13182. {
  13183. isSuccess = ConfigurationStatus_Rejected;
  13184. }
  13185. }
  13186. }
  13187. else
  13188. {
  13189. isSuccess = ConfigurationStatus_Rejected;
  13190. }
  13191. }
  13192. if(strcmp(key, "LightIntensity") == 0)
  13193. {
  13194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13195. {
  13196. check_ascii = value[0];
  13197. if( (check_ascii < 48) || (check_ascii > 57) )
  13198. {
  13199. isSuccess = ConfigurationStatus_Rejected;
  13200. }
  13201. else
  13202. {
  13203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13204. isSuccess = ConfigurationStatus_Accepted;
  13205. }
  13206. }
  13207. else
  13208. {
  13209. isSuccess = ConfigurationStatus_Rejected;
  13210. }
  13211. }
  13212. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13213. {
  13214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13215. {
  13216. strcpy(str, (const char*)value);
  13217. for(int i = 0; str[i]; i++)
  13218. {
  13219. str[i] = tolower(str[i]);
  13220. }
  13221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13222. isSuccess = ConfigurationStatus_Accepted;
  13223. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13224. }
  13225. else
  13226. {
  13227. isSuccess = ConfigurationStatus_Rejected;
  13228. }
  13229. }
  13230. if(strcmp(key, "LocalPreAuthorize") == 0)
  13231. {
  13232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13233. {
  13234. strcpy(str, (const char*)value);
  13235. for(int i = 0; str[i]; i++)
  13236. {
  13237. str[i] = tolower(str[i]);
  13238. }
  13239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13240. isSuccess = ConfigurationStatus_Accepted;
  13241. }
  13242. else
  13243. {
  13244. isSuccess = ConfigurationStatus_Rejected;
  13245. }
  13246. }
  13247. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13248. {
  13249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13250. {
  13251. check_ascii = value[0];
  13252. if( (check_ascii < 48) || (check_ascii > 57) )
  13253. {
  13254. isSuccess = ConfigurationStatus_Rejected;
  13255. }
  13256. else
  13257. {
  13258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13259. isSuccess = ConfigurationStatus_Accepted;
  13260. }
  13261. }
  13262. else
  13263. {
  13264. isSuccess = ConfigurationStatus_Rejected;
  13265. }
  13266. }
  13267. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13268. {
  13269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13270. {
  13271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13272. isSuccess = ConfigurationStatus_Accepted;
  13273. }
  13274. else
  13275. {
  13276. isSuccess = ConfigurationStatus_Rejected;
  13277. }
  13278. }
  13279. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13280. {
  13281. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13282. {
  13283. check_ascii = value[0];
  13284. if( (check_ascii < 48) || (check_ascii > 57) )
  13285. {
  13286. isSuccess = ConfigurationStatus_Rejected;
  13287. }
  13288. else
  13289. {
  13290. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13292. isSuccess = ConfigurationStatus_Accepted;
  13293. }
  13294. }
  13295. else
  13296. {
  13297. isSuccess = ConfigurationStatus_Rejected;
  13298. }
  13299. }
  13300. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13301. {
  13302. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13303. {
  13304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13305. isSuccess = ConfigurationStatus_Accepted;
  13306. }
  13307. else
  13308. {
  13309. isSuccess = ConfigurationStatus_Rejected;
  13310. }
  13311. }
  13312. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13313. {
  13314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13315. {
  13316. check_ascii = value[0];
  13317. if( (check_ascii < 48) || (check_ascii > 57) )
  13318. {
  13319. isSuccess = ConfigurationStatus_Rejected;
  13320. }
  13321. else
  13322. {
  13323. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13325. isSuccess = ConfigurationStatus_Accepted;
  13326. }
  13327. }
  13328. else
  13329. {
  13330. isSuccess = ConfigurationStatus_Rejected;
  13331. }
  13332. }
  13333. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13334. {
  13335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13336. {
  13337. check_ascii = value[0];
  13338. if( (check_ascii < 48) || (check_ascii > 57) )
  13339. {
  13340. isSuccess = ConfigurationStatus_Rejected;
  13341. }
  13342. else
  13343. {
  13344. if((atoi(value) == 0) || (atoi(value) >= 10))
  13345. {
  13346. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13348. isSuccess = ConfigurationStatus_Accepted;
  13349. }
  13350. else
  13351. {
  13352. isSuccess = ConfigurationStatus_Rejected;
  13353. }
  13354. }
  13355. }
  13356. else
  13357. {
  13358. isSuccess = ConfigurationStatus_Rejected;
  13359. }
  13360. }
  13361. if(strcmp(key, "MinimumStatusDuration") == 0)
  13362. {
  13363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13364. {
  13365. check_ascii = value[0];
  13366. if( (check_ascii < 48) || (check_ascii > 57) )
  13367. {
  13368. isSuccess = ConfigurationStatus_Rejected;
  13369. }
  13370. else
  13371. {
  13372. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13373. {
  13374. isSuccess = ConfigurationStatus_Rejected;
  13375. }
  13376. else
  13377. {
  13378. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13380. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13381. isSuccess = ConfigurationStatus_Accepted;
  13382. }
  13383. }
  13384. }
  13385. else
  13386. {
  13387. isSuccess = ConfigurationStatus_Rejected;
  13388. }
  13389. }
  13390. if(strcmp(key, "NumberOfConnectors") == 0)
  13391. {
  13392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13393. {
  13394. check_ascii = value[0];
  13395. if( (check_ascii < 48) || (check_ascii > 57) )
  13396. {
  13397. isSuccess = ConfigurationStatus_Rejected;
  13398. }
  13399. else
  13400. {
  13401. //Charger.ResetRetries = Integer.parseInt(value);
  13402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13403. isSuccess = ConfigurationStatus_Accepted;
  13404. }
  13405. }
  13406. else
  13407. {
  13408. isSuccess = ConfigurationStatus_Rejected;
  13409. }
  13410. }
  13411. if(strcmp(key, "ResetRetries") == 0)
  13412. {
  13413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13414. {
  13415. check_ascii = value[0];
  13416. if( (check_ascii < 48) || (check_ascii > 57) )
  13417. {
  13418. isSuccess = ConfigurationStatus_Rejected;
  13419. }
  13420. else
  13421. {
  13422. //Charger.ResetRetries = Integer.parseInt(value);
  13423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13424. isSuccess = ConfigurationStatus_Accepted;
  13425. }
  13426. }
  13427. else
  13428. {
  13429. isSuccess = ConfigurationStatus_Rejected;
  13430. }
  13431. }
  13432. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13433. {
  13434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13435. {
  13436. strcpy(str, (const char*)value);
  13437. for(int i = 0; str[i]; i++)
  13438. {
  13439. str[i] = tolower(str[i]);
  13440. }
  13441. if(strcmp(str, "notapplicable")== 0)
  13442. {
  13443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13444. isSuccess = ConfigurationStatus_Accepted;
  13445. }
  13446. else if(strcmp(str, "unknown")== 0)
  13447. {
  13448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13449. isSuccess = ConfigurationStatus_Accepted;
  13450. }
  13451. else if(strcmp(str, "rst")== 0)
  13452. {
  13453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13454. isSuccess = ConfigurationStatus_Accepted;
  13455. }
  13456. else if(strcmp(str, "rts")== 0)
  13457. {
  13458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13459. isSuccess = ConfigurationStatus_Accepted;
  13460. }
  13461. else if(strcmp(str, "srt")== 0)
  13462. {
  13463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13464. isSuccess = ConfigurationStatus_Accepted;
  13465. }
  13466. else if(strcmp(str, "str")== 0)
  13467. {
  13468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13469. isSuccess = ConfigurationStatus_Accepted;
  13470. }
  13471. else if(strcmp(str, "trs")== 0)
  13472. {
  13473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13474. isSuccess = ConfigurationStatus_Accepted;
  13475. }
  13476. else if(strcmp(str, "tsr")== 0)
  13477. {
  13478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13479. isSuccess = ConfigurationStatus_Accepted;
  13480. }
  13481. else
  13482. {
  13483. isSuccess = ConfigurationStatus_Rejected;
  13484. }
  13485. }
  13486. else
  13487. {
  13488. isSuccess = ConfigurationStatus_Rejected;
  13489. }
  13490. }
  13491. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13492. {
  13493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13494. {
  13495. check_ascii = value[0];
  13496. if( (check_ascii < 48) || (check_ascii > 57) )
  13497. {
  13498. isSuccess = ConfigurationStatus_Rejected;
  13499. }
  13500. else
  13501. {
  13502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13503. isSuccess = ConfigurationStatus_Accepted;
  13504. }
  13505. }
  13506. else
  13507. {
  13508. isSuccess = ConfigurationStatus_Rejected;
  13509. }
  13510. }
  13511. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13512. {
  13513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13514. {
  13515. strcpy(str, (const char*)value);
  13516. for(int i = 0; str[i]; i++)
  13517. {
  13518. str[i] = tolower(str[i]);
  13519. }
  13520. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13522. isSuccess = ConfigurationStatus_Accepted;
  13523. }
  13524. else
  13525. {
  13526. isSuccess = ConfigurationStatus_Rejected;
  13527. }
  13528. }
  13529. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13530. {
  13531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13532. {
  13533. strcpy(str, (const char*)value);
  13534. for(int i = 0; str[i]; i++)
  13535. {
  13536. str[i] = tolower(str[i]);
  13537. }
  13538. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13540. isSuccess = ConfigurationStatus_Accepted;
  13541. }
  13542. else
  13543. {
  13544. isSuccess = ConfigurationStatus_Rejected;
  13545. }
  13546. }
  13547. if(strcmp(key, "StopTxnAlignedData") == 0)
  13548. {
  13549. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13550. {
  13551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13552. isSuccess = ConfigurationStatus_Accepted;
  13553. }
  13554. else
  13555. {
  13556. isSuccess = ConfigurationStatus_Rejected;
  13557. }
  13558. }
  13559. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13560. {
  13561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13562. {
  13563. check_ascii = value[0];
  13564. if( (check_ascii < 48) || (check_ascii > 57) )
  13565. {
  13566. isSuccess = ConfigurationStatus_Rejected;
  13567. }
  13568. else
  13569. {
  13570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13571. isSuccess = ConfigurationStatus_Accepted;
  13572. }
  13573. }
  13574. else
  13575. {
  13576. isSuccess = ConfigurationStatus_Rejected;
  13577. }
  13578. }
  13579. if(strcmp(key, "StopTxnSampledData") == 0)
  13580. {
  13581. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13582. {
  13583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13584. isSuccess = ConfigurationStatus_Accepted;
  13585. }
  13586. else
  13587. {
  13588. isSuccess = ConfigurationStatus_Rejected;
  13589. }
  13590. }
  13591. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13592. {
  13593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13594. {
  13595. check_ascii = value[0];
  13596. if( (check_ascii < 48) || (check_ascii > 57) )
  13597. {
  13598. isSuccess = ConfigurationStatus_Rejected;
  13599. }
  13600. else
  13601. {
  13602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13603. isSuccess = ConfigurationStatus_Accepted;
  13604. }
  13605. }
  13606. else
  13607. {
  13608. isSuccess = ConfigurationStatus_Rejected;
  13609. }
  13610. }
  13611. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13612. {
  13613. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13614. {
  13615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13616. isSuccess = ConfigurationStatus_Accepted;
  13617. }
  13618. else
  13619. {
  13620. isSuccess = ConfigurationStatus_Rejected;
  13621. }
  13622. }
  13623. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13624. {
  13625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13626. {
  13627. check_ascii = value[0];
  13628. if( (check_ascii < 48) || (check_ascii > 57) )
  13629. {
  13630. isSuccess = ConfigurationStatus_Rejected;
  13631. }
  13632. else
  13633. {
  13634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13635. isSuccess = ConfigurationStatus_Accepted;
  13636. }
  13637. }
  13638. else
  13639. {
  13640. isSuccess = ConfigurationStatus_Rejected;
  13641. }
  13642. }
  13643. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13644. {
  13645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13646. {
  13647. check_ascii = value[0];
  13648. if( (check_ascii < 48) || (check_ascii > 57) )
  13649. {
  13650. isSuccess = ConfigurationStatus_Rejected;
  13651. }
  13652. else
  13653. {
  13654. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13656. TransactionMessageAttemptsValue = atoi(value);
  13657. isSuccess = ConfigurationStatus_Accepted;
  13658. }
  13659. }
  13660. else
  13661. {
  13662. isSuccess = ConfigurationStatus_Rejected;
  13663. }
  13664. }
  13665. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13666. {
  13667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13668. {
  13669. check_ascii = value[0];
  13670. if( (check_ascii < 48) || (check_ascii > 57) )
  13671. {
  13672. isSuccess = ConfigurationStatus_Rejected;
  13673. }
  13674. else
  13675. {
  13676. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13677. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13678. TransactionMessageRetryIntervalValue = atoi(value);
  13679. isSuccess = ConfigurationStatus_Accepted;
  13680. }
  13681. }
  13682. else
  13683. {
  13684. isSuccess = ConfigurationStatus_Rejected;
  13685. }
  13686. }
  13687. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13688. {
  13689. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13690. {
  13691. strcpy(str, (const char*)value);
  13692. for(int i = 0; str[i]; i++)
  13693. {
  13694. str[i] = tolower(str[i]);
  13695. }
  13696. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13698. isSuccess = ConfigurationStatus_Accepted;
  13699. }
  13700. else
  13701. {
  13702. isSuccess = ConfigurationStatus_Rejected;
  13703. }
  13704. }
  13705. if(strcmp(key, "WebSocketPingInterval") == 0)
  13706. {
  13707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13708. {
  13709. check_ascii = value[0];
  13710. if( (check_ascii < 48) || (check_ascii > 57) )
  13711. {
  13712. isSuccess = ConfigurationStatus_Rejected;
  13713. }
  13714. else
  13715. {
  13716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13717. isSuccess = ConfigurationStatus_Accepted;
  13718. }
  13719. }
  13720. else
  13721. {
  13722. isSuccess = ConfigurationStatus_Rejected;
  13723. }
  13724. }
  13725. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13726. {
  13727. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13728. {
  13729. strcpy(str, (const char*)value);
  13730. for(int i = 0; str[i]; i++)
  13731. {
  13732. str[i] = tolower(str[i]);
  13733. }
  13734. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13736. isSuccess = ConfigurationStatus_Accepted;
  13737. }
  13738. else
  13739. {
  13740. isSuccess = ConfigurationStatus_Rejected;
  13741. }
  13742. }
  13743. if(strcmp(key, "AuthorizationKey") == 0)
  13744. {
  13745. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13746. {
  13747. strcpy(str, (const char*)value);
  13748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13749. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13750. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  13751. isSuccess = ConfigurationStatus_Accepted;
  13752. }
  13753. else
  13754. {
  13755. isSuccess = ConfigurationStatus_Rejected;
  13756. }
  13757. }
  13758. if(strcmp(key, "SecurityProfile") == 0)
  13759. {
  13760. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13761. {
  13762. check_ascii = value[0];
  13763. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13764. {
  13765. isSuccess = ConfigurationStatus_Rejected;
  13766. }
  13767. else if(check_ascii == 0x33)
  13768. {
  13769. isSuccess = NotSupported;
  13770. }
  13771. else
  13772. {
  13773. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13774. {
  13775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13776. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  13777. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  13778. isSuccess = ConfigurationStatus_Accepted;
  13779. }
  13780. else
  13781. isSuccess = ConfigurationStatus_Rejected;
  13782. }
  13783. }
  13784. else
  13785. {
  13786. isSuccess = ConfigurationStatus_Rejected;
  13787. }
  13788. }
  13789. if(strcmp(key, "DefaultPrice") == 0)
  13790. {
  13791. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13792. {
  13793. strcpy(str, (const char*)value);
  13794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13795. isSuccess = ConfigurationStatus_Accepted;
  13796. }
  13797. else
  13798. {
  13799. isSuccess = ConfigurationStatus_Rejected;
  13800. }
  13801. }
  13802. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13803. {
  13804. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13805. {
  13806. strcpy(str, (const char*)value);
  13807. for(int i = 0; str[i]; i++)
  13808. {
  13809. str[i] = tolower(str[i]);
  13810. }
  13811. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13813. isSuccess = ConfigurationStatus_Accepted;
  13814. }
  13815. else
  13816. {
  13817. isSuccess = ConfigurationStatus_Rejected;
  13818. }
  13819. }
  13820. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13821. {
  13822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13823. {
  13824. strcpy(str, (const char*)value);
  13825. for(int i = 0; str[i]; i++)
  13826. {
  13827. str[i] = tolower(str[i]);
  13828. }
  13829. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13831. isSuccess = ConfigurationStatus_Accepted;
  13832. }
  13833. else
  13834. {
  13835. isSuccess = ConfigurationStatus_Rejected;
  13836. }
  13837. }
  13838. #if 0
  13839. //For OCPP Test Case
  13840. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13841. {
  13842. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13843. {
  13844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13845. isSuccess = ConfigurationStatus_Accepted;
  13846. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13847. }
  13848. else
  13849. {
  13850. isSuccess = ConfigurationStatus_Rejected;
  13851. }
  13852. }
  13853. #endif
  13854. #if 1
  13855. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13856. {
  13857. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13858. {
  13859. strcpy(str, (const char*)value);
  13860. for(int i = 0; str[i]; i++)
  13861. {
  13862. str[i] = tolower(str[i]);
  13863. }
  13864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13865. isSuccess = ConfigurationStatus_Accepted;
  13866. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13867. }
  13868. else
  13869. {
  13870. isSuccess = ConfigurationStatus_Rejected;
  13871. }
  13872. }
  13873. #endif
  13874. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13875. {
  13876. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13877. {
  13878. check_ascii = value[0];
  13879. if( (check_ascii < 48) || (check_ascii > 57) )
  13880. {
  13881. isSuccess = ConfigurationStatus_Rejected;
  13882. }
  13883. else
  13884. {
  13885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13886. isSuccess = ConfigurationStatus_Accepted;
  13887. }
  13888. }
  13889. else
  13890. {
  13891. isSuccess = ConfigurationStatus_Rejected;
  13892. }
  13893. }
  13894. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13895. {
  13896. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13897. {
  13898. check_ascii = value[0];
  13899. if( (check_ascii < 48) || (check_ascii > 57) )
  13900. {
  13901. isSuccess = ConfigurationStatus_Rejected;
  13902. }
  13903. else
  13904. {
  13905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13906. isSuccess = ConfigurationStatus_Accepted;
  13907. }
  13908. }
  13909. else
  13910. {
  13911. isSuccess = ConfigurationStatus_Rejected;
  13912. }
  13913. }
  13914. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13915. {
  13916. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13917. {
  13918. strcpy(str, (const char*)value);
  13919. for(int i = 0; str[i]; i++)
  13920. {
  13921. str[i] = tolower(str[i]);
  13922. }
  13923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13924. isSuccess = ConfigurationStatus_Accepted;
  13925. }
  13926. else
  13927. {
  13928. isSuccess = ConfigurationStatus_Rejected;
  13929. }
  13930. }
  13931. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13932. {
  13933. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13934. {
  13935. check_ascii = value[0];
  13936. if( (check_ascii < 48) || (check_ascii > 57) )
  13937. {
  13938. isSuccess = ConfigurationStatus_Rejected;
  13939. }
  13940. else
  13941. {
  13942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13943. isSuccess = ConfigurationStatus_Accepted;
  13944. }
  13945. }
  13946. else
  13947. {
  13948. isSuccess = ConfigurationStatus_Rejected;
  13949. }
  13950. }
  13951. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13952. {
  13953. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13954. {
  13955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13956. isSuccess = ConfigurationStatus_Accepted;
  13957. }
  13958. else
  13959. {
  13960. isSuccess = ConfigurationStatus_Rejected;
  13961. }
  13962. }
  13963. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13964. {
  13965. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13966. {
  13967. check_ascii = value[0];
  13968. if( (check_ascii < 48) || (check_ascii > 57) )
  13969. {
  13970. isSuccess = ConfigurationStatus_Rejected;
  13971. }
  13972. else
  13973. {
  13974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13975. isSuccess = ConfigurationStatus_Accepted;
  13976. }
  13977. }
  13978. else
  13979. {
  13980. isSuccess = ConfigurationStatus_Rejected;
  13981. }
  13982. }
  13983. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13984. {
  13985. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13986. {
  13987. strcpy(str, (const char*)value);
  13988. for(int i = 0; str[i]; i++)
  13989. {
  13990. str[i] = tolower(str[i]);
  13991. }
  13992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13993. isSuccess = ConfigurationStatus_Accepted;
  13994. }
  13995. else
  13996. {
  13997. isSuccess = ConfigurationStatus_Rejected;
  13998. }
  13999. }
  14000. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14001. {
  14002. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14003. {
  14004. check_ascii = value[0];
  14005. if( (check_ascii < 48) || (check_ascii > 57) )
  14006. {
  14007. isSuccess = ConfigurationStatus_Rejected;
  14008. }
  14009. else
  14010. {
  14011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14012. isSuccess = ConfigurationStatus_Accepted;
  14013. }
  14014. }
  14015. else
  14016. {
  14017. isSuccess = ConfigurationStatus_Rejected;
  14018. }
  14019. }
  14020. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14021. return isSuccess;
  14022. }
  14023. int TransactionMessageAttemptsGet(void)
  14024. {
  14025. return TransactionMessageAttemptsValue;
  14026. }
  14027. int FirstHeartBeatResponse(void)
  14028. {
  14029. return FirstHeartBeat;
  14030. }
  14031. int TransactionMessageRetryIntervalGet(void)
  14032. {
  14033. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14034. }
  14035. int ReadHttpStatus(int sock)
  14036. {
  14037. //char c;
  14038. char buff[1024]="",*ptr=buff+1;
  14039. int bytes_received, status;
  14040. DEBUG_INFO("Begin Response ..\n");
  14041. while((bytes_received = recv(sock, ptr, 1, 0))){
  14042. if(bytes_received==-1){
  14043. perror("ReadHttpStatus");
  14044. exit(1);
  14045. }
  14046. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14047. ptr++;
  14048. }
  14049. *ptr=0;
  14050. ptr=buff+1;
  14051. sscanf(ptr,"%*s %d ", &status);
  14052. DEBUG_INFO("%s\n",ptr);
  14053. DEBUG_INFO("status=%d\n",status);
  14054. DEBUG_INFO("End Response ..\n");
  14055. return (bytes_received>0)?status:0;
  14056. }
  14057. //the only filed that it parsed is 'Content-Length'
  14058. int ParseHeader(int sock)
  14059. {
  14060. //char c;
  14061. char buff[1024]="",*ptr=buff+4;
  14062. int bytes_received;
  14063. DEBUG_INFO("Begin HEADER ..\n");
  14064. while((bytes_received = recv(sock, ptr, 1, 0))){
  14065. if(bytes_received==-1){
  14066. perror("Parse Header");
  14067. exit(1);
  14068. }
  14069. if(
  14070. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14071. (ptr[-1]=='\r') && (*ptr=='\n' )
  14072. ) break;
  14073. ptr++;
  14074. }
  14075. *ptr=0;
  14076. ptr=buff+4;
  14077. //printf("%s",ptr);
  14078. if(bytes_received){
  14079. ptr=strstr(ptr,"Content-Length:");
  14080. if(ptr){
  14081. sscanf(ptr,"%*s %d",&bytes_received);
  14082. }else
  14083. bytes_received=-1; //unknown size
  14084. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14085. }
  14086. DEBUG_INFO("End HEADER ..\n");
  14087. return bytes_received ;
  14088. }
  14089. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14090. {
  14091. int result = TRUE;
  14092. char rmFileCmd[100]={0};
  14093. char FilePath[100]={0};
  14094. char ftpbuf[200];
  14095. int systemresult;
  14096. //DEBUG_INFO("filename=%s\n",filename);
  14097. //DEBUG_INFO("url=%s\n",url);
  14098. sprintf(FilePath,"/mnt/%s",filename);
  14099. system("ping 8.8.8.8 &");
  14100. if((access(FilePath,F_OK))!=-1)
  14101. {
  14102. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14103. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14104. system(rmFileCmd);
  14105. }
  14106. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14107. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14108. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14109. systemresult = system(ftpbuf);
  14110. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14111. if(systemresult != 0)
  14112. {
  14113. DEBUG_INFO("http DownLoad error!\n");
  14114. result = FALSE;
  14115. }
  14116. system("pkill ping");
  14117. return result;
  14118. }
  14119. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14120. {
  14121. int result = TRUE;
  14122. char rmFileCmd[100]={0};
  14123. char FilePath[100]={0};
  14124. char ftpbuf[200];
  14125. int systemresult;
  14126. //char temp[100];
  14127. sprintf(FilePath,"/mnt/%s",filename);
  14128. system("ping 8.8.8.8 &");
  14129. if((access(FilePath,F_OK))!=-1)
  14130. {
  14131. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14132. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14133. system(rmFileCmd);
  14134. }
  14135. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14136. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14137. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14138. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14139. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14140. systemresult = system(ftpbuf);
  14141. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14142. if(systemresult != 0)
  14143. {
  14144. printf("wget error!\n");
  14145. result = FALSE;
  14146. }
  14147. system("pkill ping");
  14148. return result;
  14149. }
  14150. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14151. {
  14152. char rmFileCmd[100]={0};
  14153. char FilePath[100]={0};
  14154. char buf[512];
  14155. int systemresult = 0;
  14156. //DEBUG_INFO("filename=%s\n",filename);
  14157. //DEBUG_INFO("url=%s\n",url);
  14158. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14159. if((access(FilePath,F_OK))!=-1)
  14160. {
  14161. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14162. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14163. system(rmFileCmd);
  14164. }
  14165. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14166. if(fp == NULL)
  14167. {
  14168. DEBUG_INFO("log is NULL\n");
  14169. return FALSE;
  14170. }
  14171. else
  14172. {
  14173. fprintf(fp, "%s\n", url);
  14174. fprintf(fp, "%s\n", filename);
  14175. fclose(fp);
  14176. }
  14177. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14178. if(phpFP == NULL)
  14179. {
  14180. DEBUG_INFO("PHP upload fail.\n");
  14181. return FALSE;
  14182. }
  14183. else
  14184. {
  14185. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14186. {
  14187. if(strstr(buf, "result") != NULL)
  14188. {
  14189. sscanf(buf, "result: %d", &systemresult);
  14190. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14191. }
  14192. }
  14193. pclose(phpFP);
  14194. }
  14195. if(systemresult != 1)
  14196. {
  14197. DEBUG_INFO("HTTP upload error!\n");
  14198. return FALSE;
  14199. }
  14200. return TRUE;
  14201. }
  14202. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14203. {
  14204. struct hostent* server;
  14205. char *IPbuffer;
  14206. char ftpbuf[200];
  14207. int systemresult;
  14208. // To retrieve host information
  14209. server = gethostbyname(location);
  14210. // To convert an Internet network
  14211. // address into ASCII string
  14212. IPbuffer = inet_ntoa(*((struct in_addr*)
  14213. server->h_addr_list[0]));
  14214. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14215. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14216. /* format : ftpput -u username -p passwd IP target source*/
  14217. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14218. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14219. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14220. systemresult = system(ftpbuf);
  14221. DEBUG_INFO("systemresult=%d\n",systemresult);
  14222. if(systemresult != 0)
  14223. {
  14224. DEBUG_INFO("ftpput error!\n");
  14225. return FALSE;
  14226. }
  14227. return TRUE;
  14228. }
  14229. int GetOcppServerURL()
  14230. {
  14231. int result = FALSE;
  14232. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14233. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14234. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14235. struct yuarel url;
  14236. char urlStr[512];
  14237. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14238. {
  14239. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14240. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14241. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14242. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14243. if(yuarel_parse(&url, urlStr) != -1)
  14244. {
  14245. sprintf(OcppProtocol, "%s", url.scheme);
  14246. sprintf(OcppHost, "%s", url.host);
  14247. if(url.path == NULL)
  14248. OcppTempPath[0] = '\0';
  14249. else
  14250. {
  14251. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14252. {
  14253. sprintf(OcppTempPath, "%s/", url.path);
  14254. }
  14255. else
  14256. {
  14257. sprintf(OcppTempPath, "%s", url.path);
  14258. }
  14259. }
  14260. if(url.port == 0)
  14261. {
  14262. if(strcmp(OcppProtocol, "wss") == 0)
  14263. OcppPort = 443;
  14264. else
  14265. OcppPort = 80;
  14266. }
  14267. else
  14268. OcppPort = url.port;
  14269. result = TRUE;
  14270. }
  14271. }
  14272. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14273. {
  14274. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14275. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14276. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14277. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14278. if(yuarel_parse(&url, urlStr) != -1)
  14279. {
  14280. sprintf(OcppProtocol, "%s", url.scheme);
  14281. sprintf(OcppHost, "%s", url.host);
  14282. if(url.path == NULL)
  14283. OcppTempPath[0] = '\0';
  14284. else
  14285. sprintf(OcppTempPath, "%s", url.path);
  14286. if(url.port == 0)
  14287. {
  14288. if(strcmp(OcppProtocol, "wss") == 0)
  14289. OcppPort = 443;
  14290. else
  14291. OcppPort = 80;
  14292. }
  14293. else
  14294. OcppPort = url.port;
  14295. result = TRUE;
  14296. }
  14297. }
  14298. else
  14299. {
  14300. strcpy(OcppHost,"");
  14301. }
  14302. return result;
  14303. }
  14304. int GetOcppPath()
  14305. {
  14306. int result = FALSE;
  14307. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14308. {
  14309. if(OcppTempPath == NULL)
  14310. {
  14311. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14312. }
  14313. else
  14314. {
  14315. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14316. }
  14317. result = TRUE;
  14318. goto End;
  14319. }
  14320. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14321. {
  14322. if(OcppTempPath == NULL)
  14323. {
  14324. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14325. }
  14326. else
  14327. {
  14328. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14329. }
  14330. result = TRUE;
  14331. goto End;
  14332. }
  14333. else
  14334. {
  14335. strcpy(OcppPath,"");
  14336. }
  14337. End:
  14338. return result;
  14339. }
  14340. int GetOcppPort()
  14341. {
  14342. return OcppPort;
  14343. }
  14344. int GetOcppConnStatus(void)
  14345. {
  14346. return ShmOCPP16Data->OcppConnStatus;
  14347. }
  14348. void SetOcppConnStatus(uint8_t status)
  14349. {
  14350. ShmOCPP16Data->OcppConnStatus = status;
  14351. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14352. }
  14353. int GetHeartBeatWithNOResponse(void)
  14354. {
  14355. return HeartBeatWithNOResponse;
  14356. }
  14357. void SetHeartBeatWithNOResponse(void)
  14358. {
  14359. HeartBeatWithNOResponse = 0;
  14360. }
  14361. void GetStartTransactionIdTag(int gun_index)
  14362. {
  14363. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14364. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14365. }
  14366. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14367. {
  14368. char ch;
  14369. FILE *fptr1;
  14370. int temptransactionId;
  14371. char str[100]={0};
  14372. temptransactionId = 0;
  14373. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14374. {
  14375. DEBUG_INFO("IdTag is empty.\n");
  14376. return temptransactionId;
  14377. }
  14378. /*------ Read the file ----------------*/
  14379. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14380. if (!fptr1)
  14381. {
  14382. DEBUG_INFO("QueueTransactionId file open error.\n");
  14383. //printf(" File not found or unable to open the input file!!\n");
  14384. return temptransactionId;
  14385. }
  14386. ch=fgetc(fptr1);
  14387. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14388. rewind(fptr1);
  14389. if(ch!=EOF)
  14390. {
  14391. // printf("%c",ch);
  14392. while (fgets(str, 100, fptr1) != NULL)
  14393. {
  14394. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14395. if(str[0]=='\0')
  14396. {
  14397. break;
  14398. }
  14399. char *revbuf[8] = {0}; // Variable store string split
  14400. int num = 0;// Quantity after string split
  14401. DEBUG_INFO("Transaction queue data= %s\n", str);
  14402. splitstring(str,",",revbuf,&num); // String split
  14403. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14404. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14405. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14406. DEBUG_INFO("------------------------------\n");
  14407. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14408. {
  14409. if(isStopTransaction)
  14410. {
  14411. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14412. {
  14413. temptransactionId = atoi(revbuf[2]);
  14414. //break;
  14415. }
  14416. }
  14417. else
  14418. {
  14419. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14420. {
  14421. temptransactionId = atoi(revbuf[2]);
  14422. //break;
  14423. }
  14424. }
  14425. }
  14426. }
  14427. }
  14428. else
  14429. DEBUG_INFO("EOF\n");
  14430. fclose(fptr1);
  14431. /*------- End of reading ---------------*/
  14432. return temptransactionId;
  14433. }
  14434. void SetTransactionIdZero(int transactionId)
  14435. {
  14436. char ch;
  14437. FILE *fptr1, *fptr2;
  14438. int temptransactionId = 0;
  14439. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14440. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14441. if (!fptr1)
  14442. {
  14443. //printf(" File not found or unable to open the input file!!\n");
  14444. return ;
  14445. }
  14446. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14447. if (!fptr2)
  14448. {
  14449. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14450. fclose(fptr1);
  14451. return ;
  14452. }
  14453. ch=fgetc(fptr1);
  14454. rewind(fptr1);
  14455. if(ch!=EOF)
  14456. {
  14457. // copy all contents to the temporary file except the specific line
  14458. while (fgets(str, 100, fptr1) != NULL)
  14459. {
  14460. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14461. if(str[0]=='\0')
  14462. {
  14463. break;
  14464. }
  14465. char *revbuf[8] = {0};
  14466. int num = 0;
  14467. strcpy(strtemp, str);
  14468. splitstring(str,",",revbuf,&num);
  14469. if(revbuf[2][0] != '\0')
  14470. {
  14471. temptransactionId = atoi(revbuf[2]);
  14472. if(transactionId != temptransactionId)
  14473. {
  14474. fprintf(fptr2, "%s\n", strtemp);
  14475. }
  14476. }
  14477. }
  14478. }
  14479. fclose(fptr1);
  14480. fclose(fptr2);
  14481. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14482. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14483. /*------ Read the file ----------------*/
  14484. }
  14485. int InternetDisconnect(void)
  14486. {
  14487. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14488. }
  14489. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14490. void storeTempStopTransaction(int gun_index)
  14491. {
  14492. char guid[37]={0};
  14493. int tempIndex = 0;
  14494. char TempStopTransaction[256];
  14495. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14496. DEBUG_INFO("storeTempStopTransaction...\n");
  14497. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14498. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14499. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14500. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14501. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14502. {
  14503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14504. {
  14505. tempIndex = ((gun_index==2) ? 1: 0);
  14506. }
  14507. else
  14508. {
  14509. tempIndex = gun_index;
  14510. }
  14511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14512. {
  14513. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14514. {
  14515. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14516. }
  14517. }// END OF CHAdeMO_QUANTITY
  14518. }
  14519. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14520. {
  14521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14522. {
  14523. tempIndex = ((gun_index==2) ? 1: 0);
  14524. }
  14525. else
  14526. {
  14527. tempIndex = gun_index;
  14528. }
  14529. for (int index = 0; index < CCS_QUANTITY; index++)
  14530. {
  14531. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14532. {
  14533. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14534. }
  14535. }// END OF CCS_QUANTITY
  14536. }
  14537. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14538. {
  14539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14540. {
  14541. tempIndex = ((gun_index==2) ? 1: 0);
  14542. }
  14543. else
  14544. {
  14545. tempIndex = gun_index;
  14546. }
  14547. for (int index = 0; index < GB_QUANTITY; index++)
  14548. {
  14549. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14550. {
  14551. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14552. }
  14553. }// END OF GB_QUANTITY
  14554. }
  14555. else if(gunType[gun_index] == GUN_TYPE_DO)
  14556. {
  14557. tempIndex = gun_index;
  14558. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14559. {
  14560. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14561. {
  14562. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14563. }
  14564. }
  14565. }
  14566. else
  14567. {
  14568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14569. {
  14570. tempIndex = 2;
  14571. }
  14572. else
  14573. {
  14574. tempIndex = gun_index;
  14575. }
  14576. for (int index = 0; index < AC_QUANTITY; index++)
  14577. {
  14578. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14579. {
  14580. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14581. }
  14582. }// END OF AC_QUANTITY
  14583. }
  14584. //Stop Transaction Time
  14585. struct timeval tmnow;
  14586. struct tm *tm;
  14587. char buf[28];//, usec_buf[6];
  14588. gettimeofday(&tmnow, NULL);
  14589. time_t t;
  14590. t = time(NULL);
  14591. /*UTC time and date*/
  14592. tm = gmtime(&t);
  14593. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14595. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14597. random_uuid(guid);
  14598. /***********************************transactionData******************************************************/
  14599. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14601. //=================================
  14602. //1. Transaction_Begin
  14603. //=================================
  14604. //============================== Energy.Active.Import.Interval ===========================================
  14605. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14606. {
  14607. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  14611. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14612. 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))
  14613. {
  14614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14615. }
  14616. else
  14617. {
  14618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14619. }
  14620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14622. }
  14623. //=================================
  14624. //2. Transaction_End
  14625. //=================================
  14626. //2.1====================================== Current.Import L1 ==============================================
  14627. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14628. {
  14629. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14630. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14631. {
  14632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14633. {
  14634. tempIndex = ((gun_index==2) ? 1: 0);
  14635. }
  14636. else
  14637. {
  14638. tempIndex = gun_index;
  14639. }
  14640. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14641. {
  14642. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14643. {
  14644. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14645. }
  14646. }// End of for CHAdeMO_QUANTITY
  14647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14648. }
  14649. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14650. {
  14651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14652. {
  14653. tempIndex = ((gun_index==2) ? 1: 0);
  14654. }
  14655. else
  14656. {
  14657. tempIndex = gun_index;
  14658. }
  14659. for (int index = 0; index < CCS_QUANTITY; index++)
  14660. {
  14661. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14662. {
  14663. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14664. }
  14665. }// End of for CCS_QUANTITY
  14666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14667. }
  14668. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14669. {
  14670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14671. {
  14672. tempIndex = ((gun_index==2) ? 1: 0);
  14673. }
  14674. else
  14675. {
  14676. tempIndex = gun_index;
  14677. }
  14678. for (int index = 0; index < GB_QUANTITY; index++)
  14679. {
  14680. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14681. {
  14682. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14683. }
  14684. }// End of for GB_QUANTITY
  14685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14686. }
  14687. else if(gunType[gun_index] == GUN_TYPE_DO)
  14688. {
  14689. tempIndex = gun_index;
  14690. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14691. {
  14692. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14693. {
  14694. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14695. }
  14696. }
  14697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14698. }
  14699. else
  14700. {
  14701. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14702. {
  14703. tempIndex = 2;
  14704. }
  14705. else
  14706. {
  14707. tempIndex = gun_index;
  14708. }
  14709. for (int index = 0; index < AC_QUANTITY; index++)
  14710. {
  14711. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14712. {
  14713. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14714. }
  14715. }// End of for AC_QUANTITY
  14716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14717. }
  14718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14721. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14724. }
  14725. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14726. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14727. {
  14728. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14729. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14730. {
  14731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14732. {
  14733. tempIndex = ((gun_index==2) ? 1: 0);
  14734. }
  14735. else
  14736. {
  14737. tempIndex = gun_index;
  14738. }
  14739. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14740. {
  14741. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14742. {
  14743. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14744. }
  14745. }// END OF CHAdeMO_QUANTITY
  14746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14747. }
  14748. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14749. {
  14750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14751. {
  14752. tempIndex = ((gun_index==2) ? 1: 0);
  14753. }
  14754. else
  14755. {
  14756. tempIndex = gun_index;
  14757. }
  14758. for (int index = 0; index < CCS_QUANTITY; index++)
  14759. {
  14760. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14761. {
  14762. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14763. }
  14764. }// END OF CCS_QUANTITY
  14765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14766. }
  14767. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14768. {
  14769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14770. {
  14771. tempIndex = ((gun_index==2) ? 1: 0);
  14772. }
  14773. else
  14774. {
  14775. tempIndex = gun_index;
  14776. }
  14777. for (int index = 0; index < GB_QUANTITY; index++)
  14778. {
  14779. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14780. {
  14781. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14782. }
  14783. }// END OF GB_QUANTITY
  14784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14785. }
  14786. else if(gunType[gun_index] == GUN_TYPE_DO)
  14787. {
  14788. tempIndex = gun_index;
  14789. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14790. {
  14791. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14792. {
  14793. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14794. }
  14795. }
  14796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14797. }
  14798. else
  14799. {
  14800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14801. {
  14802. tempIndex = 2;
  14803. }
  14804. else
  14805. {
  14806. tempIndex = gun_index;
  14807. }
  14808. for (int index = 0; index < AC_QUANTITY; index++)
  14809. {
  14810. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14811. {
  14812. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14813. }
  14814. }// END OF AC_QUANTITY
  14815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14816. }
  14817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14820. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14823. }
  14824. //2.3====================================== Power.Active.Import =========================================
  14825. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14826. {
  14827. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14828. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14829. {
  14830. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14831. {
  14832. tempIndex = ((gun_index==2) ? 1: 0);
  14833. }
  14834. else
  14835. {
  14836. tempIndex = gun_index;
  14837. }
  14838. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14839. {
  14840. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14841. {
  14842. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14843. }
  14844. } // End for CHAdeMO_QUANTITY
  14845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14846. }
  14847. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14848. {
  14849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14850. {
  14851. tempIndex = ((gun_index==2) ? 1: 0);
  14852. }
  14853. else
  14854. {
  14855. tempIndex = gun_index;
  14856. }
  14857. for (int index = 0; index < CCS_QUANTITY; index++)
  14858. {
  14859. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14860. {
  14861. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14862. }
  14863. } // END for CCS_QUANTITY
  14864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14865. }
  14866. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14867. {
  14868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14869. {
  14870. tempIndex = ((gun_index==2) ? 1: 0);
  14871. }
  14872. else
  14873. {
  14874. tempIndex = gun_index;
  14875. }
  14876. for (int index = 0; index < GB_QUANTITY; index++)
  14877. {
  14878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14879. {
  14880. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14881. }
  14882. }// END for GB_QUANTITY
  14883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14884. }
  14885. else if(gunType[gun_index] == GUN_TYPE_DO)
  14886. {
  14887. tempIndex = gun_index;
  14888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14889. {
  14890. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14891. {
  14892. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14893. }
  14894. }
  14895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14896. }
  14897. else
  14898. {
  14899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14900. {
  14901. tempIndex = 2;
  14902. }
  14903. else
  14904. {
  14905. tempIndex = gun_index;
  14906. }
  14907. for (int index = 0; index < AC_QUANTITY; index++)
  14908. {
  14909. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14910. {
  14911. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14912. }
  14913. } // END for AC_QUANTITY
  14914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14915. }
  14916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14919. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14922. }
  14923. //2.4====================================== Voltage L1 ====================================================
  14924. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14925. {
  14926. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14927. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14928. {
  14929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14930. {
  14931. tempIndex = ((gun_index==2) ? 1: 0);
  14932. }
  14933. else
  14934. {
  14935. tempIndex = gun_index;
  14936. }
  14937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14938. {
  14939. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14940. {
  14941. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14942. }
  14943. } // END OF FOR CHAdeMO_QUANTITY
  14944. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14945. }
  14946. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14947. {
  14948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14949. {
  14950. tempIndex = ((gun_index==2) ? 1: 0);
  14951. }
  14952. else
  14953. {
  14954. tempIndex = gun_index;
  14955. }
  14956. for (int index = 0; index < CCS_QUANTITY; index++)
  14957. {
  14958. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14959. {
  14960. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14961. }
  14962. } // END OF FOR CCS_QUANTITY
  14963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14964. }
  14965. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14966. {
  14967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14968. {
  14969. tempIndex = ((gun_index==2) ? 1: 0);
  14970. }
  14971. else
  14972. {
  14973. tempIndex = gun_index;
  14974. }
  14975. for (int index = 0; index < GB_QUANTITY; index++)
  14976. {
  14977. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14978. {
  14979. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14980. }
  14981. } // END OF FOR GB_QUANTITY
  14982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14983. }
  14984. else if(gunType[gun_index] == GUN_TYPE_DO)
  14985. {
  14986. tempIndex = gun_index;
  14987. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14988. {
  14989. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14990. {
  14991. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14992. }
  14993. }
  14994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14995. }
  14996. else
  14997. {
  14998. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14999. {
  15000. tempIndex = 2;
  15001. }
  15002. else
  15003. {
  15004. tempIndex = gun_index;
  15005. }
  15006. for (int index = 0; index < AC_QUANTITY; index++)
  15007. {
  15008. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15009. {
  15010. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15011. }
  15012. } // END OF FOR AC_QUANTITY
  15013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15014. }
  15015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15018. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15021. }
  15022. //2.5============================================== End SoC =========================================================
  15023. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15024. {
  15025. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15026. 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))
  15027. {
  15028. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15029. {
  15030. tempIndex = ((gun_index==2) ? 1: 0);
  15031. }
  15032. else
  15033. {
  15034. tempIndex = gun_index;
  15035. }
  15036. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15037. {
  15038. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15039. {
  15040. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15041. {
  15042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15043. }
  15044. }
  15045. }
  15046. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15047. {
  15048. for (int index = 0; index < CCS_QUANTITY; index++)
  15049. {
  15050. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15051. {
  15052. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15053. }
  15054. }
  15055. }
  15056. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15057. {
  15058. for (int index = 0; index < GB_QUANTITY; index++)
  15059. {
  15060. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15061. {
  15062. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15063. }
  15064. }
  15065. }
  15066. else if(gunType[gun_index] == GUN_TYPE_DO)
  15067. {
  15068. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15069. {
  15070. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15071. {
  15072. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15073. }
  15074. }
  15075. }
  15076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15082. } // END FOR DC CASE
  15083. }
  15084. //2.6====================================== Current.Import L2 ==============================================
  15085. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15086. {
  15087. // AC 3 phase L2 current
  15088. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15089. {
  15090. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15091. {
  15092. tempIndex = 2;
  15093. }
  15094. else
  15095. {
  15096. tempIndex = gun_index;
  15097. }
  15098. for (int index = 0; index < AC_QUANTITY; index++)
  15099. {
  15100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15101. {
  15102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15103. }
  15104. }// End of for AC_QUANTITY
  15105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15106. }
  15107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15112. }
  15113. //2.7====================================== Current.Import L3 ==============================================
  15114. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15115. {
  15116. // AC 3 phase L3 current
  15117. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15118. {
  15119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15120. {
  15121. tempIndex = 2;
  15122. }
  15123. else
  15124. {
  15125. tempIndex = gun_index;
  15126. }
  15127. for (int index = 0; index < AC_QUANTITY; index++)
  15128. {
  15129. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15130. {
  15131. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15132. }
  15133. }// End of for AC_QUANTITY
  15134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15135. }
  15136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15141. }
  15142. //2.9====================================== Voltage L2 ====================================================
  15143. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15144. {
  15145. // AC 3 phase L2 volatge
  15146. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15147. {
  15148. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15149. {
  15150. tempIndex = 2;
  15151. }
  15152. else
  15153. {
  15154. tempIndex = gun_index;
  15155. }
  15156. for (int index = 0; index < AC_QUANTITY; index++)
  15157. {
  15158. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15159. {
  15160. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15161. }
  15162. } // END OF FOR AC_QUANTITY
  15163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15164. }
  15165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15170. }
  15171. //2.10====================================== Voltage L3 ====================================================
  15172. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15173. {
  15174. // AC 3 phase L3 volatge
  15175. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15176. {
  15177. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15178. {
  15179. tempIndex = 2;
  15180. }
  15181. else
  15182. {
  15183. tempIndex = gun_index;
  15184. }
  15185. for (int index = 0; index < AC_QUANTITY; index++)
  15186. {
  15187. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15188. {
  15189. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15190. }
  15191. } // END OF FOR AC_QUANTITY
  15192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15193. }
  15194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15199. }
  15200. //====================== Start SoC ================================
  15201. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15202. {
  15203. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15204. 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))
  15205. {
  15206. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15207. {
  15208. tempIndex = ((gun_index==2) ? 1: 0);
  15209. }
  15210. else
  15211. {
  15212. tempIndex = gun_index;
  15213. }
  15214. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15215. {
  15216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15217. {
  15218. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15219. {
  15220. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15221. }
  15222. }
  15223. }
  15224. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15225. {
  15226. for (int index = 0; index < CCS_QUANTITY; index++)
  15227. {
  15228. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15229. {
  15230. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15231. }
  15232. }
  15233. }
  15234. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15235. {
  15236. for (int index = 0; index < GB_QUANTITY; index++)
  15237. {
  15238. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15239. {
  15240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15241. }
  15242. }
  15243. }
  15244. else if(gunType[gun_index] == GUN_TYPE_DO)
  15245. {
  15246. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15247. {
  15248. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15249. {
  15250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15251. }
  15252. }
  15253. }
  15254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15260. } // END FOR DC CASE
  15261. }
  15262. //======================================== Message create ==============================================
  15263. json_object *StopTransaction = json_object_new_object();
  15264. json_object *transactionDatas = json_object_new_array();
  15265. json_object *sampledValues = json_object_new_array();
  15266. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15267. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15268. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15269. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15270. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15271. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15272. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15273. {
  15274. json_object *transactionData = json_object_new_object();
  15275. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15276. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15277. {
  15278. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15279. {
  15280. json_object *sampledValue = json_object_new_object();
  15281. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15282. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15283. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15284. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15285. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15286. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15287. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15288. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15289. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15290. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15291. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15292. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15293. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15294. json_object_array_add(sampledValues, sampledValue);
  15295. }
  15296. }
  15297. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15298. json_object_array_add(transactionDatas, transactionData);
  15299. }
  15300. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15301. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15302. ,MESSAGE_TYPE_CALL
  15303. ,guid
  15304. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15305. json_object_put(StopTransaction);
  15306. // Check File "TempStopTransaction" Exist
  15307. if((access(TempStopTransaction,F_OK))!=-1)
  15308. {
  15309. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15310. fclose(fopen(TempStopTransaction, "w"));
  15311. }
  15312. else
  15313. {
  15314. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15315. FILE *log = fopen(TempStopTransaction, "w+");
  15316. if(log == NULL)
  15317. {
  15318. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15319. return ;
  15320. }
  15321. else
  15322. {
  15323. fclose(log);
  15324. }
  15325. }
  15326. //Add TempStopTransaction | Update TempStopTransaction
  15327. // open file for writing
  15328. FILE *outfile;
  15329. outfile = fopen (TempStopTransaction, "a");
  15330. //DEBUG_INFO("data = %s\n", queuedata);
  15331. fputs(queuedata, outfile);
  15332. fputs("\n", outfile);
  15333. fclose (outfile);
  15334. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15335. }
  15336. void checkTempStopTransaction(int gun_index)
  15337. {
  15338. FILE *fptr1;
  15339. char ch;
  15340. char str[QUEUE_MESSAGE_LENGTH]={0};
  15341. char guid[37]={0};
  15342. char tempdata[65]={0};
  15343. char connectorStr[2]={0};
  15344. char TempStopTransaction[256];
  15345. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15346. fptr1 = fopen(TempStopTransaction, "r");
  15347. //TempStopTransaction格式: 槍號,StopTransaction封包
  15348. if (!fptr1)
  15349. {
  15350. //printf(" File not found or unable to open the input file!!\n");
  15351. return ;
  15352. }
  15353. ch=fgetc(fptr1);
  15354. //printf(" Now the content of the file %s is : \n",fname);
  15355. rewind(fptr1);
  15356. if(ch!=EOF)
  15357. {
  15358. // copy all contents to the temporary file except the specific line
  15359. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15360. {
  15361. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15362. if(str[0]=='\0')
  15363. {
  15364. break;
  15365. }
  15366. //TempStopTransaction格式: 槍號,StopTransaction封包
  15367. strncpy(connectorStr, str, 1);
  15368. if(atoi(connectorStr) != (gun_index+1))
  15369. {
  15370. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15371. fclose(fptr1);
  15372. return ;
  15373. }
  15374. //random_uuid(guid);
  15375. strncpy(guid, str+6, 36); //copy guid
  15376. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15377. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15378. {
  15379. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15380. }
  15381. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15382. OCPP_insert_transaction_msg(NO, str);
  15383. memset(str,0,ARRAY_SIZE(str));
  15384. }
  15385. }
  15386. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15387. fclose(fptr1);
  15388. remove(TempStopTransaction); // remove the original file
  15389. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15390. }
  15391. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15392. {
  15393. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15394. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15395. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15396. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15397. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15398. }
  15399. int GetWebSocketPingInterval(void)
  15400. {
  15401. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15402. }
  15403. int GetServerSign(void)
  15404. {
  15405. return server_sign;
  15406. }
  15407. uint8_t GetOcppSecurityProfile()
  15408. {
  15409. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15410. }
  15411. void GetOcppChargerBoxId(uint8_t *data)
  15412. {
  15413. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15414. }
  15415. void GetOcppSecurityPassword(uint8_t *data)
  15416. {
  15417. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15418. }
  15419. void SetOcppVersion(uint8_t *version)
  15420. {
  15421. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15422. DEBUG_INFO("ocpp version: %s\n", version);
  15423. if(strstr((char*)version, "ocpp1.6") != NULL)
  15424. {
  15425. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15426. }
  15427. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15428. {
  15429. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15430. system("pkill OcppBackend");
  15431. }
  15432. }
  15433. void SetServerSign(int value)
  15434. {
  15435. server_sign = value;
  15436. }
  15437. int GetBootNotificationInterval(void)
  15438. {
  15439. return BootNotificationInterval;
  15440. }
  15441. int GetInternetConn(void)
  15442. {
  15443. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15444. }
  15445. int GetBackendConnectionTimeout(void)
  15446. {
  15447. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15448. }
  15449. int isConnectorInitMode(int gun_index)
  15450. {
  15451. int tempIndex = 0;
  15452. int result = TRUE;
  15453. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15454. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15455. {
  15456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15457. {
  15458. tempIndex = ((gun_index==2) ? 1: 0);
  15459. }
  15460. else
  15461. {
  15462. tempIndex = gun_index;
  15463. }
  15464. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15465. {
  15466. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15467. {
  15468. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15469. } //end of the same index
  15470. }//end of for CHAdeMO_QUANTITY
  15471. }
  15472. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15473. {
  15474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15475. {
  15476. tempIndex = ((gun_index==2) ? 1: 0);
  15477. }
  15478. else
  15479. {
  15480. tempIndex = gun_index;
  15481. }
  15482. for (int index = 0; index < CCS_QUANTITY; index++)
  15483. {
  15484. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15485. {
  15486. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15487. } //end of the same index
  15488. } // end of for CCS_QUANTITY
  15489. }
  15490. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15491. {
  15492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15493. {
  15494. tempIndex = ((gun_index==2) ? 1: 0);
  15495. }
  15496. else
  15497. {
  15498. tempIndex = gun_index;
  15499. }
  15500. for (int index = 0; index < GB_QUANTITY; index++)
  15501. {
  15502. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15503. {
  15504. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15505. } //end of the same index
  15506. } // end of for GB_QUANTITY
  15507. }
  15508. else if(gunType[gun_index] == GUN_TYPE_DO)
  15509. {
  15510. tempIndex = gun_index;
  15511. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15512. {
  15513. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15514. {
  15515. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15516. } //end of the same index
  15517. }
  15518. }
  15519. else
  15520. {
  15521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15522. {
  15523. tempIndex = 2;
  15524. }
  15525. else
  15526. {
  15527. tempIndex = gun_index;
  15528. }
  15529. for (int index = 0; index < AC_QUANTITY; index++)
  15530. {
  15531. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15532. {
  15533. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15534. }//end of the same index
  15535. }//end of for AC_QUANTITY
  15536. }
  15537. return result;
  15538. }
  15539. void refreshProcDogTimer()
  15540. {
  15541. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15542. }
  15543. void InitialSystemValue(void)
  15544. {
  15545. int connectorIndex = 0;
  15546. //int valueASCII = 0;
  15547. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15548. gunTotalNumber=0;
  15549. SystemInitial = 0;
  15550. localversion=0;
  15551. BootNotificationInterval = 0;
  15552. authorizeRetryTimes = 0;
  15553. GunStatusInterval = 10;
  15554. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15555. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15556. //Hear Beat
  15557. HeartBeatWithNOResponse = 0;
  15558. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15559. FirstHeartBeat = 0;
  15560. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15561. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15562. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15563. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15564. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15565. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15566. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15567. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15568. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15569. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15570. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15571. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15572. memset(gunType, 0, ARRAY_SIZE(gunType));
  15573. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15574. {
  15575. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15576. {
  15577. // DO series
  15578. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15579. {
  15580. SystemInitial = SystemInitial + 1;
  15581. gunTotalNumber = gunTotalNumber + 1;
  15582. gunType[connectorIndex] = GUN_TYPE_DO;
  15583. connectorIndex = connectorIndex + 1;
  15584. }
  15585. }
  15586. else
  15587. {
  15588. // DM, DW, DS series
  15589. //check connector / socket type (index: 8, 9, 10)
  15590. for(int index=7; index <10 ; index++)
  15591. {
  15592. if(index != 8)
  15593. {
  15594. // DC Connector
  15595. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15596. {
  15597. SystemInitial = SystemInitial + 1;
  15598. gunTotalNumber = gunTotalNumber + 1;
  15599. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15600. connectorIndex = connectorIndex + 1;
  15601. }
  15602. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15603. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15604. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15605. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15606. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15607. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15608. {
  15609. SystemInitial = SystemInitial + 1;
  15610. gunTotalNumber = gunTotalNumber + 1;
  15611. gunType[connectorIndex] = GUN_TYPE_CCS;
  15612. connectorIndex = connectorIndex + 1;
  15613. }
  15614. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15615. {
  15616. SystemInitial = SystemInitial + 1;
  15617. gunTotalNumber = gunTotalNumber + 1;
  15618. gunType[connectorIndex] = GUN_TYPE_GBT;
  15619. connectorIndex = connectorIndex + 1;
  15620. }
  15621. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15622. {
  15623. SystemInitial = SystemInitial + 1;
  15624. gunTotalNumber = gunTotalNumber + 1;
  15625. gunType[connectorIndex] = GUN_TYPE_DO;
  15626. connectorIndex = connectorIndex + 1;
  15627. }
  15628. }
  15629. else
  15630. {
  15631. // AC Connector
  15632. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15633. {
  15634. SystemInitial = SystemInitial + 1;
  15635. gunTotalNumber = gunTotalNumber + 1;
  15636. gunType[connectorIndex] = GUN_TYPE_AC;
  15637. connectorIndex = connectorIndex + 1;
  15638. }
  15639. }
  15640. }
  15641. }
  15642. //DEBUG_INFO("DC ...\n");
  15643. }
  15644. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15645. {
  15646. //check connector / socket type (index: 8, 9, 10)
  15647. for(int index=7; index <10 ; index++)
  15648. {
  15649. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15650. {
  15651. SystemInitial = SystemInitial + 1;
  15652. gunTotalNumber = gunTotalNumber + 1;
  15653. gunType[connectorIndex] = GUN_TYPE_AC;
  15654. connectorIndex = connectorIndex + 1;
  15655. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15656. }
  15657. }
  15658. }
  15659. //Status && ConnectorPlugIn Setting
  15660. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15661. {
  15662. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15663. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15664. }
  15665. for (int index = 0; index < CCS_QUANTITY; index++)
  15666. {
  15667. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15668. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15669. }
  15670. for (int index = 0; index < GB_QUANTITY; index++)
  15671. {
  15672. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15673. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15674. }
  15675. for (int index = 0; index < AC_QUANTITY; index++)
  15676. {
  15677. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15678. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15679. }
  15680. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15681. {
  15682. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15683. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15684. }
  15685. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15686. {
  15687. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15688. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15689. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15690. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15691. }
  15692. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15693. clientTime.Heartbeat=time((time_t*)NULL);
  15694. sleep(1);
  15695. }
  15696. void LWS_Send(char *str)
  15697. {
  15698. //=====================================================
  15699. // Check InternetConn 0: disconnected, 1: connected
  15700. //====================================================
  15701. if(GetOcppConnStatus() == 0)
  15702. {
  15703. DEBUG_INFO("offline now !!!\n");
  15704. return;
  15705. }
  15706. // Only disable isWebsocketSendable operation initiated by charger
  15707. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15708. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15709. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15710. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15711. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15712. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15713. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15714. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15715. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15716. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15717. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15718. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15719. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15720. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15721. {
  15722. isWebsocketSendable = 0;
  15723. }
  15724. pthread_mutex_lock(&lock_send);
  15725. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15726. sprintf((char *)SendBuffer, "%s", str);
  15727. SendBufLen = strlen(str);
  15728. pthread_mutex_unlock(&lock_send);
  15729. lws_callback_on_writable(wsi_client);
  15730. //lws_service(context, 0);
  15731. //sleep(1);
  15732. }
  15733. void LWS_SendNow(char *str)
  15734. {
  15735. //=====================================================
  15736. // Check InternetConn 0: disconnected, 1: connected
  15737. //====================================================
  15738. if(GetOcppConnStatus() == 0)
  15739. {
  15740. DEBUG_INFO("offline now !!!\n");
  15741. return;
  15742. }
  15743. // Only disable isWebsocketSendable operation initiated by charger
  15744. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15745. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15746. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15747. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15748. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15749. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15750. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15751. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15752. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15753. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15754. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15755. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15756. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15757. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15758. {
  15759. isWebsocketSendable = 0;
  15760. }
  15761. pthread_mutex_lock(&lock_send);
  15762. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15763. sprintf((char *)SendBuffer, "%s", str);
  15764. SendBufLen = strlen(str);
  15765. pthread_mutex_unlock(&lock_send);
  15766. lws_callback_on_writable(wsi_client);
  15767. lws_service(context, 0);
  15768. //sleep(1);
  15769. }