MessageHandler.c 770 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119
  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_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2655. {
  2656. checkTempStopTransaction(gun_index);
  2657. }
  2658. #endif
  2659. }
  2660. }
  2661. }
  2662. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2663. {
  2664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2665. {
  2666. tempIndex = ((gun_index==2) ? 1: 0);
  2667. }
  2668. else
  2669. {
  2670. tempIndex = gun_index;
  2671. }
  2672. for (int index = 0; index < CCS_QUANTITY; index++)
  2673. {
  2674. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2675. {
  2676. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2677. {
  2678. // Sent unplug message for California pricing logic
  2679. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2680. {
  2681. uint8_t ts[20];
  2682. getNowDatetime(ts);
  2683. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2684. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2685. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2686. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2687. }
  2688. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2689. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2690. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2691. statusModeChage[gun_index] = TRUE;
  2692. }
  2693. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2694. {
  2695. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2696. if((access(filenmae,F_OK))!=-1)
  2697. {
  2698. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2699. sprintf(str,"rm -f %s",filenmae);
  2700. system(str);
  2701. }
  2702. }
  2703. #if 1 // for TempStopTransaction
  2704. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2705. {
  2706. checkTempStopTransaction(gun_index);
  2707. }
  2708. #endif
  2709. }
  2710. }
  2711. }
  2712. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2713. {
  2714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2715. {
  2716. tempIndex = ((gun_index==2) ? 1: 0);
  2717. }
  2718. else
  2719. {
  2720. tempIndex = gun_index;
  2721. }
  2722. for (int index = 0; index < GB_QUANTITY; index++)
  2723. {
  2724. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2725. {
  2726. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2727. {
  2728. // Sent unplug message for California pricing logic
  2729. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2730. {
  2731. uint8_t ts[20];
  2732. getNowDatetime(ts);
  2733. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2734. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2735. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2736. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2737. }
  2738. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2739. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2740. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2741. statusModeChage[gun_index] = TRUE;
  2742. }
  2743. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2744. {
  2745. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2746. if((access(filenmae,F_OK))!=-1)
  2747. {
  2748. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2749. sprintf(str,"rm -f %s",filenmae);
  2750. system(str);
  2751. }
  2752. }
  2753. #if 1 // for TempStopTransaction
  2754. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2755. {
  2756. checkTempStopTransaction(gun_index);
  2757. }
  2758. #endif
  2759. }
  2760. }
  2761. }
  2762. else if(gunType[gun_index] == GUN_TYPE_DO)
  2763. {
  2764. tempIndex = gun_index;
  2765. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2766. {
  2767. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2768. {
  2769. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2770. {
  2771. // Sent unplug message for California pricing logic
  2772. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2773. {
  2774. uint8_t ts[20];
  2775. getNowDatetime(ts);
  2776. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2777. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2778. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2779. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2780. }
  2781. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2782. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2783. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2784. statusModeChage[gun_index] = TRUE;
  2785. }
  2786. 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
  2787. {
  2788. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2789. if((access(filenmae,F_OK))!=-1)
  2790. {
  2791. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2792. sprintf(str,"rm -f %s",filenmae);
  2793. system(str);
  2794. }
  2795. }
  2796. #if 1 // for TempStopTransaction
  2797. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2798. {
  2799. checkTempStopTransaction(gun_index);
  2800. }
  2801. #endif
  2802. }
  2803. }
  2804. }
  2805. else
  2806. {
  2807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2808. {
  2809. tempIndex = 2;
  2810. }
  2811. else
  2812. {
  2813. tempIndex = gun_index;
  2814. }
  2815. for (int index = 0; index < AC_QUANTITY; index++)
  2816. {
  2817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2818. {
  2819. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2820. {
  2821. // Sent unplug message for California pricing logic
  2822. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2823. {
  2824. uint8_t ts[20];
  2825. getNowDatetime(ts);
  2826. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2827. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2828. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2829. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2830. }
  2831. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2832. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2833. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2834. statusModeChage[gun_index] = TRUE;
  2835. }
  2836. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2837. {
  2838. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2839. if((access(filenmae,F_OK))!=-1)
  2840. {
  2841. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2842. sprintf(str,"rm -f %s",filenmae);
  2843. system(str);
  2844. }
  2845. }
  2846. #if 1 // for TempStopTransaction
  2847. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2848. {
  2849. checkTempStopTransaction(gun_index);
  2850. }
  2851. #endif
  2852. }
  2853. }// END
  2854. }
  2855. if(isWebsocketSendable && (server_sign == TRUE) &&
  2856. (
  2857. (statusModeChage[gun_index] == TRUE) ||
  2858. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2859. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5))
  2860. )
  2861. )
  2862. {
  2863. if(SystemInitial > 0)
  2864. SystemInitial -= 1;
  2865. sendStatusNotificationRequest(gun_index);
  2866. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2867. statusModeChage[gun_index] = FALSE;
  2868. }
  2869. //==============================================
  2870. // Meter report
  2871. //==============================================
  2872. // Trigger MeterValue
  2873. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2874. {
  2875. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2876. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2877. }
  2878. // ClockAlign MeterValue
  2879. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2880. {
  2881. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2882. {
  2883. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2884. {
  2885. tempIndex = ((gun_index==2) ? 1: 0);
  2886. }
  2887. else
  2888. {
  2889. tempIndex = gun_index;
  2890. }
  2891. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2892. {
  2893. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2894. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2895. {
  2896. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2897. {
  2898. reqClockAlignMeter[gun_index] = 1;
  2899. }
  2900. }
  2901. }// End for CHAdeMO
  2902. }
  2903. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2904. {
  2905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2906. {
  2907. tempIndex = ((gun_index==2) ? 1: 0);
  2908. }
  2909. else
  2910. {
  2911. tempIndex = gun_index;
  2912. }
  2913. for (int index = 0; index < CCS_QUANTITY; index++)
  2914. {
  2915. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2916. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2917. {
  2918. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2919. {
  2920. reqClockAlignMeter[gun_index] = 1;
  2921. }
  2922. }
  2923. } // End for CCS
  2924. }
  2925. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2926. {
  2927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2928. {
  2929. tempIndex = ((gun_index==2) ? 1: 0);
  2930. }
  2931. else
  2932. {
  2933. tempIndex = gun_index;
  2934. }
  2935. for (int index = 0; index < GB_QUANTITY; index++)
  2936. {
  2937. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2938. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2939. {
  2940. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2941. {
  2942. reqClockAlignMeter[gun_index] = 1;
  2943. }
  2944. }
  2945. }// End for GB
  2946. }
  2947. else if(gunType[gun_index] == GUN_TYPE_DO)
  2948. {
  2949. tempIndex = gun_index;
  2950. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2951. {
  2952. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2953. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2954. {
  2955. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2956. {
  2957. reqClockAlignMeter[gun_index] = 1;
  2958. }
  2959. }
  2960. }
  2961. }
  2962. else
  2963. {
  2964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2965. {
  2966. tempIndex = 2;
  2967. }
  2968. else
  2969. {
  2970. tempIndex = gun_index;
  2971. }
  2972. for (int index = 0; index < AC_QUANTITY; index++)
  2973. {
  2974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2975. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2976. {
  2977. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2978. {
  2979. reqClockAlignMeter[gun_index] = 1;
  2980. }
  2981. }
  2982. }//End for AC
  2983. }
  2984. if(reqClockAlignMeter[gun_index] == 1)
  2985. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2986. }
  2987. // Sample period MeterValue
  2988. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2989. {
  2990. //check Transaction active
  2991. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2992. {
  2993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2994. {
  2995. tempIndex = ((gun_index==2) ? 1: 0);
  2996. }
  2997. else
  2998. {
  2999. tempIndex = gun_index;
  3000. }
  3001. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3002. {
  3003. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3004. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3005. {
  3006. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3007. {
  3008. reqSampleMeter[gun_index] = 1;
  3009. }
  3010. }
  3011. }// End for CHAdeMO
  3012. }
  3013. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3014. {
  3015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3016. {
  3017. tempIndex = ((gun_index==2) ? 1: 0);
  3018. }
  3019. else
  3020. {
  3021. tempIndex = gun_index;
  3022. }
  3023. for (int index = 0; index < CCS_QUANTITY; index++)
  3024. {
  3025. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3026. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3027. {
  3028. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3029. {
  3030. reqSampleMeter[gun_index] = 1;
  3031. }
  3032. }
  3033. } // End for CCS
  3034. }
  3035. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3036. {
  3037. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3038. {
  3039. tempIndex = ((gun_index==2) ? 1: 0);
  3040. }
  3041. else
  3042. {
  3043. tempIndex = gun_index;
  3044. }
  3045. for (int index = 0; index < GB_QUANTITY; index++)
  3046. {
  3047. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3048. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3049. {
  3050. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3051. {
  3052. reqSampleMeter[gun_index] = 1;
  3053. }
  3054. }
  3055. }// End for GB
  3056. }
  3057. else if(gunType[gun_index] == GUN_TYPE_DO)
  3058. {
  3059. tempIndex = gun_index;
  3060. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3061. {
  3062. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3063. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3064. {
  3065. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3066. {
  3067. reqSampleMeter[gun_index] = 1;
  3068. }
  3069. }
  3070. }
  3071. }
  3072. else
  3073. {
  3074. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3075. {
  3076. tempIndex = 2;
  3077. }
  3078. else
  3079. {
  3080. tempIndex = gun_index;
  3081. }
  3082. for (int index = 0; index < AC_QUANTITY; index++)
  3083. {
  3084. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3085. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3086. {
  3087. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3088. {
  3089. reqSampleMeter[gun_index] = 1;
  3090. }
  3091. }
  3092. }//End for AC
  3093. }
  3094. if(reqSampleMeter[gun_index] == 1)
  3095. {
  3096. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3097. storeTempStopTransaction(gun_index);
  3098. }
  3099. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3100. }
  3101. //==============================================
  3102. // Check Connector reserved
  3103. //==============================================
  3104. //===============================
  3105. // Check if Reserve is expired
  3106. //===============================
  3107. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3108. {
  3109. double diff_t;
  3110. struct tm tp;
  3111. // current time
  3112. time_t t = time(NULL);
  3113. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3114. tp.tm_isdst = -1;
  3115. time_t utc = mktime(&tp);
  3116. diff_t = difftime(utc, t);
  3117. if(diff_t <= 0)
  3118. {
  3119. DEBUG_INFO("reserve expired.\n");
  3120. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3121. }
  3122. }//END OF Check if Reserve is expired
  3123. //==========================================
  3124. // csu trigger FirmwareStatusNotificationReq
  3125. //==========================================
  3126. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3127. {
  3128. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3129. }
  3130. //==========================================
  3131. // csu trigger DiagnosticsStatusNotificationReq
  3132. //==========================================
  3133. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3134. {
  3135. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3136. }
  3137. //==========================================
  3138. // csu trigger CancelReservationConf
  3139. //==========================================
  3140. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3141. {
  3142. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3143. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3144. }
  3145. //==========================================
  3146. // csu trigger ChangeAvailabilityConf
  3147. //==========================================
  3148. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3149. {
  3150. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3151. }
  3152. //==========================================
  3153. // csu trigger UnlockConnectorConf
  3154. //==========================================
  3155. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3156. {
  3157. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3158. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3159. }
  3160. //==========================================
  3161. // csu trigger ReserveNowConf
  3162. //==========================================
  3163. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3164. {
  3165. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3166. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3167. }
  3168. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3169. {
  3170. sendSignCertificateRequest();
  3171. }
  3172. }
  3173. }
  3174. //==========================================
  3175. // send request routine
  3176. //==========================================
  3177. int sendAuthorizeRequest(int gun_index)
  3178. {
  3179. mtrace();
  3180. int result = FAIL;
  3181. char message[100]={0};
  3182. char guid[37];
  3183. char tempdata[65]={0};
  3184. DEBUG_INFO("sendAuthorizeRequest...\n");
  3185. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3186. //Local Authorize
  3187. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3188. {
  3189. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  3190. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3191. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3192. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3193. result = PASS;
  3194. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3195. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3196. authorizeRetryTimes = 0;
  3197. return result;
  3198. }
  3199. 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))||
  3200. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3201. {
  3202. // Query from cache
  3203. DEBUG_INFO("Authorize from cache.\n");
  3204. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3205. // Query from list
  3206. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3207. {
  3208. DEBUG_INFO("Authorize from list.\n");
  3209. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3210. }
  3211. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3212. {
  3213. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3214. {
  3215. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3216. }
  3217. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3218. {
  3219. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3220. }
  3221. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3222. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3223. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3224. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3225. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3226. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3227. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3228. authorizeRetryTimes = 0;
  3229. return result;
  3230. }
  3231. else
  3232. {
  3233. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3234. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3235. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3236. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3237. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3238. else
  3239. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3240. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3241. result = PASS;
  3242. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3243. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3244. authorizeRetryTimes = 0;
  3245. return result;
  3246. }
  3247. }
  3248. //initialize struct Authorize
  3249. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3250. //get data from shared memory
  3251. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3252. random_uuid(guid);
  3253. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3254. LWS_Send(message);
  3255. sprintf(tempdata, "Authorize,%d", gun_index);
  3256. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3257. {
  3258. result = PASS;
  3259. DEBUG_INFO("Authorize mapItem pass\n");
  3260. }
  3261. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3262. return result;
  3263. }
  3264. int sendBootNotificationRequest(void)
  3265. {
  3266. mtrace();
  3267. int result = FAIL;
  3268. char message[500]={0}, payload[700]={0};
  3269. char guid[37]={0};
  3270. char tempdata[65]={0};
  3271. // Fill BootNotification fields
  3272. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3273. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3274. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3275. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3276. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3277. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3278. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3279. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3280. ShmOCPP16Data->ChargeBoxId
  3281. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3282. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3283. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3284. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3285. ,ShmOCPP16Data->BootNotification.CpIccid
  3286. ,ShmOCPP16Data->BootNotification.CpImsi);
  3287. random_uuid(guid);
  3288. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3289. LWS_Send(message);
  3290. sprintf(tempdata, "BootNotification,0");
  3291. 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*/)
  3292. {
  3293. result = PASS;
  3294. }
  3295. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3296. strcpy(queuedata,message);
  3297. return result;
  3298. }
  3299. int sendDataTransferRequest(int gun_index)
  3300. {
  3301. mtrace();
  3302. char message[1000]={0};
  3303. char guid[37]={0};
  3304. char tempdata[65]={0};
  3305. int result = FAIL;
  3306. random_uuid(guid);
  3307. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3308. MESSAGE_TYPE_CALL,
  3309. guid,
  3310. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3311. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3312. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3313. LWS_Send(message);
  3314. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3315. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3316. {
  3317. result = PASS;
  3318. DEBUG_INFO("DataTransfer mapItem pass\n");
  3319. }
  3320. return result;
  3321. }
  3322. int sendDiagnosticsStatusNotificationRequest(char *status)
  3323. {
  3324. mtrace();
  3325. int result = FAIL;
  3326. char message[110]={0};
  3327. char guid[37]={0};
  3328. char tempdata[65]={0};
  3329. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3330. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3331. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3332. random_uuid(guid);
  3333. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3334. LWS_SendNow(message);
  3335. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3336. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3337. {
  3338. result = PASS;
  3339. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3340. }
  3341. //#ifdef SystemLogMessage
  3342. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3343. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3344. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3345. //#endif
  3346. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3347. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3348. //record status
  3349. if(strcmp(status,"Idle")==0)
  3350. {
  3351. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3352. }
  3353. else if(strcmp(status,"Uploaded")==0)
  3354. {
  3355. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3356. }
  3357. else if(strcmp(status,"UploadFailed")==0)
  3358. {
  3359. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3360. }
  3361. else if(strcmp(status,"Uploading")==0)
  3362. {
  3363. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3364. }
  3365. return result;
  3366. }
  3367. int sendFirmwareStatusNotificationRequest(char *status)
  3368. {
  3369. mtrace();
  3370. int result = FAIL;
  3371. char message[110]={0};
  3372. char guid[37]={0};
  3373. char tempdata[65]={0};
  3374. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3375. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3376. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3377. random_uuid(guid);
  3378. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3379. LWS_SendNow(message);
  3380. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3381. 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*/)
  3382. {
  3383. result = PASS;
  3384. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3385. }
  3386. //#ifdef SystemLogMessage
  3387. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3388. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3389. //#endif
  3390. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3391. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3392. //record status
  3393. if(strcmp(status,"Downloaded")==0)
  3394. {
  3395. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3396. }
  3397. else if(strcmp(status,"DownloadFailed")==0)
  3398. {
  3399. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3400. }
  3401. else if(strcmp(status,"Downloading")==0)
  3402. {
  3403. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3404. }
  3405. else if(strcmp(status,"Idle")==0)
  3406. {
  3407. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3408. }
  3409. else if(strcmp(status,"InstallationFailed")==0)
  3410. {
  3411. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3412. }
  3413. else if(strcmp(status,"Installing")==0)
  3414. {
  3415. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3416. }
  3417. else if(strcmp(status,"Installed")==0)
  3418. {
  3419. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3420. }
  3421. return result;
  3422. }
  3423. int sendHeartbeatRequest(int gun_index)
  3424. {
  3425. mtrace();
  3426. int result = FAIL;
  3427. char message[80]={0};
  3428. char guid[37]={0};
  3429. char tempdata[65]={0};
  3430. random_uuid(guid);
  3431. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3432. , MESSAGE_TYPE_CALL
  3433. , guid );
  3434. LWS_Send(message);
  3435. sprintf(tempdata, "Heartbeat,%d", 0);
  3436. 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*/)
  3437. {
  3438. result = PASS;
  3439. }
  3440. return result;
  3441. }
  3442. int sendStartTransactionRequest(int gun_index)
  3443. {
  3444. mtrace();
  3445. int result = FAIL;
  3446. char message[250]={0};
  3447. char guid[37]={0};
  3448. struct timeval tmnow;
  3449. struct tm *tm;
  3450. char buf[28];//, usec_buf[6];
  3451. char tempdata[65]={0};
  3452. int tempIndex = 0;
  3453. DEBUG_INFO("sendStartTransactionRequest...\n");
  3454. gettimeofday(&tmnow, NULL);
  3455. time_t t;
  3456. t = time(NULL);
  3457. /*UTC time and date*/
  3458. tm = gmtime(&t);
  3459. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3460. #if 0 // remove temporally
  3461. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3462. strcat(buf,".");
  3463. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3464. strcat(buf,usec_buf);
  3465. #endif
  3466. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3467. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3468. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3469. // clear StartTransaction Response
  3470. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3471. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3472. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3473. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3474. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3475. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3476. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3477. {
  3478. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3479. {
  3480. tempIndex = ((gun_index==2) ? 1: 0);
  3481. }
  3482. else
  3483. {
  3484. tempIndex = gun_index;
  3485. }
  3486. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3487. {
  3488. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3489. {
  3490. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3491. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3492. }
  3493. }
  3494. }
  3495. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3496. {
  3497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3498. {
  3499. tempIndex = ((gun_index==2) ? 1: 0);
  3500. }
  3501. else
  3502. {
  3503. tempIndex = gun_index;
  3504. }
  3505. for (int index = 0; index < CCS_QUANTITY; index++)
  3506. {
  3507. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3508. {
  3509. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3510. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3511. }
  3512. }
  3513. }
  3514. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3515. {
  3516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3517. {
  3518. tempIndex = ((gun_index==2) ? 1: 0);
  3519. }
  3520. else
  3521. {
  3522. tempIndex = gun_index;
  3523. }
  3524. for (int index = 0; index < GB_QUANTITY; index++)
  3525. {
  3526. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3527. {
  3528. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3529. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3530. }
  3531. }
  3532. }
  3533. else if(gunType[gun_index] == GUN_TYPE_DO)
  3534. {
  3535. tempIndex = gun_index;
  3536. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3537. {
  3538. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3539. {
  3540. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3541. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3542. }
  3543. }
  3544. }
  3545. else
  3546. {
  3547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3548. {
  3549. tempIndex = 2;
  3550. }
  3551. else
  3552. {
  3553. tempIndex = gun_index;
  3554. }
  3555. for (int index = 0; index < AC_QUANTITY; index++)
  3556. {
  3557. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3558. {
  3559. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3560. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3561. }
  3562. }
  3563. }
  3564. random_uuid(guid);
  3565. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3566. {
  3567. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3568. , gun_index +1
  3569. , MESSAGE_TYPE_CALL
  3570. , guid
  3571. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3572. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3573. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3574. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3575. }
  3576. else
  3577. {
  3578. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3579. , gun_index +1
  3580. , MESSAGE_TYPE_CALL
  3581. , guid
  3582. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3583. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3584. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3585. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3586. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3587. }
  3588. #if 1
  3589. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3590. 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*/)
  3591. {
  3592. result = PASS;
  3593. }
  3594. #endif
  3595. strcpy(queuedata, message);
  3596. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3597. OCPP_insert_transaction_msg(YES, queuedata);
  3598. return result;
  3599. }
  3600. int sendStatusNotificationRequest(int gun_index)
  3601. {
  3602. mtrace();
  3603. int result = FAIL;
  3604. char message[600]={0};
  3605. char guid[37];
  3606. int currentStatus = 0;
  3607. struct timeval tmnow;
  3608. struct tm *tm;
  3609. char buf[28];//, usec_buf[6];
  3610. char tempdata[65]={0};
  3611. int tempIndex = 0;
  3612. uint8_t isStateChanged = TRUE;
  3613. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3614. gettimeofday(&tmnow, NULL);
  3615. time_t t;
  3616. t = time(NULL);
  3617. /*UTC time and date*/
  3618. tm = gmtime(&t);
  3619. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3620. #if 0 // remove temporally
  3621. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3622. strcat(buf,".");
  3623. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3624. strcat(buf,usec_buf);
  3625. #endif
  3626. printf("%s",buf);
  3627. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3628. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3629. // it's option
  3630. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3631. /*
  3632. enum _SYSTEM_STATUS
  3633. {
  3634. S_BOOTING = 0,
  3635. S_IDLE, = 1
  3636. S_AUTHORIZING, =2
  3637. S_REASSIGN_CHECK, =3
  3638. S_REASSIGN, =4
  3639. S_PRECHARGE, =5
  3640. S_PREPARING_FOR_EV, =6
  3641. S_PREPARING_FOR_EVSE, =7
  3642. S_CHARGING, =8
  3643. S_TERMINATING, =9
  3644. S_COMPLETE, =10
  3645. S_ALARM, =11
  3646. S_FAULT =12
  3647. }
  3648. */
  3649. //check Transaction active
  3650. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3651. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3652. {
  3653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3654. {
  3655. tempIndex = ((gun_index==2) ? 1: 0);
  3656. }
  3657. else
  3658. {
  3659. tempIndex = gun_index;
  3660. }
  3661. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3662. {
  3663. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3664. {
  3665. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3666. {
  3667. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3668. {
  3669. currentStatus = Preparing; //OCPP Status: Preparing
  3670. }
  3671. else
  3672. {
  3673. currentStatus = Available; //OCPP Status: Available
  3674. }
  3675. }
  3676. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3677. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3678. ) //S_PRECHARGE
  3679. {
  3680. currentStatus = Preparing; //OCPP Status: Preparing
  3681. }
  3682. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3683. {
  3684. currentStatus = Charging; //OCPP Status: Charging
  3685. }
  3686. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3687. {
  3688. currentStatus = Finishing; //OCPP Status: Finishing
  3689. }
  3690. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3691. {
  3692. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3693. }
  3694. 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
  3695. {
  3696. currentStatus = Unavailable; //OCPP Status: Unavailable
  3697. }
  3698. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3699. {
  3700. currentStatus = Faulted; //OCPP Status: Faulted
  3701. }
  3702. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3703. {
  3704. currentStatus = Reserved; //OCPP Status: Reserved
  3705. }
  3706. } //end of the same index
  3707. }//end of for CHAdeMO_QUANTITY
  3708. }
  3709. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3710. {
  3711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3712. {
  3713. tempIndex = ((gun_index==2) ? 1: 0);
  3714. }
  3715. else
  3716. {
  3717. tempIndex = gun_index;
  3718. }
  3719. for (int index = 0; index < CCS_QUANTITY; index++)
  3720. {
  3721. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3722. {
  3723. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3724. {
  3725. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3726. {
  3727. currentStatus = Preparing; //OCPP Status: Preparing
  3728. }
  3729. else
  3730. {
  3731. currentStatus = Available; //OCPP Status: Available
  3732. }
  3733. }
  3734. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3735. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3736. ) //S_PRECHARGE
  3737. {
  3738. currentStatus = Preparing; //OCPP Status: Preparing
  3739. }
  3740. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3741. {
  3742. currentStatus = Charging; //OCPP Status: Charging
  3743. }
  3744. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3745. {
  3746. currentStatus = Finishing; //OCPP Status: Finishing
  3747. }
  3748. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3749. {
  3750. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3751. }
  3752. 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
  3753. {
  3754. currentStatus = Unavailable; //OCPP Status : Unavailable
  3755. }
  3756. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3757. {
  3758. currentStatus = Faulted; //OCPP Status: Faulted
  3759. }
  3760. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3761. {
  3762. currentStatus = Reserved; //OCPP Status: Reserved
  3763. }
  3764. } //end of the same index
  3765. } // end of for CCS_QUANTITY
  3766. }
  3767. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3768. {
  3769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3770. {
  3771. tempIndex = ((gun_index==2) ? 1: 0);
  3772. }
  3773. else
  3774. {
  3775. tempIndex = gun_index;
  3776. }
  3777. for (int index = 0; index < GB_QUANTITY; index++)
  3778. {
  3779. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3780. {
  3781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3782. {
  3783. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3784. {
  3785. currentStatus = Preparing; //OCPP Status: Preparing
  3786. }
  3787. else
  3788. {
  3789. currentStatus = Available; //OCPP Status: Available
  3790. }
  3791. }
  3792. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3793. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3794. ) //S_PRECHARGE
  3795. {
  3796. currentStatus = Preparing; //OCPP Status: Preparing
  3797. }
  3798. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3799. {
  3800. currentStatus = Charging; //OCPP Status: Charging
  3801. }
  3802. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3803. {
  3804. currentStatus = Finishing; //OCPP Status: Finishing
  3805. }
  3806. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3807. {
  3808. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3809. }
  3810. 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
  3811. {
  3812. currentStatus = Unavailable; //OCPP Status: Unavailable
  3813. }
  3814. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3815. {
  3816. currentStatus = Faulted; //OCPP Status: Faulted
  3817. }
  3818. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3819. {
  3820. currentStatus = Reserved; //OCPP Status: Reserved
  3821. }
  3822. } //end of the same index
  3823. } // end of for GB_QUANTITY
  3824. }
  3825. else if(gunType[gun_index] == GUN_TYPE_DO)
  3826. {
  3827. tempIndex = gun_index;
  3828. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3829. {
  3830. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3831. {
  3832. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3833. {
  3834. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3835. {
  3836. currentStatus = Preparing; //OCPP Status: Preparing
  3837. }
  3838. else
  3839. {
  3840. currentStatus = Available; //OCPP Status: Available
  3841. }
  3842. }
  3843. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3844. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3845. ) //S_PRECHARGE
  3846. {
  3847. currentStatus = Preparing; //OCPP Status: Preparing
  3848. }
  3849. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3850. {
  3851. currentStatus = Charging; //OCPP Status: Charging
  3852. }
  3853. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3854. {
  3855. currentStatus = Finishing; //OCPP Status: Finishing
  3856. }
  3857. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3858. {
  3859. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3860. }
  3861. 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
  3862. {
  3863. currentStatus = Unavailable; //OCPP Status: Unavailable
  3864. }
  3865. 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
  3866. {
  3867. currentStatus = Faulted; //OCPP Status: Faulted
  3868. }
  3869. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3870. {
  3871. currentStatus = Reserved; //OCPP Status: Reserved
  3872. }
  3873. } //end of the same index
  3874. }
  3875. }
  3876. else
  3877. {
  3878. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3879. {
  3880. tempIndex = 2;
  3881. }
  3882. else
  3883. {
  3884. tempIndex = gun_index;
  3885. }
  3886. for (int index = 0; index < AC_QUANTITY; index++)
  3887. {
  3888. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3889. {
  3890. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3891. {
  3892. 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))
  3893. {
  3894. currentStatus = Preparing; //OCPP Status: Preparing
  3895. }
  3896. else
  3897. {
  3898. currentStatus = Available; //OCPP Status: Available
  3899. }
  3900. }
  3901. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3902. {
  3903. currentStatus = Preparing; //OCPP Status: Preparing
  3904. }
  3905. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3906. {
  3907. currentStatus = Charging; //OCPP Status: Charging
  3908. }
  3909. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3910. {
  3911. currentStatus = Finishing; //OCPP Status: Finishing
  3912. }
  3913. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3914. {
  3915. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3916. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3917. else
  3918. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3919. }
  3920. 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
  3921. {
  3922. currentStatus = Unavailable; //OCPP Status: Unavailable
  3923. }
  3924. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3925. {
  3926. currentStatus = Faulted; //OCPP Status: Faulted
  3927. }
  3928. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3929. {
  3930. currentStatus = Reserved; //OCPP Status: Reserved
  3931. }
  3932. }//end of the same index
  3933. }//end of for AC_QUANTITY
  3934. }
  3935. //it's option
  3936. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3937. !ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq)
  3938. {
  3939. isStateChanged = FALSE;
  3940. }
  3941. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3942. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3943. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3944. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3945. random_uuid(guid);
  3946. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3947. , MESSAGE_TYPE_CALL
  3948. , guid
  3949. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3950. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3951. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3952. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3953. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3954. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3955. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3956. if((server_sign == TRUE) && isStateChanged)
  3957. {
  3958. LWS_Send(message);
  3959. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3960. 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*/)
  3961. {
  3962. //DEBUG_ERROR("statusNotification mapitem pass");
  3963. result = PASS;
  3964. }
  3965. }
  3966. else
  3967. {
  3968. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3969. result = PASS;
  3970. }
  3971. return result;
  3972. }
  3973. int sendStopTransactionRequest(int gun_index)
  3974. {
  3975. mtrace();
  3976. int result = FAIL;
  3977. //char message[1500]={0};
  3978. char guid[37]={0};
  3979. char tempdata[65]={0};
  3980. int tempIndex = 0;
  3981. char TempStopTransaction[256];
  3982. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3983. //int idx_sample=0;
  3984. DEBUG_INFO("sendStopTransactionRequest \n");
  3985. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3986. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3987. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3988. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3989. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3990. {
  3991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3992. {
  3993. tempIndex = ((gun_index==2) ? 1: 0);
  3994. }
  3995. else
  3996. {
  3997. tempIndex = gun_index;
  3998. }
  3999. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4000. {
  4001. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4002. {
  4003. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4004. }
  4005. }// END OF CHAdeMO_QUANTITY
  4006. }
  4007. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4008. {
  4009. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4010. {
  4011. tempIndex = ((gun_index==2) ? 1: 0);
  4012. }
  4013. else
  4014. {
  4015. tempIndex = gun_index;
  4016. }
  4017. for (int index = 0; index < CCS_QUANTITY; index++)
  4018. {
  4019. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4020. {
  4021. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4022. }
  4023. }// END OF CCS_QUANTITY
  4024. }
  4025. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4026. {
  4027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4028. {
  4029. tempIndex = ((gun_index==2) ? 1: 0);
  4030. }
  4031. else
  4032. {
  4033. tempIndex = gun_index;
  4034. }
  4035. for (int index = 0; index < GB_QUANTITY; index++)
  4036. {
  4037. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4038. {
  4039. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4040. }
  4041. }// END OF GB_QUANTITY
  4042. }
  4043. else if(gunType[gun_index] == GUN_TYPE_DO)
  4044. {
  4045. tempIndex = gun_index;
  4046. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4047. {
  4048. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4049. {
  4050. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4051. }
  4052. }// END OF GB_QUANTITY
  4053. }
  4054. else
  4055. {
  4056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4057. {
  4058. tempIndex = 2;
  4059. }
  4060. else
  4061. {
  4062. tempIndex = gun_index;
  4063. }
  4064. for (int index = 0; index < AC_QUANTITY; index++)
  4065. {
  4066. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4067. {
  4068. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4069. }
  4070. }// END OF AC_QUANTITY
  4071. }
  4072. //====================================== Stop Transaction Time =====================================================
  4073. struct timeval tmnow;
  4074. struct tm *tm;
  4075. char buf[28];//, usec_buf[6];
  4076. gettimeofday(&tmnow, NULL);
  4077. time_t t;
  4078. t = time(NULL);
  4079. /*UTC time and date*/
  4080. tm = gmtime(&t);
  4081. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4083. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4084. random_uuid(guid);
  4085. /***********************************transactionData******************************************************/
  4086. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4088. //=================================
  4089. // Transaction_Begin
  4090. //=================================
  4091. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4092. {
  4093. //============================================ Energy.Active.Import.Interval ================================
  4094. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4097. 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*/]);
  4098. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4099. 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))
  4100. {
  4101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4102. }
  4103. else
  4104. {
  4105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4106. }
  4107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4109. }
  4110. //=================================
  4111. // Transaction_End
  4112. //=================================
  4113. // ================================= Current.Import L1 ===============================================
  4114. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4115. {
  4116. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4117. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4118. {
  4119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4120. {
  4121. tempIndex = ((gun_index==2) ? 1: 0);
  4122. }
  4123. else
  4124. {
  4125. tempIndex = gun_index;
  4126. }
  4127. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4128. {
  4129. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4130. {
  4131. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4132. }
  4133. }// End of for CHAdeMO_QUANTITY
  4134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4135. }
  4136. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4137. {
  4138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4139. {
  4140. tempIndex = ((gun_index==2) ? 1: 0);
  4141. }
  4142. else
  4143. {
  4144. tempIndex = gun_index;
  4145. }
  4146. for (int index = 0; index < CCS_QUANTITY; index++)
  4147. {
  4148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4149. {
  4150. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4151. }
  4152. }// End of for CCS_QUANTITY
  4153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4154. }
  4155. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4156. {
  4157. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4158. {
  4159. tempIndex = ((gun_index==2) ? 1: 0);
  4160. }
  4161. else
  4162. {
  4163. tempIndex = gun_index;
  4164. }
  4165. for (int index = 0; index < GB_QUANTITY; index++)
  4166. {
  4167. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4168. {
  4169. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4170. }
  4171. }// End of for GB_QUANTITY
  4172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4173. }
  4174. else if(gunType[gun_index] == GUN_TYPE_DO)
  4175. {
  4176. tempIndex = gun_index;
  4177. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4178. {
  4179. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4180. {
  4181. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4182. }
  4183. }
  4184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4185. }
  4186. else
  4187. {
  4188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4189. {
  4190. tempIndex = 2;
  4191. }
  4192. else
  4193. {
  4194. tempIndex = gun_index;
  4195. }
  4196. for (int index = 0; index < AC_QUANTITY; index++)
  4197. {
  4198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4199. {
  4200. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4201. }
  4202. }// End of for AC_QUANTITY
  4203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4204. }
  4205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4210. }
  4211. // ================================= Energy.Active.Import.Interval ==============================================
  4212. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4213. {
  4214. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4215. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4216. {
  4217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4218. {
  4219. tempIndex = ((gun_index==2) ? 1: 0);
  4220. }
  4221. else
  4222. {
  4223. tempIndex = gun_index;
  4224. }
  4225. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4226. {
  4227. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4228. {
  4229. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4230. }
  4231. }// END OF CHAdeMO_QUANTITY
  4232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4233. }
  4234. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4235. {
  4236. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4237. {
  4238. tempIndex = ((gun_index==2) ? 1: 0);
  4239. }
  4240. else
  4241. {
  4242. tempIndex = gun_index;
  4243. }
  4244. for (int index = 0; index < CCS_QUANTITY; index++)
  4245. {
  4246. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4247. {
  4248. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4249. }
  4250. }// END OF CCS_QUANTITY
  4251. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4252. }
  4253. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4254. {
  4255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4256. {
  4257. tempIndex = ((gun_index==2) ? 1: 0);
  4258. }
  4259. else
  4260. {
  4261. tempIndex = gun_index;
  4262. }
  4263. for (int index = 0; index < GB_QUANTITY; index++)
  4264. {
  4265. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4266. {
  4267. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4268. }
  4269. }// END OF GB_QUANTITY
  4270. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4271. }
  4272. else if(gunType[gun_index] == GUN_TYPE_DO)
  4273. {
  4274. tempIndex = gun_index;
  4275. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4276. {
  4277. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4278. {
  4279. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4280. }
  4281. }
  4282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4283. }
  4284. else
  4285. {
  4286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4287. {
  4288. tempIndex = 2;
  4289. }
  4290. else
  4291. {
  4292. tempIndex = gun_index;
  4293. }
  4294. for (int index = 0; index < AC_QUANTITY; index++)
  4295. {
  4296. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4297. {
  4298. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4299. }
  4300. }// END OF AC_QUANTITY
  4301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4302. }
  4303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4308. }
  4309. //=================================== Power.Active.Import ==================================================
  4310. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4311. {
  4312. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4313. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4314. {
  4315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4316. {
  4317. tempIndex = ((gun_index==2) ? 1: 0);
  4318. }
  4319. else
  4320. {
  4321. tempIndex = gun_index;
  4322. }
  4323. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4324. {
  4325. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4326. {
  4327. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4328. }
  4329. } // End for CHAdeMO_QUANTITY
  4330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4331. }
  4332. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4333. {
  4334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4335. {
  4336. tempIndex = ((gun_index==2) ? 1: 0);
  4337. }
  4338. else
  4339. {
  4340. tempIndex = gun_index;
  4341. }
  4342. for (int index = 0; index < CCS_QUANTITY; index++)
  4343. {
  4344. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4345. {
  4346. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4347. }
  4348. } // END for CCS_QUANTITY
  4349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4350. }
  4351. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4352. {
  4353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4354. {
  4355. tempIndex = ((gun_index==2) ? 1: 0);
  4356. }
  4357. else
  4358. {
  4359. tempIndex = gun_index;
  4360. }
  4361. for (int index = 0; index < GB_QUANTITY; index++)
  4362. {
  4363. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4364. {
  4365. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4366. }
  4367. }// END for GB_QUANTITY
  4368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4369. }
  4370. else if(gunType[gun_index] == GUN_TYPE_DO)
  4371. {
  4372. tempIndex = gun_index;
  4373. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4374. {
  4375. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4376. {
  4377. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4378. }
  4379. }
  4380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4381. }
  4382. else
  4383. {
  4384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4385. {
  4386. tempIndex = 2;
  4387. }
  4388. else
  4389. {
  4390. tempIndex = gun_index;
  4391. }
  4392. for (int index = 0; index < AC_QUANTITY; index++)
  4393. {
  4394. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4395. {
  4396. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4397. }
  4398. } // END for AC_QUANTITY
  4399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4400. }
  4401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4406. }
  4407. //============================ Voltage L1 ====================================
  4408. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4409. {
  4410. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4411. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4412. {
  4413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4414. {
  4415. tempIndex = ((gun_index==2) ? 1: 0);
  4416. }
  4417. else
  4418. {
  4419. tempIndex = gun_index;
  4420. }
  4421. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4422. {
  4423. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4424. {
  4425. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4426. }
  4427. } // END OF FOR CHAdeMO_QUANTITY
  4428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4429. }
  4430. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4431. {
  4432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4433. {
  4434. tempIndex = ((gun_index==2) ? 1: 0);
  4435. }
  4436. else
  4437. {
  4438. tempIndex = gun_index;
  4439. }
  4440. for (int index = 0; index < CCS_QUANTITY; index++)
  4441. {
  4442. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4443. {
  4444. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4445. }
  4446. } // END OF FOR CCS_QUANTITY
  4447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4448. }
  4449. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4450. {
  4451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4452. {
  4453. tempIndex = ((gun_index==2) ? 1: 0);
  4454. }
  4455. else
  4456. {
  4457. tempIndex = gun_index;
  4458. }
  4459. for (int index = 0; index < GB_QUANTITY; index++)
  4460. {
  4461. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4462. {
  4463. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4464. }
  4465. } // END OF FOR GB_QUANTITY
  4466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4467. }
  4468. else if(gunType[gun_index] == GUN_TYPE_DO)
  4469. {
  4470. tempIndex = gun_index;
  4471. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4472. {
  4473. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4474. {
  4475. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4476. }
  4477. }
  4478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4479. }
  4480. else
  4481. {
  4482. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4483. {
  4484. tempIndex = 2;
  4485. }
  4486. else
  4487. {
  4488. tempIndex = gun_index;
  4489. }
  4490. for (int index = 0; index < AC_QUANTITY; index++)
  4491. {
  4492. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4493. {
  4494. 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
  4495. }
  4496. } // END OF FOR AC_QUANTITY
  4497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4498. }
  4499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4504. }
  4505. //====================== End SoC ================================
  4506. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4507. {
  4508. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4509. 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))
  4510. {
  4511. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4512. {
  4513. tempIndex = ((gun_index==2) ? 1: 0);
  4514. }
  4515. else
  4516. {
  4517. tempIndex = gun_index;
  4518. }
  4519. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4520. {
  4521. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4522. {
  4523. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4524. {
  4525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4526. }
  4527. }
  4528. }
  4529. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4530. {
  4531. for (int index = 0; index < CCS_QUANTITY; index++)
  4532. {
  4533. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4534. {
  4535. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4536. }
  4537. }
  4538. }
  4539. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4540. {
  4541. for (int index = 0; index < GB_QUANTITY; index++)
  4542. {
  4543. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4544. {
  4545. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4546. }
  4547. }
  4548. }
  4549. else if(gunType[gun_index] == GUN_TYPE_DO)
  4550. {
  4551. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4552. {
  4553. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4554. {
  4555. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4556. }
  4557. }
  4558. }
  4559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4565. } // END FOR DC CASE
  4566. }
  4567. // ================================= Current.Import L2 ===============================================
  4568. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4569. {
  4570. // AC 3 phse L2 current
  4571. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4572. {
  4573. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4574. {
  4575. tempIndex = 2;
  4576. }
  4577. else
  4578. {
  4579. tempIndex = gun_index;
  4580. }
  4581. for (int index = 0; index < AC_QUANTITY; index++)
  4582. {
  4583. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4584. {
  4585. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4586. }
  4587. }// End of for AC_QUANTITY
  4588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4589. }
  4590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4595. }
  4596. // ================================= Current.Import L3 ===============================================
  4597. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4598. {
  4599. // AC 3 phse L3 current
  4600. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4601. {
  4602. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4603. {
  4604. tempIndex = 2;
  4605. }
  4606. else
  4607. {
  4608. tempIndex = gun_index;
  4609. }
  4610. for (int index = 0; index < AC_QUANTITY; index++)
  4611. {
  4612. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4613. {
  4614. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4615. }
  4616. }// End of for AC_QUANTITY
  4617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4618. }
  4619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4623. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4624. }
  4625. //============================ Voltage L2 ====================================
  4626. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4627. {
  4628. // AC 3 phse L2 voltage
  4629. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4630. {
  4631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4632. {
  4633. tempIndex = 2;
  4634. }
  4635. else
  4636. {
  4637. tempIndex = gun_index;
  4638. }
  4639. for (int index = 0; index < AC_QUANTITY; index++)
  4640. {
  4641. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4642. {
  4643. 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
  4644. }
  4645. } // END OF FOR AC_QUANTITY
  4646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4647. }
  4648. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4649. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4650. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4652. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4653. }
  4654. //============================ Voltage L3 ====================================
  4655. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4656. {
  4657. // AC 3 phse L3 voltage
  4658. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4659. {
  4660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4661. {
  4662. tempIndex = 2;
  4663. }
  4664. else
  4665. {
  4666. tempIndex = gun_index;
  4667. }
  4668. for (int index = 0; index < AC_QUANTITY; index++)
  4669. {
  4670. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4671. {
  4672. 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
  4673. }
  4674. } // END OF FOR AC_QUANTITY
  4675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4676. }
  4677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4682. }
  4683. //====================== Start SoC ================================
  4684. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4685. {
  4686. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4687. 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))
  4688. {
  4689. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4690. {
  4691. tempIndex = ((gun_index==2) ? 1: 0);
  4692. }
  4693. else
  4694. {
  4695. tempIndex = gun_index;
  4696. }
  4697. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4698. {
  4699. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4700. {
  4701. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4702. {
  4703. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4704. }
  4705. }
  4706. }
  4707. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4708. {
  4709. for (int index = 0; index < CCS_QUANTITY; index++)
  4710. {
  4711. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4712. {
  4713. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4714. }
  4715. }
  4716. }
  4717. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4718. {
  4719. for (int index = 0; index < GB_QUANTITY; index++)
  4720. {
  4721. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4722. {
  4723. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4724. }
  4725. }
  4726. }
  4727. else if(gunType[gun_index] == GUN_TYPE_DO)
  4728. {
  4729. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4730. {
  4731. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4732. {
  4733. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4734. }
  4735. }
  4736. }
  4737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4743. } // END FOR DC CASE
  4744. }
  4745. //================================================ Message create ====================================================
  4746. json_object *StopTransaction = json_object_new_object();
  4747. json_object *transactionDatas = json_object_new_array();
  4748. json_object *sampledValues = json_object_new_array();
  4749. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4750. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4751. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4752. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4753. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4754. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4755. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4756. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4757. {
  4758. json_object *transactionData = json_object_new_object();
  4759. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4760. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4761. {
  4762. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4763. {
  4764. json_object *sampledValue = json_object_new_object();
  4765. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4766. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4767. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4768. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4769. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4770. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4771. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4772. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4773. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4774. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4775. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4776. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4777. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4778. json_object_array_add(sampledValues, sampledValue);
  4779. }
  4780. }
  4781. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4782. json_object_array_add(transactionDatas, transactionData);
  4783. }
  4784. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4785. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4786. ,MESSAGE_TYPE_CALL
  4787. ,guid
  4788. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4789. json_object_put(StopTransaction);
  4790. #if 1 // for TempStopTransaction
  4791. //Delete TempStopTransaction
  4792. if((access(TempStopTransaction,F_OK))!=-1)
  4793. {
  4794. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4795. }
  4796. #endif
  4797. #if 1
  4798. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4799. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4800. {
  4801. result = PASS;
  4802. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4803. }
  4804. #endif
  4805. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4806. OCPP_insert_transaction_msg(NO, queuedata);
  4807. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4808. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4809. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4810. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4811. {
  4812. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4813. }
  4814. //for test
  4815. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4816. return result;
  4817. }
  4818. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4819. {
  4820. mtrace();
  4821. int result = FAIL;
  4822. char guid[37]={0};
  4823. char tempdata[65]={0};
  4824. int tempIndex = 0;
  4825. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4826. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4827. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4828. //set value
  4829. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4830. 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) )?
  4831. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4832. -1);
  4833. random_uuid(guid);
  4834. //UTC Date time
  4835. struct timeval tmnow;
  4836. struct tm *tm;
  4837. char buf[28];//, usec_buf[6];
  4838. gettimeofday(&tmnow, NULL);
  4839. time_t t;
  4840. t = time(NULL);
  4841. /*UTC time and date*/
  4842. tm = gmtime(&t);
  4843. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4844. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4845. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4846. //********************************(1)Current.Import L1************************************************/
  4847. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4848. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4849. (dataType == ReadingContext_Trigger))
  4850. {
  4851. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4852. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4853. {
  4854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4855. {
  4856. tempIndex = ((gun_index==2) ? 1: 0);
  4857. }
  4858. else
  4859. {
  4860. tempIndex = gun_index;
  4861. }
  4862. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4863. {
  4864. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4865. {
  4866. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4867. }
  4868. }
  4869. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4870. }
  4871. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4872. {
  4873. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4874. {
  4875. tempIndex = ((gun_index==2) ? 1: 0);
  4876. }
  4877. else
  4878. {
  4879. tempIndex = gun_index;
  4880. }
  4881. for (int index = 0; index < CCS_QUANTITY; index++)
  4882. {
  4883. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4884. {
  4885. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4886. }
  4887. }
  4888. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4889. }
  4890. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4891. {
  4892. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4893. {
  4894. tempIndex = ((gun_index==2) ? 1: 0);
  4895. }
  4896. else
  4897. {
  4898. tempIndex = gun_index;
  4899. }
  4900. for (int index = 0; index < GB_QUANTITY; index++)
  4901. {
  4902. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4903. {
  4904. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4905. }
  4906. }
  4907. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4908. }
  4909. else if(gunType[gun_index] == GUN_TYPE_DO)
  4910. {
  4911. tempIndex = gun_index;
  4912. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4913. {
  4914. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4915. {
  4916. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4917. }
  4918. }
  4919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4920. }
  4921. else
  4922. {
  4923. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4924. {
  4925. tempIndex = 2;
  4926. }
  4927. else
  4928. {
  4929. tempIndex = gun_index;
  4930. }
  4931. for (int index = 0; index < AC_QUANTITY; index++)
  4932. {
  4933. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4934. {
  4935. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4936. }
  4937. }
  4938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4939. }
  4940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4942. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4943. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4944. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4945. }
  4946. //********************************(2)Energy.Active.Import.Register ************************************************/
  4947. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4948. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4949. (dataType == ReadingContext_Trigger))
  4950. {
  4951. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4952. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4953. {
  4954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4955. {
  4956. tempIndex = ((gun_index==2) ? 1: 0);
  4957. }
  4958. else
  4959. {
  4960. tempIndex = gun_index;
  4961. }
  4962. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4963. {
  4964. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4965. {
  4966. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4967. }
  4968. }
  4969. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4970. }
  4971. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4972. {
  4973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4974. {
  4975. tempIndex = ((gun_index==2) ? 1: 0);
  4976. }
  4977. else
  4978. {
  4979. tempIndex = gun_index;
  4980. }
  4981. for (int index = 0; index < CCS_QUANTITY; index++)
  4982. {
  4983. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4984. {
  4985. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4986. }
  4987. }
  4988. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4989. }
  4990. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4991. {
  4992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4993. {
  4994. tempIndex = ((gun_index==2) ? 1: 0);
  4995. }
  4996. else
  4997. {
  4998. tempIndex = gun_index;
  4999. }
  5000. for (int index = 0; index < GB_QUANTITY; index++)
  5001. {
  5002. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5003. {
  5004. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5005. }
  5006. }
  5007. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5008. }
  5009. else if(gunType[gun_index] == GUN_TYPE_DO)
  5010. {
  5011. tempIndex = gun_index;
  5012. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5013. {
  5014. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5015. {
  5016. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5017. }
  5018. }
  5019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5020. }
  5021. else
  5022. {
  5023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5024. {
  5025. tempIndex = 2;
  5026. }
  5027. else
  5028. {
  5029. tempIndex = gun_index;
  5030. }
  5031. for (int index = 0; index < AC_QUANTITY; index++)
  5032. {
  5033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5034. {
  5035. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5036. }
  5037. }
  5038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5039. }
  5040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5042. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5044. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5045. }
  5046. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5047. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5048. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5049. (dataType == ReadingContext_Trigger))
  5050. {
  5051. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5052. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5053. {
  5054. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5055. {
  5056. tempIndex = ((gun_index==2) ? 1: 0);
  5057. }
  5058. else
  5059. {
  5060. tempIndex = gun_index;
  5061. }
  5062. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5063. {
  5064. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5065. {
  5066. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5067. }
  5068. } // END OF FOR CHAdeMO_QUANTITY
  5069. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5070. }
  5071. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5072. {
  5073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5074. {
  5075. tempIndex = ((gun_index==2) ? 1: 0);
  5076. }
  5077. else
  5078. {
  5079. tempIndex = gun_index;
  5080. }
  5081. for (int index = 0; index < CCS_QUANTITY; index++)
  5082. {
  5083. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5084. {
  5085. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5086. }
  5087. } // END OF CCS_QUANTITY
  5088. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5089. }
  5090. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5091. {
  5092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5093. {
  5094. tempIndex = ((gun_index==2) ? 1: 0);
  5095. }
  5096. else
  5097. {
  5098. tempIndex = gun_index;
  5099. }
  5100. for (int index = 0; index < GB_QUANTITY; index++)
  5101. {
  5102. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5103. {
  5104. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5105. }
  5106. } // END OF GB_QUANTITY
  5107. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5108. }
  5109. else if(gunType[gun_index] == GUN_TYPE_DO)
  5110. {
  5111. tempIndex = gun_index;
  5112. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5113. {
  5114. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5115. {
  5116. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5117. }
  5118. }
  5119. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5120. }
  5121. else
  5122. {
  5123. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5124. {
  5125. tempIndex = 2;
  5126. }
  5127. else
  5128. {
  5129. tempIndex = gun_index;
  5130. }
  5131. for (int index = 0; index < AC_QUANTITY; index++)
  5132. {
  5133. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5134. {
  5135. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5136. }
  5137. }
  5138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5139. }
  5140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5142. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5143. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5144. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5145. }
  5146. //********************************(4)Power.Active.Import************************************************/
  5147. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5148. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5149. (dataType == ReadingContext_Trigger))
  5150. {
  5151. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5152. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5153. {
  5154. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5155. {
  5156. tempIndex = ((gun_index==2) ? 1: 0);
  5157. }
  5158. else
  5159. {
  5160. tempIndex = gun_index;
  5161. }
  5162. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5163. {
  5164. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5165. {
  5166. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5167. }
  5168. } // END OF FOR
  5169. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5170. }
  5171. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5172. {
  5173. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5174. {
  5175. tempIndex = ((gun_index==2) ? 1: 0);
  5176. }
  5177. else
  5178. {
  5179. tempIndex = gun_index;
  5180. }
  5181. for (int index = 0; index < CCS_QUANTITY; index++)
  5182. {
  5183. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5184. {
  5185. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5186. }
  5187. }
  5188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5189. }
  5190. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5191. {
  5192. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5193. {
  5194. tempIndex = ((gun_index==2) ? 1: 0);
  5195. }
  5196. else
  5197. {
  5198. tempIndex = gun_index;
  5199. }
  5200. for (int index = 0; index < GB_QUANTITY; index++)
  5201. {
  5202. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5203. {
  5204. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5205. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5206. }
  5207. }
  5208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5209. }
  5210. else if(gunType[gun_index] == GUN_TYPE_DO)
  5211. {
  5212. tempIndex = gun_index;
  5213. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5214. {
  5215. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5216. {
  5217. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5218. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5219. }
  5220. }
  5221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5222. }
  5223. else
  5224. {
  5225. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5226. {
  5227. tempIndex = 2;
  5228. }
  5229. else
  5230. {
  5231. tempIndex = gun_index;
  5232. }
  5233. for (int index = 0; index < AC_QUANTITY; index++)
  5234. {
  5235. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5236. {
  5237. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5238. }
  5239. }
  5240. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5241. }
  5242. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5243. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5244. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5245. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5247. }
  5248. //***********************************************(5)VOLTAGE L1******************************************************/
  5249. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5250. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5251. (dataType == ReadingContext_Trigger))
  5252. {
  5253. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5254. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5255. {
  5256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5257. {
  5258. tempIndex = ((gun_index==2) ? 1: 0);
  5259. }
  5260. else
  5261. {
  5262. tempIndex = gun_index;
  5263. }
  5264. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5265. {
  5266. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5267. {
  5268. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5269. }
  5270. }
  5271. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5272. }
  5273. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5274. {
  5275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5276. {
  5277. tempIndex = ((gun_index==2) ? 1: 0);
  5278. }
  5279. else
  5280. {
  5281. tempIndex = gun_index;
  5282. }
  5283. for (int index = 0; index < CCS_QUANTITY; index++)
  5284. {
  5285. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5286. {
  5287. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5288. }
  5289. }
  5290. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5291. }
  5292. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5293. {
  5294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5295. {
  5296. tempIndex = ((gun_index==2) ? 1: 0);
  5297. }
  5298. else
  5299. {
  5300. tempIndex = gun_index;
  5301. }
  5302. for (int index = 0; index < GB_QUANTITY; index++)
  5303. {
  5304. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5305. {
  5306. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5307. }
  5308. }
  5309. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5310. }
  5311. else if(gunType[gun_index] == GUN_TYPE_DO)
  5312. {
  5313. tempIndex = gun_index;
  5314. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5315. {
  5316. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5317. {
  5318. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5319. }
  5320. }
  5321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5322. }
  5323. else
  5324. {
  5325. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5326. {
  5327. tempIndex = 2;
  5328. }
  5329. else
  5330. {
  5331. tempIndex = gun_index;
  5332. }
  5333. for (int index = 0; index < AC_QUANTITY; index++)
  5334. {
  5335. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5336. {
  5337. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5338. }
  5339. }
  5340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5341. }
  5342. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5343. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5344. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5345. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5346. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5347. }
  5348. //***********************************************(6)SOC******************************************************/
  5349. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5350. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5351. (dataType == ReadingContext_Trigger))
  5352. {
  5353. 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))
  5354. {
  5355. //idx_sample=5;
  5356. //sampledValue = NULL;
  5357. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5358. {
  5359. tempIndex = ((gun_index==2) ? 1: 0);
  5360. }
  5361. else
  5362. {
  5363. tempIndex = gun_index;
  5364. }
  5365. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5366. {
  5367. //tempIndex = ((gun_index==2) ? 1: 0);
  5368. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5369. {
  5370. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5371. {
  5372. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5373. }
  5374. }
  5375. }
  5376. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5377. {
  5378. //tempIndex = ((gun_index==2) ? 1: 0);
  5379. for (int index = 0; index < CCS_QUANTITY; index++)
  5380. {
  5381. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5382. {
  5383. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5384. }
  5385. }
  5386. }
  5387. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5388. {
  5389. //tempIndex = ((gun_index==2) ? 1: 0);
  5390. for (int index = 0; index < GB_QUANTITY; index++)
  5391. {
  5392. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5393. {
  5394. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5395. }
  5396. }
  5397. }
  5398. else if(gunType[gun_index] == GUN_TYPE_DO)
  5399. {
  5400. //tempIndex = ((gun_index==2) ? 1: 0);
  5401. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5402. {
  5403. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5404. {
  5405. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5406. }
  5407. }
  5408. }
  5409. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5410. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5411. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5412. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5413. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5415. }
  5416. }
  5417. //********************************(7)Current.Import L2************************************************/
  5418. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5419. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5420. (dataType == ReadingContext_Trigger))
  5421. {
  5422. // Only for AC 3 phase
  5423. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5424. {
  5425. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5426. {
  5427. tempIndex = 2;
  5428. }
  5429. else
  5430. {
  5431. tempIndex = gun_index;
  5432. }
  5433. for (int index = 0; index < AC_QUANTITY; index++)
  5434. {
  5435. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5436. {
  5437. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5438. }
  5439. }
  5440. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5441. }
  5442. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5447. }
  5448. //********************************(8)Current.Import L3************************************************/
  5449. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5450. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5451. (dataType == ReadingContext_Trigger))
  5452. {
  5453. // Only for AC 3 phase
  5454. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5455. {
  5456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5457. {
  5458. tempIndex = 2;
  5459. }
  5460. else
  5461. {
  5462. tempIndex = gun_index;
  5463. }
  5464. for (int index = 0; index < AC_QUANTITY; index++)
  5465. {
  5466. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5467. {
  5468. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5469. }
  5470. }
  5471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5472. }
  5473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5474. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5475. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5476. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5478. }
  5479. //***********************************************(9)VOLTAGE L2******************************************************/
  5480. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5481. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5482. (dataType == ReadingContext_Trigger))
  5483. {
  5484. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5485. {
  5486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5487. {
  5488. tempIndex = 2;
  5489. }
  5490. else
  5491. {
  5492. tempIndex = gun_index;
  5493. }
  5494. for (int index = 0; index < AC_QUANTITY; index++)
  5495. {
  5496. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5497. {
  5498. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5499. }
  5500. }
  5501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5502. }
  5503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5508. }
  5509. //***********************************************(10)VOLTAGE L3******************************************************/
  5510. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5511. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5512. (dataType == ReadingContext_Trigger))
  5513. {
  5514. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5515. {
  5516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5517. {
  5518. tempIndex = 2;
  5519. }
  5520. else
  5521. {
  5522. tempIndex = gun_index;
  5523. }
  5524. for (int index = 0; index < AC_QUANTITY; index++)
  5525. {
  5526. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5527. {
  5528. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5529. }
  5530. }
  5531. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5532. }
  5533. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5535. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5537. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5538. }
  5539. // Message create ====================================================================================================
  5540. if(TRUE)
  5541. {
  5542. json_object *MeterValueReq = json_object_new_object();
  5543. json_object *MeterValues = json_object_new_array();
  5544. json_object *sampledValues = json_object_new_array();
  5545. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5546. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5547. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5548. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5549. {
  5550. json_object *MeterValue = json_object_new_object();
  5551. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5552. {
  5553. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5554. {
  5555. json_object *sampledValue = json_object_new_object();
  5556. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5557. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5558. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5559. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5560. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5561. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5562. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5563. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5564. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5565. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5566. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5567. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5568. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5569. json_object_array_add(sampledValues, sampledValue);
  5570. }
  5571. }
  5572. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5573. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5574. json_object_array_add(MeterValues, MeterValue);
  5575. }
  5576. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5577. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5578. ,gun_index + 1
  5579. ,MESSAGE_TYPE_CALL
  5580. ,guid
  5581. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5582. json_object_put(MeterValueReq);
  5583. }
  5584. // Put request guid to hash map
  5585. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5586. 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*/)
  5587. {
  5588. result = PASS;
  5589. //DEBUG_INFO("MeterValues mapitem pass\n");
  5590. }
  5591. if((dataType != ReadingContext_Trigger) &&
  5592. (dataType != ReadingContext_Sample_Clock) &&
  5593. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5594. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5595. else
  5596. {
  5597. if(FirstHeartBeat)
  5598. LWS_Send(queuedata +2);
  5599. }
  5600. return result;
  5601. }
  5602. int sendLogStatusNotificationRequest(char *status)
  5603. {
  5604. mtrace();
  5605. int result = PASS;
  5606. char message[4096]={0};
  5607. char guid[37]={0};
  5608. char tempdata[128]={0};
  5609. json_object *LogStatusNotification = json_object_new_object();
  5610. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5611. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5612. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5613. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5614. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5615. random_uuid(guid);
  5616. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5617. json_object_put(LogStatusNotification);
  5618. LWS_Send(message);
  5619. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5620. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5621. {
  5622. result = PASS;
  5623. }
  5624. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5625. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5626. return result;
  5627. }
  5628. int sendSecurityEventNotificationRequest()
  5629. {
  5630. mtrace();
  5631. int result = PASS;
  5632. char message[4096]={0};
  5633. char guid[37]={0};
  5634. char tempdata[128]={0};
  5635. json_object *SecurityEventNotification = json_object_new_object();
  5636. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5637. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5638. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5639. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5640. random_uuid(guid);
  5641. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5642. json_object_put(SecurityEventNotification);
  5643. LWS_Send(message);
  5644. sprintf(tempdata, "SecurityEventNotification,0");
  5645. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5646. {
  5647. result = PASS;
  5648. }
  5649. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5650. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5651. return result;
  5652. }
  5653. int sendSignCertificateRequest()
  5654. {
  5655. mtrace();
  5656. int result = PASS;
  5657. char message[4096]={0};
  5658. char guid[37]={0};
  5659. char tempdata[128]={0};
  5660. json_object *SignCertificate = json_object_new_object();
  5661. DEBUG_INFO("sendSignCertificateRequest...\n");
  5662. // Read csr file content
  5663. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5664. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5665. char *line = NULL;
  5666. size_t len = 0;
  5667. while(getline(&line, &len, fp) != -1)
  5668. {
  5669. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5670. {
  5671. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5672. }
  5673. }
  5674. fclose(fp);
  5675. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5676. random_uuid(guid);
  5677. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5678. json_object_put(SignCertificate);
  5679. LWS_Send(message);
  5680. sprintf(tempdata, "SignCertificate,0");
  5681. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5682. {
  5683. result = PASS;
  5684. }
  5685. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5686. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5687. return result;
  5688. }
  5689. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5690. {
  5691. mtrace();
  5692. int result = PASS;
  5693. char message[110]={0};
  5694. char guid[37]={0};
  5695. char tempdata[65]={0};
  5696. json_object *FirmwareStatusNotification = json_object_new_object();
  5697. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5698. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5699. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5700. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5701. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5702. random_uuid(guid);
  5703. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5704. json_object_put(FirmwareStatusNotification);
  5705. LWS_Send(message);
  5706. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5707. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5708. {
  5709. result = PASS;
  5710. }
  5711. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5712. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5713. return result;
  5714. }
  5715. //==========================================
  5716. // send confirm routine
  5717. //==========================================
  5718. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5719. {
  5720. mtrace();
  5721. int result = FAIL;
  5722. char message[100]={0};
  5723. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5724. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5725. LWS_Send(message);
  5726. result = TRUE;
  5727. return result;
  5728. }
  5729. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5730. {
  5731. mtrace();
  5732. int result = FAIL;
  5733. char message[100]={0};
  5734. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5735. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5736. LWS_Send(message);
  5737. result = TRUE;
  5738. return result;
  5739. }
  5740. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5741. {
  5742. mtrace();
  5743. int result = FAIL;
  5744. char message[100]={0};
  5745. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5746. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5747. LWS_Send(message);
  5748. result = TRUE;
  5749. return result;
  5750. }
  5751. int sendClearCacheConfirmation(char *uuid,char *payload)
  5752. {
  5753. mtrace();
  5754. int result = FAIL;
  5755. char message[500]={0};
  5756. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5757. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5758. LWS_Send(message);
  5759. return result;
  5760. }
  5761. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5762. {
  5763. mtrace();
  5764. int result = FAIL;
  5765. char message[500]={0};
  5766. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5767. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5768. LWS_Send(message);
  5769. return result;
  5770. }
  5771. int sendDataTransferConfirmation(char *uuid,char *payload)
  5772. {
  5773. mtrace();
  5774. char statusStr[20]={0};
  5775. char dataStr[10]={0};
  5776. char sstr[20]={0};
  5777. int c = 0;
  5778. char *loc;
  5779. int result = FAIL;
  5780. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5781. /**********************status**************************/
  5782. loc = strstr(payload, "status");
  5783. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5784. c = 0;
  5785. while (loc[3+strlen("status")+c] != '\"')
  5786. {
  5787. sstr[c] = loc[3+strlen("status")+c];
  5788. c++;
  5789. }
  5790. sstr[c] = '\0';
  5791. strcpy(statusStr, sstr);
  5792. /**********************data**************************/
  5793. loc = strstr(payload, "data");
  5794. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5795. c = 0;
  5796. while (loc[3+strlen("data")+c] != '\"')
  5797. {
  5798. sstr[c] = loc[3+strlen("data")+c];
  5799. c++;
  5800. }
  5801. sstr[c] = '\0';
  5802. strcpy(dataStr, sstr);
  5803. return result;
  5804. }
  5805. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5806. {
  5807. mtrace();
  5808. int result = FAIL;
  5809. char message[1000]={0};
  5810. int CompositeScheduleIndex = 0;
  5811. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5812. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5813. if(nPeriod == 0)
  5814. {
  5815. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5816. {
  5817. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5818. ,MESSAGE_TYPE_CALLRESULT
  5819. ,uuid
  5820. ,payload
  5821. ,connectorIdInt);
  5822. }
  5823. else
  5824. {
  5825. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5826. ,MESSAGE_TYPE_CALLRESULT
  5827. ,uuid
  5828. ,payload
  5829. ,connectorIdInt
  5830. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5831. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5832. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5833. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5834. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5835. }
  5836. }
  5837. else
  5838. {
  5839. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5840. ,MESSAGE_TYPE_CALLRESULT
  5841. ,uuid
  5842. ,payload
  5843. ,connectorIdInt
  5844. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5845. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5846. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5847. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5848. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5849. {
  5850. if (idx_sample == 0)
  5851. {
  5852. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5853. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5854. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5855. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5856. }
  5857. else
  5858. {
  5859. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5860. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5861. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5862. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5863. }
  5864. }
  5865. sprintf(message + strlen(message), "]}}]");
  5866. }
  5867. LWS_Send(message);
  5868. result = TRUE;
  5869. return result;
  5870. }
  5871. int sendGetConfigurationConfirmation(char *uuid)
  5872. {
  5873. mtrace();
  5874. int result = FAIL;
  5875. int MaxKeySupported = 0;
  5876. int sentConfigurationNumber= 0;
  5877. int sentunConfigurationNumber= 0;
  5878. char message[4000]={0};
  5879. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5880. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5881. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5882. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5883. ,MESSAGE_TYPE_CALLRESULT
  5884. ,uuid );
  5885. //configuration key
  5886. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5887. {
  5888. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5889. {
  5890. if (sentConfigurationNumber == 0)
  5891. {
  5892. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5893. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5894. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5895. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5896. }
  5897. else
  5898. {
  5899. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5900. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5901. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5902. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5903. }
  5904. sentConfigurationNumber = sentConfigurationNumber + 1;
  5905. }
  5906. }
  5907. sprintf(message + strlen(message), "]");
  5908. if(UnknownKeynum != 0)
  5909. {
  5910. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5911. //unkown key
  5912. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5913. {
  5914. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5915. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5916. if(sentunConfigurationNumber == 0)
  5917. {
  5918. sprintf(message + strlen(message), "\"%s\""
  5919. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5920. }
  5921. else
  5922. {
  5923. sprintf(message + strlen(message), ",\"%s\""
  5924. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5925. }
  5926. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5927. }
  5928. sprintf(message + strlen(message), "]");
  5929. }
  5930. sprintf(message + strlen(message), "}]");
  5931. LWS_Send(message);
  5932. return result;
  5933. }
  5934. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5935. {
  5936. mtrace();
  5937. int result = FAIL;
  5938. char message[400]={0};
  5939. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5940. if(strcmp(payload,"")==0)
  5941. {
  5942. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5943. }
  5944. else
  5945. {
  5946. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5947. }
  5948. LWS_Send(message);
  5949. result = TRUE;
  5950. return result;
  5951. }
  5952. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5953. {
  5954. mtrace();
  5955. int result = FAIL;
  5956. char message[80]={0};
  5957. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5958. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5959. LWS_Send(message);
  5960. result = TRUE;
  5961. return result;
  5962. }
  5963. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5964. {
  5965. mtrace();
  5966. int result = FAIL;
  5967. char message[80]={0};
  5968. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5969. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5970. LWS_Send(message);
  5971. result = TRUE;
  5972. return result;
  5973. }
  5974. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5975. {
  5976. mtrace();
  5977. int result = FAIL;
  5978. char message[80]={0};
  5979. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5980. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5981. LWS_Send(message);
  5982. result = TRUE;
  5983. return result;
  5984. }
  5985. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5986. {
  5987. mtrace();
  5988. int result = FAIL;
  5989. char message[80]={0};
  5990. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5991. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5992. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5993. LWS_Send(message);
  5994. result = TRUE;
  5995. return result;
  5996. }
  5997. int sendResetConfirmation(char *uuid,char *payload)
  5998. {
  5999. mtrace();
  6000. int result = FAIL;
  6001. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6002. char message[80]={0};
  6003. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6004. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6005. LWS_Send(message);
  6006. result = TRUE;
  6007. return result;
  6008. }
  6009. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6010. {
  6011. mtrace();
  6012. int result = FAIL;
  6013. char message[500]={0};
  6014. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6015. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6016. LWS_Send(message);
  6017. result = TRUE;
  6018. return result;
  6019. }
  6020. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6021. {
  6022. mtrace();
  6023. int result = FAIL;
  6024. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6025. char message[80]={0};
  6026. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6027. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6028. LWS_Send(message);
  6029. result = TRUE;
  6030. return result;
  6031. }
  6032. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6033. {
  6034. mtrace();
  6035. int result = FAIL;
  6036. char message[80]={0};
  6037. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6038. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6039. LWS_Send(message);
  6040. result = TRUE;
  6041. return result;
  6042. }
  6043. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6044. {
  6045. mtrace();
  6046. int result = FAIL;
  6047. char message[80]={0};
  6048. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6049. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6050. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6051. LWS_Send(message);
  6052. result = TRUE;
  6053. return result;
  6054. }
  6055. int sendUpdateFirmwareConfirmation(char *uuid)
  6056. {
  6057. mtrace();
  6058. int result = FAIL;
  6059. char message[60]={0};
  6060. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6061. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6062. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6063. LWS_Send(message);
  6064. result = TRUE;
  6065. return result;
  6066. }
  6067. int sendCertificateSignedConfirmation(char *uuid)
  6068. {
  6069. mtrace();
  6070. int result = PASS;
  6071. char message[4096]={0};
  6072. json_object *CertificateSigned = json_object_new_object();
  6073. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6074. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6075. sprintf(message,"[%d,\"%s\",%s]"
  6076. ,MESSAGE_TYPE_CALLRESULT
  6077. ,uuid
  6078. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6079. json_object_put(CertificateSigned);
  6080. LWS_Send(message);
  6081. return result;
  6082. }
  6083. int sendDeleteCertificateConfirmation(char *uuid)
  6084. {
  6085. mtrace();
  6086. int result = PASS;
  6087. char message[4096]={0};
  6088. json_object *DeleteCertificate = json_object_new_object();
  6089. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6090. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6091. sprintf(message,"[%d,\"%s\",%s]"
  6092. ,MESSAGE_TYPE_CALLRESULT
  6093. ,uuid
  6094. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6095. json_object_put(DeleteCertificate);
  6096. LWS_Send(message);
  6097. return result;
  6098. }
  6099. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6100. {
  6101. mtrace();
  6102. int result = PASS;
  6103. char message[4096]={0};
  6104. json_object *ExtendedTriggerMessage = json_object_new_object();
  6105. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6106. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6107. sprintf(message,"[%d,\"%s\",%s]"
  6108. ,MESSAGE_TYPE_CALLRESULT
  6109. ,uuid
  6110. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6111. json_object_put(ExtendedTriggerMessage);
  6112. LWS_Send(message);
  6113. return result;
  6114. }
  6115. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6116. {
  6117. mtrace();
  6118. int result = PASS;
  6119. char message[4096]={0};
  6120. json_object *GetInstalledCertificateIds = json_object_new_object();
  6121. json_object *certificateHashDataDatas = json_object_new_array();
  6122. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6123. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6124. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6125. {
  6126. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6127. {
  6128. json_object *certificateHashData = json_object_new_object();
  6129. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6130. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6131. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6132. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6133. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6134. }
  6135. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6136. }
  6137. else
  6138. {
  6139. json_object_put(certificateHashDataDatas);
  6140. }
  6141. sprintf(message,"[%d,\"%s\",%s]"
  6142. ,MESSAGE_TYPE_CALLRESULT
  6143. ,uuid
  6144. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6145. json_object_put(GetInstalledCertificateIds);
  6146. LWS_Send(message);
  6147. return result;
  6148. }
  6149. int sendGetLogConfirmation(char *uuid)
  6150. {
  6151. mtrace();
  6152. int result = PASS;
  6153. char message[4096]={0};
  6154. json_object *GetLog = json_object_new_object();
  6155. DEBUG_INFO("sendGetLogConfirmation...\n");
  6156. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6157. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6158. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6159. sprintf(message,"[%d,\"%s\",%s]"
  6160. ,MESSAGE_TYPE_CALLRESULT
  6161. ,uuid
  6162. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6163. json_object_put(GetLog);
  6164. LWS_Send(message);
  6165. return result;
  6166. }
  6167. int sendInstallCertificateConfirmation(char *uuid)
  6168. {
  6169. mtrace();
  6170. int result = PASS;
  6171. char message[4096]={0};
  6172. json_object *InstallCertificate = json_object_new_object();
  6173. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6174. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6175. sprintf(message,"[%d,\"%s\",%s]"
  6176. ,MESSAGE_TYPE_CALLRESULT
  6177. ,uuid
  6178. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6179. json_object_put(InstallCertificate);
  6180. LWS_Send(message);
  6181. return result;
  6182. }
  6183. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6184. {
  6185. mtrace();
  6186. int result = PASS;
  6187. char message[4096]={0};
  6188. json_object *SignedUpdateFirmware = json_object_new_object();
  6189. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6190. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6191. sprintf(message,"[%d,\"%s\",%s]"
  6192. ,MESSAGE_TYPE_CALLRESULT
  6193. ,uuid
  6194. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6195. json_object_put(SignedUpdateFirmware);
  6196. LWS_Send(message);
  6197. return result;
  6198. }
  6199. int sendUnknownConfirmation(char *uuid)
  6200. {
  6201. mtrace();
  6202. int result = PASS;
  6203. char message[256]={0};
  6204. DEBUG_INFO("sendUnknownConfirmation...\n");
  6205. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6206. LWS_Send(message);
  6207. return result;
  6208. }
  6209. //==========================================
  6210. // Handle server request routine Start
  6211. //==========================================
  6212. int handleCancelReservationRequest(char *uuid, char *payload)
  6213. {
  6214. mtrace();
  6215. int result = FAIL;
  6216. int gunNO = 0;
  6217. int reservationIdInt = -1;
  6218. char comfirmstr[20];
  6219. DEBUG_INFO("handleCancelReservationRequest...\n");
  6220. json_object *CancelReservation;
  6221. CancelReservation = json_tokener_parse(payload);
  6222. if(!is_error(CancelReservation))
  6223. {
  6224. // Required data
  6225. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6226. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6227. }
  6228. json_object_put(CancelReservation);
  6229. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6230. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6231. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6232. if(reservationIdInt != -1)
  6233. {
  6234. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6235. //check Transaction active
  6236. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6237. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6238. {
  6239. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6240. {
  6241. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6242. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6243. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6244. {
  6245. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6246. }
  6247. else
  6248. {
  6249. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6250. }
  6251. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6252. goto end;
  6253. }
  6254. }
  6255. for (int index = 0; index < CCS_QUANTITY; index++)
  6256. {
  6257. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6258. {
  6259. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6260. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6261. if(gunType[2] == GUN_TYPE_CCS)
  6262. {
  6263. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6264. }
  6265. else
  6266. {
  6267. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6268. }
  6269. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6270. goto end;
  6271. }
  6272. }
  6273. for (int index = 0; index < GB_QUANTITY; index++)
  6274. {
  6275. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6276. {
  6277. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6278. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6279. if(gunType[2] == GUN_TYPE_GBT)
  6280. {
  6281. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6282. }
  6283. else
  6284. {
  6285. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6286. }
  6287. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6288. goto end;
  6289. }
  6290. }
  6291. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6292. {
  6293. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6294. {
  6295. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6296. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6297. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6298. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6299. goto end;
  6300. }
  6301. }
  6302. for (int index = 0; index < AC_QUANTITY; index++)
  6303. {
  6304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6305. {
  6306. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6307. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6308. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6309. {
  6310. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6311. }
  6312. else
  6313. {
  6314. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6315. }
  6316. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6317. goto end;
  6318. }
  6319. }
  6320. }
  6321. //The reservationId does NOT match the reservationId
  6322. sendCancelReservationConfirmation(uuid, comfirmstr);
  6323. end:
  6324. // Fill in ocpp packet uuid
  6325. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6326. return result;
  6327. }
  6328. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6329. {
  6330. mtrace();
  6331. int result = FAIL;
  6332. int gunIndex = 0;
  6333. char typeStr[16]={0};
  6334. char comfirmstr[20];
  6335. int specificId = FALSE;
  6336. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6337. json_object *ChangeAvailability;
  6338. ChangeAvailability = json_tokener_parse(payload);
  6339. if(!is_error(ChangeAvailability))
  6340. {
  6341. // Required data
  6342. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6343. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6344. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6345. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6346. }
  6347. json_object_put(ChangeAvailability);
  6348. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6349. {
  6350. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6351. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6352. }
  6353. else if(gunIndex == 0)
  6354. {
  6355. for(int i=0; i < gunTotalNumber; i++)
  6356. {
  6357. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6358. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6359. }
  6360. }
  6361. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6362. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6363. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6364. {
  6365. specificId = TRUE;
  6366. }
  6367. if(specificId == FALSE)
  6368. goto end;
  6369. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6370. {
  6371. //----------------------gunIndex is 0 ------------------------------------------------//
  6372. if(gunIndex == 0)
  6373. {
  6374. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6375. {
  6376. for(int i=0; i < gunTotalNumber; i++)
  6377. {
  6378. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6379. {
  6380. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6381. {
  6382. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6383. {
  6384. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6385. goto end;
  6386. }
  6387. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6388. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6389. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6390. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6391. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6392. {
  6393. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6394. goto end;
  6395. }
  6396. }
  6397. }//END FOR CHAdeMO_QUANTITY
  6398. for (int index = 0; index < CCS_QUANTITY; index++)
  6399. {
  6400. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6401. {
  6402. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6403. {
  6404. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6405. goto end;
  6406. }
  6407. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6408. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6409. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6410. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6411. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6412. {
  6413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6414. goto end;
  6415. }
  6416. }
  6417. }//END FOR CCS_QUANTITY
  6418. for (int index = 0; index < GB_QUANTITY; index++)
  6419. {
  6420. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6421. {
  6422. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6423. {
  6424. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6425. goto end;
  6426. }
  6427. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6428. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6429. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6430. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6431. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6432. {
  6433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6434. goto end;
  6435. }
  6436. }
  6437. }// END FOR GB_QUANTITY
  6438. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6439. {
  6440. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6441. {
  6442. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6443. {
  6444. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6445. goto end;
  6446. }
  6447. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6448. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6449. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6450. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6451. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6452. {
  6453. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6454. goto end;
  6455. }
  6456. }
  6457. }// END FOR GENERAL_GUN_QUANTITY
  6458. for (int index = 0; index < AC_QUANTITY; index++)
  6459. {
  6460. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6461. {
  6462. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6463. {
  6464. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6465. goto end;
  6466. }
  6467. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6468. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6469. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6470. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6471. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6472. {
  6473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6474. goto end;
  6475. }
  6476. }
  6477. }//END FOR AC_QUANTITY
  6478. }// END FOR gunTotalNumber
  6479. }
  6480. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6481. {
  6482. for(int i=0; i < gunTotalNumber; i++)
  6483. {
  6484. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6485. {
  6486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6487. goto end;
  6488. }
  6489. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6490. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6491. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6492. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6493. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6494. {
  6495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6496. goto end;
  6497. }
  6498. }
  6499. }
  6500. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6501. goto end;
  6502. }
  6503. //----------------------gunIndex is not 0 ------------------------------------------------//
  6504. //check Transaction active
  6505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6506. {
  6507. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6508. {
  6509. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6510. {
  6511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6512. goto end;
  6513. }
  6514. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6515. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6516. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6517. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6518. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6519. {
  6520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6521. goto end;
  6522. }
  6523. else
  6524. {
  6525. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6526. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6527. goto end;
  6528. }
  6529. }
  6530. }//END FOR CHAdeMO_QUANTITY
  6531. for (int index = 0; index < CCS_QUANTITY; index++)
  6532. {
  6533. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6534. {
  6535. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6536. {
  6537. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6538. goto end;
  6539. }
  6540. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6541. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6542. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6543. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6544. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6545. {
  6546. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6547. goto end;
  6548. }
  6549. else
  6550. {
  6551. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6553. goto end;
  6554. }
  6555. }
  6556. }//END FOR CCS_QUANTITY
  6557. for (int index = 0; index < GB_QUANTITY; index++)
  6558. {
  6559. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6560. {
  6561. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6562. {
  6563. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6564. goto end;
  6565. }
  6566. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6567. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6568. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6569. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6570. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6571. {
  6572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6573. goto end;
  6574. }
  6575. else
  6576. {
  6577. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6578. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6579. goto end;
  6580. }
  6581. }
  6582. }// END FOR GB_QUANTITY
  6583. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6584. {
  6585. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6586. {
  6587. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6588. {
  6589. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6590. goto end;
  6591. }
  6592. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6593. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6594. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6595. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6596. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6597. {
  6598. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6599. goto end;
  6600. }
  6601. else
  6602. {
  6603. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6605. goto end;
  6606. }
  6607. }
  6608. }// END FOR GENERAL_GUN_QUANTITY
  6609. for (int index = 0; index < AC_QUANTITY; index++)
  6610. {
  6611. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6612. {
  6613. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6614. {
  6615. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6616. goto end;
  6617. }
  6618. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6619. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6620. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6621. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6622. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6623. {
  6624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6625. goto end;
  6626. }
  6627. else
  6628. {
  6629. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6630. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6631. goto end;
  6632. }
  6633. }
  6634. }//END FOR AC_QUANTITY
  6635. }//END FOR AvailabilityTypeStr[Inoperative]
  6636. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6637. {
  6638. //----------------------gunIndex is 0 ------------------------------------------------//
  6639. if(gunIndex == 0)
  6640. {
  6641. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6642. {
  6643. for(int i=0; i < gunTotalNumber; i++)
  6644. {
  6645. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6646. {
  6647. 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
  6648. {
  6649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6650. goto end;
  6651. }
  6652. }//END FOR CHAdeMO_QUANTITY
  6653. for (int index = 0; index < CCS_QUANTITY; index++)
  6654. {
  6655. 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
  6656. {
  6657. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6658. goto end;
  6659. }
  6660. }//END FOR CCS_QUANTITY
  6661. for (int index = 0; index < GB_QUANTITY; index++)
  6662. {
  6663. 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
  6664. {
  6665. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6666. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6667. goto end;
  6668. }
  6669. }// END FOR GB_QUANTITY
  6670. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6671. {
  6672. 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
  6673. {
  6674. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6675. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6676. goto end;
  6677. }
  6678. }// END FOR GENERAL_GUN_QUANTITY
  6679. for (int index = 0; index < AC_QUANTITY; index++)
  6680. {
  6681. 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
  6682. {
  6683. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6684. goto end;
  6685. }
  6686. }//END FOR CHAdeMO_QUANTITY
  6687. }// END FOR gunTotalNumber
  6688. }
  6689. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6690. {
  6691. for(int i=0; i < gunTotalNumber; i++)
  6692. {
  6693. for (int index = 0; index < AC_QUANTITY; index++)
  6694. {
  6695. 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
  6696. {
  6697. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6698. goto end;
  6699. }
  6700. }//END FOR CHAdeMO_QUANTITY
  6701. } // END FOR gunTotalNumber
  6702. }
  6703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6704. goto end;
  6705. }
  6706. //----------------------gunIndex is not 0 ------------------------------------------------//
  6707. //check Transaction active
  6708. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6709. {
  6710. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6711. {
  6712. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6713. goto end;
  6714. }
  6715. }//END FOR CHAdeMO_QUANTITY
  6716. for (int index = 0; index < CCS_QUANTITY; index++)
  6717. {
  6718. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6719. {
  6720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6721. goto end;
  6722. }
  6723. }//END FOR CCS_QUANTITY
  6724. for (int index = 0; index < GB_QUANTITY; index++)
  6725. {
  6726. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6727. {
  6728. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6729. goto end;
  6730. }
  6731. }// END FOR GB_QUANTITY
  6732. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6733. {
  6734. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6735. {
  6736. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6737. goto end;
  6738. }
  6739. }// END FOR GENERAL_GUN_QUANTITY
  6740. for (int index = 0; index < AC_QUANTITY; index++)
  6741. {
  6742. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6743. {
  6744. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6745. goto end;
  6746. }
  6747. }//END FOR AC_QUANTITY
  6748. }//END FOR AvailabilityTypeStr[Operative]
  6749. end:
  6750. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6751. {
  6752. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6753. }
  6754. else
  6755. {
  6756. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6757. }
  6758. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6759. {
  6760. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6761. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6762. }
  6763. else if(gunIndex == 0)
  6764. {
  6765. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6766. {
  6767. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6768. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6769. }
  6770. }
  6771. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6772. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6773. return result;
  6774. }
  6775. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6776. {
  6777. mtrace();
  6778. int result = FAIL;
  6779. char keystr[40]={0};
  6780. char valuestr[256]={0};
  6781. char comfirmstr[20]={0};
  6782. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6783. json_object *ChangeConfiguration;
  6784. ChangeConfiguration = json_tokener_parse(payload);
  6785. if(!is_error(ChangeConfiguration))
  6786. {
  6787. // Required data
  6788. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6789. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6790. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6791. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6792. }
  6793. json_object_put(ChangeConfiguration);
  6794. if((uuid==NULL) || (payload ==NULL) )
  6795. {
  6796. DEBUG_ERROR("Payload is null\n");
  6797. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6798. }
  6799. else
  6800. {
  6801. int status = setKeyValue(keystr, valuestr);
  6802. switch(status)
  6803. {
  6804. case ConfigurationStatus_Accepted:
  6805. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6806. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6807. StoreConfigurationTable();
  6808. break;
  6809. case RebootRequired:
  6810. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6811. StoreConfigurationTable();
  6812. break;
  6813. case NotSupported:
  6814. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6815. break;
  6816. case ConfigurationStatus_Rejected:
  6817. default:
  6818. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6819. break;
  6820. }
  6821. }
  6822. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6823. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6824. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6825. {
  6826. ChageWebSocketPingInterval(atoi(valuestr));
  6827. }
  6828. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6829. {
  6830. SetOcppConnStatus(FALSE);
  6831. }
  6832. return result;
  6833. }
  6834. int handleClearCacheRequest(char *uuid, char *payload)
  6835. {
  6836. mtrace();
  6837. int result = FAIL;
  6838. char comfirmstr[20];
  6839. char rmFileCmd[100]={0};
  6840. struct stat stats;
  6841. DEBUG_INFO("handleClearCacheRequest...\n");
  6842. stat("/Storage/OCPP", &stats);
  6843. // Check for directory existence
  6844. if (S_ISDIR(stats.st_mode) == 1)
  6845. {}
  6846. else
  6847. {
  6848. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6849. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6850. system(rmFileCmd);
  6851. }
  6852. if(OCPP_cleanLocalCache())
  6853. {
  6854. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6855. }
  6856. else
  6857. {
  6858. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6859. }
  6860. sendClearCacheConfirmation(uuid, comfirmstr);
  6861. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6862. return result;
  6863. }
  6864. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6865. {
  6866. mtrace();
  6867. int result = FAIL;
  6868. int resultRename;
  6869. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6870. char chargingProfilePurposeStr[26]={0};
  6871. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6872. char tempchargingProfilePurposeStr[26]={0};
  6873. char str[100]={0};
  6874. char fname[200]={0};
  6875. char comfirmstr[20]={0};
  6876. char word[1600]={0};
  6877. int clearflag = FALSE;
  6878. int chargingProfileIdIsNULL = FALSE;
  6879. int connectorIsNULL = FALSE;
  6880. int chargingProfilePurposeIsNULL = FALSE;
  6881. int stackLevelIsNULL = FALSE;
  6882. //int GotoEnd = FALSE;
  6883. FILE *fptr1, *fptr2;
  6884. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6885. int n_chargingProfile=0;
  6886. int isEmptyFile = FALSE;
  6887. char sLineWord[1600]={0};
  6888. char chargingProfiles[10][100]={0};
  6889. int ChargeProfileCount = 0;
  6890. int ch;
  6891. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6892. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6893. json_object *ClearChargingProfile;
  6894. ClearChargingProfile = json_tokener_parse(payload);
  6895. if(!is_error(ClearChargingProfile))
  6896. {
  6897. // Optional data
  6898. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6899. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6900. else
  6901. chargingProfileIdIsNULL = TRUE;
  6902. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6903. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6904. else
  6905. connectorIsNULL = TRUE;
  6906. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6907. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6908. else
  6909. chargingProfilePurposeIsNULL = TRUE;
  6910. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6911. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6912. else
  6913. stackLevelIsNULL = TRUE;
  6914. }
  6915. json_object_put(ClearChargingProfile);
  6916. if(connectorIsNULL == FALSE)
  6917. {
  6918. switch(connectorIdInt)
  6919. {
  6920. case 0:
  6921. if(chargingProfilePurposeIsNULL == TRUE)
  6922. {
  6923. int l = 0;
  6924. strcpy(fname, ChargePointMaxProfile_JSON);
  6925. if((access(fname,F_OK))!=-1)
  6926. {
  6927. strcpy(chargingProfiles[l], fname);
  6928. l = l + 1;
  6929. }
  6930. strcpy(fname, TxDefaultProfile_0_JSON);
  6931. if((access(fname,F_OK))!=-1)
  6932. {
  6933. strcpy(chargingProfiles[l], fname);
  6934. l = l + 1;
  6935. }
  6936. ChargeProfileCount = l;
  6937. }
  6938. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6939. {
  6940. strcpy(fname, ChargePointMaxProfile_JSON);
  6941. if((access(fname,F_OK))!=-1)
  6942. {
  6943. strcpy(chargingProfiles[0], fname);
  6944. ChargeProfileCount = 1;
  6945. }
  6946. }
  6947. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6948. {
  6949. strcpy(fname, TxDefaultProfile_0_JSON);
  6950. if((access(fname,F_OK))!=-1)
  6951. {
  6952. strcpy(chargingProfiles[0], fname);
  6953. ChargeProfileCount = 1;
  6954. }
  6955. }
  6956. break;
  6957. default:
  6958. if(chargingProfilePurposeIsNULL == TRUE)
  6959. {
  6960. int m = 0;
  6961. memset(fname, 0, ARRAY_SIZE(fname));
  6962. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6963. if((access(fname,F_OK))!=-1)
  6964. {
  6965. strcpy(chargingProfiles[m], fname);
  6966. m = m + 1;
  6967. }
  6968. memset(fname, 0, ARRAY_SIZE(fname));
  6969. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6970. if((access(fname,F_OK))!=-1)
  6971. {
  6972. strcpy(chargingProfiles[m], fname);
  6973. m = m + 1;
  6974. }
  6975. ChargeProfileCount = m;
  6976. }
  6977. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6978. {
  6979. //strcpy(fname, TxDefaultProfile_1_JSON);
  6980. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6981. if((access(fname,F_OK))!=-1)
  6982. {
  6983. strcpy(chargingProfiles[0], fname);
  6984. ChargeProfileCount = 1;
  6985. }
  6986. }
  6987. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6988. {
  6989. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6990. if((access(fname,F_OK))!=-1)
  6991. {
  6992. strcpy(chargingProfiles[0], fname);
  6993. ChargeProfileCount = 1;
  6994. }
  6995. //strcpy(fname, TxProfile_1_JSON);
  6996. }
  6997. //strcpy(fname, ChargePointMaxProfile_JSON );
  6998. break;
  6999. }
  7000. }
  7001. else // Check all Charging Profiles
  7002. {
  7003. int i = 0;
  7004. char fnametemp[200]={0};
  7005. ChargeProfileCount = 0;
  7006. //Check ChargePointMaxProfile.json exit
  7007. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7008. {
  7009. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7010. i = i + 1;
  7011. }
  7012. //Check TxDefaultProfile_0.json exit
  7013. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7014. {
  7015. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7016. i = i + 1;
  7017. }
  7018. //Check TxDefaultProfile_%d.json
  7019. for(int j=1; j <= gunTotalNumber; j++)
  7020. {
  7021. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7022. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7023. if((access(fnametemp,F_OK))!=-1)
  7024. {
  7025. strcpy(chargingProfiles[i], fnametemp);
  7026. i = i + 1;
  7027. }
  7028. }
  7029. //Check TxProfile_%d.json
  7030. for(int j=1; j <= gunTotalNumber; j++)
  7031. {
  7032. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7033. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7034. if((access(fnametemp,F_OK))!=-1)
  7035. {
  7036. strcpy(chargingProfiles[i], fnametemp);
  7037. i = i + 1;
  7038. }
  7039. }
  7040. ChargeProfileCount = i;
  7041. }// End connectorIsNULL is TRUE
  7042. if(ChargeProfileCount == 0)
  7043. {
  7044. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7045. goto end;
  7046. }
  7047. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7048. {
  7049. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7050. goto end;
  7051. }
  7052. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7053. {
  7054. memset(str, 0, ARRAY_SIZE(str));
  7055. // clear temp file
  7056. sprintf(str,"rm -f %s",temp);
  7057. system(str);
  7058. for(int k=0; k < ChargeProfileCount; k++)
  7059. {
  7060. memset(str, 0, ARRAY_SIZE(str));
  7061. //clear file in C
  7062. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7063. system(str);
  7064. }
  7065. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7066. goto end;
  7067. }
  7068. else if(connectorIsNULL == TRUE)
  7069. {
  7070. for(int k=0; k < ChargeProfileCount; k++)
  7071. {
  7072. fptr1 = fopen(chargingProfiles[k], "r");
  7073. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7074. //Check Charging Profile Count
  7075. while(fscanf(fptr1, "%s", word) != EOF)
  7076. {
  7077. //DEBUG_INFO("word=%s\n",word);
  7078. if(strstr(word, "chargingProfileId")!= NULL)
  7079. {
  7080. //DEBUG_INFO("test chargingProfileId \n");
  7081. n_chargingProfile = n_chargingProfile + 1;
  7082. //DEBUG_INFO("chargingProfileId Found\n");
  7083. }
  7084. }
  7085. rewind(fptr1);
  7086. //search Charging Profile Element
  7087. //int i= 0;
  7088. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7089. {
  7090. json_object *tmpProfilee;
  7091. tmpProfilee = json_tokener_parse(sLineWord);
  7092. if(!is_error(tmpProfilee))
  7093. {
  7094. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7095. {
  7096. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7097. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7098. }
  7099. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7100. {
  7101. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7102. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7103. }
  7104. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7105. {
  7106. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7107. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7108. }
  7109. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7110. {
  7111. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7112. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7113. }
  7114. }
  7115. json_object_put(tmpProfilee);
  7116. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7117. {
  7118. //------- not write to fptr2-------//
  7119. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7120. //clearflag = TRUE;
  7121. }
  7122. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7123. {
  7124. //------- not write to fptr2-------//
  7125. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7126. }
  7127. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7128. {
  7129. //------- not write to fptr2-------//
  7130. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7131. }
  7132. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7133. {
  7134. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7135. }
  7136. else
  7137. {
  7138. fprintf(fptr2, sLineWord);//writing data into file
  7139. }
  7140. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7141. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7142. if(clearflag == TRUE)
  7143. {
  7144. fclose(fptr1);
  7145. fclose(fptr2);
  7146. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7147. system(str);
  7148. // clear temp file
  7149. sprintf(str,"rm -f %s",temp);
  7150. system(str);
  7151. }
  7152. else
  7153. {
  7154. fclose(fptr1);
  7155. fclose(fptr2);
  7156. memset(str, 0, ARRAY_SIZE(str));
  7157. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7158. system(str);
  7159. resultRename = rename(temp, chargingProfiles[k]);
  7160. if(resultRename == 0)
  7161. {
  7162. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7163. }
  7164. else
  7165. {
  7166. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7167. }
  7168. if(comfirmstr[0]== 0)
  7169. {
  7170. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7171. }
  7172. //Check chargingProfile is empty file
  7173. /*------ Read the file ----------------*/
  7174. fptr1=fopen(chargingProfiles[k],"r");
  7175. ch=fgetc(fptr1);
  7176. rewind(fptr1);
  7177. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7178. if(ch!=EOF)
  7179. {
  7180. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7181. {
  7182. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7183. if(sLineWord[0]=='\0')
  7184. {
  7185. isEmptyFile = TRUE;
  7186. break;
  7187. }
  7188. else
  7189. {
  7190. isEmptyFile = FALSE;
  7191. break;
  7192. }
  7193. }
  7194. }
  7195. else
  7196. isEmptyFile = TRUE;
  7197. fclose(fptr1);
  7198. if(isEmptyFile == TRUE)
  7199. {
  7200. memset(str, 0, ARRAY_SIZE(str));
  7201. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7202. system(str);
  7203. }
  7204. }
  7205. }// End of while(int k=0; k < ChargePointCount; k++)
  7206. }
  7207. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7208. {
  7209. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7210. for(int k=0; k < ChargeProfileCount; k++)
  7211. {
  7212. fptr1 = fopen(chargingProfiles[k], "r");
  7213. fptr2 = fopen(temp, "w+");
  7214. //Check Charging Profile Count
  7215. while(fscanf(fptr1, "%s", word) != EOF)
  7216. {
  7217. //DEBUG_INFO("word=%s\n",word);
  7218. if(strstr(word, "chargingProfileId")!= NULL)
  7219. {
  7220. n_chargingProfile = n_chargingProfile + 1;
  7221. }
  7222. }
  7223. rewind(fptr1);
  7224. //search Charging Profile Element
  7225. //int i= 0;
  7226. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7227. {
  7228. json_object *tmpProfilee;
  7229. tmpProfilee = json_tokener_parse(sLineWord);
  7230. if(!is_error(tmpProfilee))
  7231. {
  7232. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7233. {
  7234. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7235. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7236. }
  7237. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7238. {
  7239. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7240. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7241. }
  7242. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7243. {
  7244. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7245. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7246. }
  7247. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7248. {
  7249. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7250. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7251. }
  7252. }
  7253. json_object_put(tmpProfilee);
  7254. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7255. {
  7256. //------- not write to fptr2-------//
  7257. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7258. //clearflag = TRUE;
  7259. }
  7260. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7261. {
  7262. //------- not write to fptr2-------//
  7263. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7264. }
  7265. else if(stackLevelIsNULL == TRUE)
  7266. {
  7267. //Clear Whole File
  7268. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7269. clearflag = TRUE;
  7270. break;
  7271. }
  7272. else
  7273. {
  7274. fprintf(fptr2, sLineWord);//writing data into file
  7275. }
  7276. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7277. }
  7278. if(clearflag == TRUE)
  7279. {
  7280. fclose(fptr1);
  7281. fclose(fptr2);
  7282. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7283. system(str);
  7284. // clear temp file
  7285. sprintf(str,"rm -f %s",temp);
  7286. system(str);
  7287. }
  7288. else
  7289. {
  7290. fclose(fptr1);
  7291. fclose(fptr2);
  7292. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7293. system(str);
  7294. resultRename = rename(temp, chargingProfiles[k]);
  7295. if(resultRename == 0)
  7296. {
  7297. DEBUG_INFO("File ChargingProfile renamed successfully");
  7298. }
  7299. else
  7300. {
  7301. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7302. }
  7303. if(comfirmstr[0]== 0)
  7304. {
  7305. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7306. }
  7307. //Check chargingProfile is empty file
  7308. /*------ Read the file ----------------*/
  7309. fptr1=fopen(chargingProfiles[k],"r");
  7310. ch=fgetc(fptr1);
  7311. rewind(fptr1);
  7312. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7313. if(ch!=EOF)
  7314. {
  7315. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7316. {
  7317. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7318. if(sLineWord[0]=='\0')
  7319. {
  7320. isEmptyFile = TRUE;
  7321. break;
  7322. }
  7323. else
  7324. {
  7325. isEmptyFile = FALSE;
  7326. break;
  7327. }
  7328. }
  7329. }
  7330. else
  7331. isEmptyFile = TRUE;
  7332. fclose(fptr1);
  7333. if(isEmptyFile == TRUE)
  7334. {
  7335. memset(str, 0, ARRAY_SIZE(str));
  7336. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7337. system(str);
  7338. }
  7339. /*------- End of reading ---------------*/
  7340. }
  7341. } // while(int k=0; k < ChargeProfileCount; k++)
  7342. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7343. end:
  7344. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7345. {
  7346. if(connectorIdInt == 0)
  7347. {
  7348. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7349. {
  7350. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7351. }
  7352. }
  7353. else
  7354. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7355. }
  7356. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7357. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7358. return result;
  7359. }
  7360. void createFirmwareVersionByDataTransfer(void)
  7361. {
  7362. json_object *FirmwareDataTransfer = json_object_new_object();
  7363. // AC & DC model
  7364. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7365. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7366. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7367. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7368. // DC model
  7369. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7370. {
  7371. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7372. {
  7373. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7374. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7375. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7376. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7377. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7378. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7379. }
  7380. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7381. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7382. {
  7383. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7384. }
  7385. }
  7386. else
  7387. {
  7388. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7389. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7390. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7391. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7392. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7393. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7394. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7395. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7396. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7397. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7398. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7399. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7400. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7401. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7402. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7403. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7404. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7405. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7406. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7407. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7408. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7409. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7410. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7411. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7412. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7413. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7414. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7415. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7416. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7417. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7418. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7419. }
  7420. // 4G model
  7421. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7422. {
  7423. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7424. }
  7425. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7426. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7427. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7428. json_object_put(FirmwareDataTransfer);
  7429. }
  7430. int handleDataTransferRequest(char *uuid, char *payload)
  7431. {
  7432. mtrace();
  7433. json_object *response = json_object_new_object();
  7434. int result = FAIL;
  7435. char tempvendorId[255]={0};
  7436. char tempmessageId[50]={0};
  7437. char tempdata[512]={0};
  7438. char message[2048]={0};
  7439. DEBUG_INFO("handleDataTransferRequest...\n");
  7440. if((uuid != NULL) && (payload != NULL))
  7441. {
  7442. json_object *DataTransfer;
  7443. DataTransfer = json_tokener_parse(payload);
  7444. if(!is_error(DataTransfer))
  7445. {
  7446. // Required data
  7447. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7448. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7449. // Optional data
  7450. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7451. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7452. if(json_object_object_get(DataTransfer, "data") != NULL)
  7453. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7454. result = PASS;
  7455. }
  7456. json_object_put(DataTransfer);
  7457. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7458. {
  7459. // Send all moudle firmware version on EVSE
  7460. createFirmwareVersionByDataTransfer();
  7461. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7462. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7463. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7464. json_object_put(response);
  7465. }
  7466. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7467. {
  7468. system("/usr/bin/run_tmate_restart.sh &");
  7469. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7470. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7471. json_object_put(response);
  7472. }
  7473. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7474. {
  7475. json_object *data;
  7476. data = json_tokener_parse(tempdata);
  7477. if(!is_error(data))
  7478. {
  7479. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7480. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7481. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7482. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7483. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7484. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7485. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7486. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7487. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7488. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7489. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7490. }
  7491. else
  7492. {
  7493. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7494. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7495. }
  7496. json_object_put(data);
  7497. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7498. json_object_put(response);
  7499. }
  7500. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7501. {
  7502. json_object *data;
  7503. data = json_tokener_parse(tempdata);
  7504. if(!is_error(data))
  7505. {
  7506. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7507. if(json_object_object_get(data, "idToken") != NULL)
  7508. {
  7509. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7510. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7511. }
  7512. if(json_object_object_get(data, "price") != NULL)
  7513. {
  7514. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7515. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7516. }
  7517. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7518. }
  7519. else
  7520. {
  7521. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7522. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7523. }
  7524. json_object_put(data);
  7525. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7526. json_object_put(response);
  7527. }
  7528. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7529. {
  7530. json_object *data;
  7531. data = json_tokener_parse(tempdata);
  7532. if(!is_error(data))
  7533. {
  7534. if(json_object_object_get(data, "txId") != NULL)
  7535. {
  7536. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7537. for(int idx = 0;idx<gunTotalNumber;idx++)
  7538. {
  7539. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7540. {
  7541. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7542. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7543. if(json_object_object_get(data, "description") != NULL)
  7544. {
  7545. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7546. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7547. }
  7548. }
  7549. }
  7550. }
  7551. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7552. }
  7553. else
  7554. {
  7555. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7556. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7557. }
  7558. json_object_put(data);
  7559. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7560. json_object_put(response);
  7561. }
  7562. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7563. {
  7564. json_object *data;
  7565. data = json_tokener_parse(tempdata);
  7566. if(!is_error(data))
  7567. {
  7568. if(json_object_object_get(data, "txId") != NULL)
  7569. {
  7570. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7571. for(int idx = 0;idx<gunTotalNumber;idx++)
  7572. {
  7573. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7574. {
  7575. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7576. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7577. if(json_object_object_get(data, "description") != NULL)
  7578. {
  7579. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7580. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7581. }
  7582. }
  7583. }
  7584. }
  7585. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7586. }
  7587. else
  7588. {
  7589. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7590. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7591. }
  7592. json_object_put(data);
  7593. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7594. json_object_put(response);
  7595. }
  7596. else
  7597. {
  7598. // Can not find valid message id
  7599. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7600. }
  7601. }
  7602. else
  7603. {
  7604. // Payload is null
  7605. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7606. }
  7607. LWS_Send(message);
  7608. return result;
  7609. }
  7610. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7611. {
  7612. mtrace();
  7613. int result = FAIL;
  7614. int connectorIdInt, durationInt;
  7615. char chargingRateUnitStr[4]={0};
  7616. char comfirmstr[20];
  7617. int confirmPeriods = 0;
  7618. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7619. json_object *GetCompositeSchedule;
  7620. GetCompositeSchedule = json_tokener_parse(payload);
  7621. if(!is_error(GetCompositeSchedule))
  7622. {
  7623. // Required data
  7624. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7625. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7626. else
  7627. connectorIdInt = -1;
  7628. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7629. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7630. else
  7631. durationInt = 86400;
  7632. // Optional data
  7633. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7634. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7635. }
  7636. json_object_put(GetCompositeSchedule);
  7637. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7638. if((connectorIdInt == 0) ||
  7639. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7640. {
  7641. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7642. struct StructChargingProfile tmpProfile[1];
  7643. if(strstr(chargingRateUnitStr, "W") != NULL)
  7644. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7645. else
  7646. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7647. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7648. {
  7649. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7650. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7651. }
  7652. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7653. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7654. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7655. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7656. {
  7657. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7658. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7659. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7660. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7661. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7662. {
  7663. confirmPeriods = idx;
  7664. break;
  7665. }
  7666. }
  7667. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7668. {
  7669. confirmPeriods += 1;
  7670. }
  7671. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7672. }
  7673. else
  7674. {
  7675. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7676. }
  7677. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7678. return result;
  7679. }
  7680. int handleGetConfigurationRequest(char *uuid, char *payload)
  7681. {
  7682. mtrace();
  7683. int result = FAIL;
  7684. int MaxKeySupported = 0;
  7685. int n_keys = 0;
  7686. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7687. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7688. json_object *GetConfiguration;
  7689. GetConfiguration = json_tokener_parse(payload);
  7690. if(!is_error(GetConfiguration))
  7691. {
  7692. // Optional data
  7693. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7694. {
  7695. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7696. {
  7697. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7698. n_keys = idx + 1;
  7699. }
  7700. }
  7701. }
  7702. json_object_put(GetConfiguration);
  7703. UnknownKeynum = 0;
  7704. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7705. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7706. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7707. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7708. if(n_keys != 0)
  7709. {
  7710. for(int i=0;i<n_keys;i++)
  7711. {
  7712. getKeyValue(requestKey[i]);
  7713. }
  7714. }
  7715. else
  7716. {
  7717. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7718. getKeyValue("");
  7719. }
  7720. processUnkownKey();
  7721. sendGetConfigurationConfirmation(uuid);
  7722. return result;
  7723. }
  7724. static char fnamePlusPath[100]={0};
  7725. static char fnamePWithNoPath[60]={0};
  7726. void checkUploadLog(void)
  7727. {
  7728. FILE *fp;
  7729. /* Open the command for reading. */
  7730. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7731. if (fp == NULL) {
  7732. printf("Failed to run command\n" );
  7733. exit(1);
  7734. }
  7735. int ftppathlen = 0;
  7736. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7737. int i = 0;
  7738. /* Read the output a line at a time - output it. */
  7739. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7740. if(i==0)
  7741. {
  7742. ftppathlen = strlen(fnamePlusPath);
  7743. printf("%s\n", fnamePlusPath);
  7744. fnamePlusPath[ftppathlen]='\0';
  7745. break;
  7746. }
  7747. i= i+1;
  7748. }
  7749. /* close */
  7750. pclose(fp);
  7751. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7752. {
  7753. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7754. {
  7755. fnamePlusPath[k]='\0';
  7756. }
  7757. }
  7758. i=1;
  7759. //char fname[60]={0};
  7760. while(i < ftppathlen)
  7761. {
  7762. int len=ftppathlen-i;
  7763. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7764. {
  7765. printf("compare '/' all right\n");
  7766. break;
  7767. }
  7768. i=i+1;
  7769. }
  7770. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7771. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7772. fnamePWithNoPath[i+1] = '\0';
  7773. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7774. {
  7775. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7776. {
  7777. fnamePWithNoPath[j]='\0';
  7778. }
  7779. }
  7780. FILE* fp1 = fopen(fnamePlusPath, "r");
  7781. if (fp1)
  7782. {
  7783. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7784. // file exists
  7785. fclose(fp1);
  7786. }
  7787. else
  7788. {
  7789. // file doesn't exist
  7790. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7791. }
  7792. }
  7793. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7794. {
  7795. mtrace();
  7796. int result = FAIL;
  7797. time_t CurrentTime;
  7798. struct tm *tm;
  7799. pthread_t th_Status;
  7800. CurrentTime = time(NULL);
  7801. tm = localtime(&CurrentTime);
  7802. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7803. 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);
  7804. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7805. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7806. return result;
  7807. }
  7808. void* GetDiagnosticsProcess(void* data)
  7809. {
  7810. pthread_detach(pthread_self());
  7811. mtrace();
  7812. int retriesInt=0, retryIntervalInt=0;
  7813. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7814. 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};
  7815. int port=0;
  7816. int isSuccess = FALSE;
  7817. char cmdBuf[2048];
  7818. struct tm *tmNow;
  7819. time_t CurrentTime;
  7820. struct tm tmStart;
  7821. struct tm tmStop;
  7822. CurrentTime = time(NULL);
  7823. tmNow=localtime(&CurrentTime);
  7824. uint16_t targetYear, targetMonth;
  7825. json_object *GetDiagnostics;
  7826. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7827. GetDiagnostics = json_tokener_parse(data);
  7828. if(!is_error(GetDiagnostics))
  7829. {
  7830. // Required data
  7831. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7832. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7833. // Optional data
  7834. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7835. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7836. else
  7837. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7838. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7839. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7840. else
  7841. retryIntervalInt = 30;
  7842. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7843. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7844. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7845. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7846. }
  7847. json_object_put(GetDiagnostics);
  7848. // Pack log to compress file
  7849. 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) &&
  7850. (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))
  7851. {
  7852. // Pack system log
  7853. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7854. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7855. targetYear = tmStart.tm_year;
  7856. targetMonth = tmStart.tm_mon;
  7857. do
  7858. {
  7859. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7860. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7861. if(targetMonth+1>=13)
  7862. {
  7863. targetYear += 1;
  7864. targetMonth = 1;
  7865. }
  7866. else
  7867. {
  7868. targetMonth += 1;
  7869. }
  7870. }while((targetYear < (tmNow->tm_year+1900)) ||
  7871. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7872. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7873. system(cmdBuf);
  7874. // Pack charging & event log
  7875. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7876. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7877. targetYear = tmStart.tm_year;
  7878. targetMonth = tmStart.tm_mon;
  7879. do
  7880. {
  7881. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7882. if(targetMonth+1>=13)
  7883. {
  7884. targetYear += 1;
  7885. targetMonth = 1;
  7886. }
  7887. else
  7888. {
  7889. targetMonth += 1;
  7890. }
  7891. }while((targetYear < (tmNow->tm_year+1900)) ||
  7892. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7893. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7894. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7895. system(cmdBuf);
  7896. // Combine log file
  7897. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7898. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7899. }
  7900. else
  7901. {
  7902. system("exec /root/logPackTools 'log' 6");
  7903. }
  7904. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7905. system(cmdBuf);
  7906. checkUploadLog();
  7907. //****************location*******************/
  7908. if(strcmp(locationstr,"")==0)
  7909. {
  7910. DEBUG_INFO("location is <Empty>!\n");
  7911. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7912. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7913. goto end;
  7914. }
  7915. memset(protocol, 0, ARRAY_SIZE(protocol));
  7916. memset(user, 0, ARRAY_SIZE(user) );
  7917. memset(password, 0, ARRAY_SIZE(password));
  7918. memset(host, 0, ARRAY_SIZE(host));
  7919. memset(path, 0, ARRAY_SIZE(path));
  7920. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7921. memset(host1, 0, ARRAY_SIZE(host1));
  7922. memset(path1, 0, ARRAY_SIZE(path1));
  7923. /*location: ftp://user:password@host:port/path*/
  7924. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7925. if((access(fnamePlusPath,F_OK))!=-1)
  7926. {
  7927. DEBUG_INFO("fnamePlusPath exist.\n");
  7928. }
  7929. else
  7930. {
  7931. DEBUG_INFO("fnamePlusPath not exist!\n");
  7932. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7933. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7934. goto end;
  7935. }
  7936. if(strchr(locationstr,'@')==NULL)
  7937. {
  7938. sscanf(locationstr,
  7939. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7940. protocol, host, &port, path);
  7941. strcpy(user,"anonymous");
  7942. strcpy(password,"");
  7943. }
  7944. else
  7945. {
  7946. //DEBUG_INFO("pch=%s\n", pch);
  7947. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7948. protocol, user, password, host, &port, path);
  7949. }
  7950. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  7951. {
  7952. DEBUG_INFO("protocol is not ftp/http ! \n");
  7953. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7954. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7955. goto end;
  7956. }
  7957. if(strncmp(locationstr,"http", 4) == 0)
  7958. {
  7959. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7960. sprintf(ftppath,"/%s", path);
  7961. do
  7962. {
  7963. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7964. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7965. sleep(3);
  7966. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7967. if(!isSuccess)
  7968. {
  7969. DEBUG_INFO("Diagnostics fail.\n");
  7970. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7971. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7972. sleep(retryIntervalInt);
  7973. }
  7974. else
  7975. {
  7976. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7977. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7978. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7979. }
  7980. retriesInt--;
  7981. }while((isSuccess == 0)&&(retriesInt >= 0));
  7982. }
  7983. else
  7984. {
  7985. sscanf(host,"%[^/]%s",host1, path1);
  7986. if(strlen(path) > 0)
  7987. sprintf(ftppath,"/%s", path);
  7988. else
  7989. sprintf(ftppath,"/%s", path1);
  7990. int ftppathlen=strlen(ftppath);
  7991. int i=1;
  7992. char filenametemp[50];
  7993. while(i < ftppathlen)
  7994. {
  7995. int len=ftppathlen-i;
  7996. if(ftppath[len]== 47) // '/' ascll code: 47
  7997. {
  7998. DEBUG_INFO("find '/' all right\n");
  7999. break;
  8000. }
  8001. i=i+1;
  8002. }
  8003. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8004. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8005. filenametemp[i+1] = 0;
  8006. if(port == 0)
  8007. port = 21;
  8008. do
  8009. {
  8010. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8011. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8012. sleep(3);
  8013. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8014. if(!isSuccess)
  8015. {
  8016. DEBUG_INFO("Diagnostics fail.\n");
  8017. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8018. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8019. sleep(retryIntervalInt);
  8020. }
  8021. else
  8022. {
  8023. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8024. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8025. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8026. }
  8027. retriesInt--;
  8028. }while((!isSuccess)&&(retriesInt >= 0));
  8029. }
  8030. end:
  8031. system("rm -f /mnt/*");
  8032. sleep(5);
  8033. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8034. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8035. pthread_exit(NULL);
  8036. }
  8037. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8038. {
  8039. mtrace();
  8040. int result = FAIL;
  8041. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8042. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8043. {
  8044. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8045. localversion = -1;
  8046. }
  8047. else
  8048. {
  8049. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8050. OCPP_getListVerion();
  8051. }
  8052. //from db.OCPP_getListVerion
  8053. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  8054. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  8055. sendGetLocalListVersionConfirmation(uuid,"");
  8056. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  8057. return result;
  8058. }
  8059. int handleRemoteStartRequest(char *uuid, char *payload)
  8060. {
  8061. mtrace();
  8062. int result = FAIL;
  8063. int connectorIdInt=0;
  8064. int tempIndex = 0;
  8065. int connectorIdIsNULL, chargingProfileIsNULL;
  8066. char comfirmstr[20]={0};
  8067. char cmdBuf[512];
  8068. json_object *RemoteStartTransaction;
  8069. FILE *fp;
  8070. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8071. if(server_pending == TRUE)
  8072. {
  8073. return 0;
  8074. }
  8075. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8076. RemoteStartTransaction = json_tokener_parse(payload);
  8077. if(!is_error(RemoteStartTransaction))
  8078. {
  8079. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8080. {
  8081. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8082. if(connectorIdInt <= gunTotalNumber)
  8083. {
  8084. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8085. // Required data
  8086. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8087. // Optional data
  8088. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8089. {
  8090. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8091. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8092. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8093. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8094. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8095. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8096. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8097. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8098. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8099. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8100. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8101. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8102. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8103. {
  8104. 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")));
  8105. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8106. 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"));
  8107. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8108. 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"));
  8109. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8110. 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")));
  8111. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8112. {
  8113. 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++)
  8114. {
  8115. 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"));
  8116. 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"));
  8117. 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)
  8118. 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"));
  8119. }
  8120. }
  8121. }
  8122. }
  8123. else
  8124. chargingProfileIsNULL = TRUE;
  8125. }
  8126. }
  8127. else
  8128. connectorIdIsNULL = TRUE;
  8129. }
  8130. else
  8131. connectorIdIsNULL = TRUE;
  8132. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8133. {
  8134. DEBUG_WARN("Connector id is NULL\n.");
  8135. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8136. goto end;
  8137. }
  8138. /*
  8139. enum _SYSTEM_STATUS
  8140. {
  8141. S_BOOTING = 0,
  8142. S_IDLE, = 1
  8143. S_AUTHORIZING, = 2
  8144. S_REASSIGN_CHECK, = 3
  8145. S_REASSIGN, = 4
  8146. S_PRECHARGE, = 5
  8147. S_PREPARING_FOR_EV, = 6
  8148. S_PREPARING_FOR_EVSE, = 7
  8149. S_CHARGING, = 8
  8150. S_TERMINATING, = 9
  8151. S_COMPLETE, = 10
  8152. S_ALARM, = 11
  8153. S_FAULT = 12
  8154. }
  8155. */
  8156. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8157. {
  8158. //check Transaction active
  8159. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8160. {
  8161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8162. {
  8163. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8164. }
  8165. else
  8166. {
  8167. tempIndex = connectorIdInt -1;
  8168. }
  8169. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8170. {
  8171. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8172. {
  8173. 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))
  8174. {
  8175. //Reserved
  8176. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8177. }
  8178. 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))
  8179. {
  8180. //Reserved
  8181. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8182. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8183. goto end;
  8184. }
  8185. else
  8186. {
  8187. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8188. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8189. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8190. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8191. {
  8192. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8193. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8194. goto end;
  8195. }
  8196. }//END FOR ELSE
  8197. }
  8198. }// END FOR CHAdeMO_QUANTITY
  8199. }
  8200. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8201. {
  8202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8203. {
  8204. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8205. }
  8206. else
  8207. {
  8208. tempIndex = connectorIdInt -1;
  8209. }
  8210. for (int index = 0; index < CCS_QUANTITY; index++)
  8211. {
  8212. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8213. {
  8214. 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))
  8215. {
  8216. //Reserved
  8217. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8218. }
  8219. 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))
  8220. {
  8221. //Reserved
  8222. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8223. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8224. goto end;
  8225. }
  8226. else
  8227. {
  8228. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8229. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8230. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8231. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8232. {
  8233. DEBUG_WARN("CCS connector not allow start\n.");
  8234. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8235. goto end;
  8236. }
  8237. }// END FOR ELSE
  8238. }
  8239. }// END FOR CCS_QUANTITY
  8240. }
  8241. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8242. {
  8243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8244. {
  8245. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8246. }
  8247. else
  8248. {
  8249. tempIndex = connectorIdInt -1;
  8250. }
  8251. for (int index = 0; index < GB_QUANTITY; index++)
  8252. {
  8253. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8254. {
  8255. 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))
  8256. {
  8257. //Reserved
  8258. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8259. }
  8260. 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))
  8261. {
  8262. //Reserved
  8263. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8265. goto end;
  8266. }
  8267. else
  8268. {
  8269. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8270. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8271. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8272. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8273. {
  8274. DEBUG_WARN("GB connector not allow start\n.");
  8275. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8276. goto end;
  8277. }
  8278. }// END FOR ELSE
  8279. }
  8280. } // END FOR GB_QUANTITY
  8281. }
  8282. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8283. {
  8284. tempIndex = connectorIdInt -1;
  8285. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8286. {
  8287. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8288. {
  8289. 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))
  8290. {
  8291. //Reserved
  8292. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8293. }
  8294. 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))
  8295. {
  8296. //Reserved
  8297. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8298. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8299. goto end;
  8300. }
  8301. else
  8302. {
  8303. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8304. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8305. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8306. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8307. {
  8308. DEBUG_WARN("GB connector not allow start\n.");
  8309. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8310. goto end;
  8311. }
  8312. }// END FOR ELSE
  8313. }
  8314. } // END FOR GB_QUANTITY
  8315. }
  8316. else
  8317. {
  8318. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8319. {
  8320. tempIndex = 2;
  8321. }
  8322. else
  8323. {
  8324. tempIndex = connectorIdInt -1;
  8325. }
  8326. for (int index = 0; index < AC_QUANTITY; index++)
  8327. {
  8328. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8329. {
  8330. 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))
  8331. {
  8332. //Reserved
  8333. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8334. }
  8335. 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))
  8336. {
  8337. //Reserved
  8338. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8339. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8340. goto end;
  8341. }
  8342. else
  8343. {
  8344. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8345. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8346. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8347. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8348. {
  8349. DEBUG_WARN("AC connector not allow start\n.");
  8350. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8351. goto end;
  8352. }
  8353. }//END FOR ELSE
  8354. }
  8355. }// END FOR AC_QUANTITY
  8356. }
  8357. if(chargingProfileIsNULL == FALSE)
  8358. {
  8359. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8360. {
  8361. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8362. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8363. //memset idTag
  8364. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8365. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8366. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8367. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8368. // Save profile to file
  8369. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8370. system(cmdBuf);
  8371. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8372. fp = fopen(cmdBuf, "w");
  8373. 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));
  8374. fclose(fp);
  8375. }
  8376. else
  8377. {
  8378. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8379. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8380. }
  8381. }
  8382. else
  8383. {
  8384. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8385. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8386. //memset idTag
  8387. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8388. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8389. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8390. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8391. }
  8392. }
  8393. else
  8394. {
  8395. DEBUG_WARN("Connector id over\n.");
  8396. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8397. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8398. }
  8399. end:
  8400. json_object_put(RemoteStartTransaction);
  8401. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8402. {
  8403. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8404. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8405. }
  8406. //OCPP send RemoteStartConfirmation by first.
  8407. sendRemoteStartConfirmation(uuid, comfirmstr);
  8408. return result;
  8409. }
  8410. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8411. {
  8412. mtrace();
  8413. int result = FAIL;
  8414. int match = FALSE;
  8415. int GunNO = 0;
  8416. int tempIndex = 0;
  8417. int transactionIdInt=0;
  8418. int transactionIdIsNULL= TRUE;
  8419. char comfirmstr[20];
  8420. json_object *RemoteStopTransaction;
  8421. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8422. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8423. if(server_pending == TRUE)
  8424. {
  8425. return 0;
  8426. }
  8427. RemoteStopTransaction = json_tokener_parse(payload);
  8428. if(!is_error(RemoteStopTransaction))
  8429. {
  8430. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8431. {
  8432. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8433. transactionIdIsNULL = FALSE;
  8434. }
  8435. }
  8436. json_object_put(RemoteStopTransaction);
  8437. if(transactionIdIsNULL == FALSE)
  8438. {
  8439. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8440. {
  8441. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8442. {
  8443. //check Transaction active
  8444. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8445. {
  8446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8447. {
  8448. tempIndex = ((gun_index==2) ? 1: 0);
  8449. }
  8450. else
  8451. {
  8452. tempIndex = gun_index;
  8453. }
  8454. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8455. {
  8456. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8457. {
  8458. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8459. {
  8460. match = TRUE;
  8461. GunNO = gun_index;
  8462. }
  8463. }
  8464. }// END FOR CHAdeMO_QUANTITY
  8465. }
  8466. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8467. {
  8468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8469. {
  8470. tempIndex = ((gun_index==2) ? 1: 0);
  8471. }
  8472. else
  8473. {
  8474. tempIndex = gun_index;
  8475. }
  8476. for (int index = 0; index < CCS_QUANTITY; index++)
  8477. {
  8478. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8479. {
  8480. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8481. {
  8482. match = TRUE;
  8483. GunNO = gun_index;
  8484. }
  8485. }
  8486. }// END FOR CCS_QUANTITY
  8487. }
  8488. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8489. {
  8490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8491. {
  8492. tempIndex = ((gun_index==2) ? 1: 0);
  8493. }
  8494. else
  8495. {
  8496. tempIndex = gun_index;
  8497. }
  8498. for (int index = 0; index < GB_QUANTITY; index++)
  8499. {
  8500. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8501. {
  8502. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8503. {
  8504. match = TRUE;
  8505. GunNO = gun_index;
  8506. }
  8507. }
  8508. }// END FOR GB_QUANTITY
  8509. }
  8510. else if(gunType[gun_index] == GUN_TYPE_DO)
  8511. {
  8512. tempIndex = gun_index;
  8513. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8514. {
  8515. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8516. {
  8517. 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
  8518. {
  8519. match = TRUE;
  8520. GunNO = gun_index;
  8521. }
  8522. }
  8523. }// END FOR GB_QUANTITY
  8524. }
  8525. else
  8526. {
  8527. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8528. {
  8529. tempIndex = 2;
  8530. }
  8531. else
  8532. {
  8533. tempIndex = gun_index;
  8534. }
  8535. for (int index = 0; index < AC_QUANTITY; index++)
  8536. {
  8537. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8538. {
  8539. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8540. {
  8541. match = TRUE;
  8542. GunNO = gun_index;
  8543. }
  8544. }
  8545. }// END FOR CHAdeMO_QUANTITY
  8546. } // END FOR AC ELSE
  8547. }// CHECK IF ResponseTransactionId == transactionIdInt
  8548. }//END FOR
  8549. if( match == TRUE)
  8550. {
  8551. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8552. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8553. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8554. }
  8555. else
  8556. {
  8557. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8558. }
  8559. }
  8560. else
  8561. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8562. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8563. return result;
  8564. }
  8565. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8566. {
  8567. mtrace();
  8568. int result = FAIL;
  8569. int connectorIdInt=0, reservationIdInt=0;
  8570. int tempIndex = 0;
  8571. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8572. char comfirmstr[20]={0};
  8573. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8574. int c = 0;
  8575. char *loc;
  8576. //char *ptr;
  8577. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8578. strcpy(sstrtemp, stringtrimspace(payload));
  8579. //***(1)connectorId ****/
  8580. c=0;
  8581. loc = strstr(sstrtemp, "connectorId");
  8582. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8583. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8584. {
  8585. sstr[c] = loc[strlen("connectorId")+2+c];
  8586. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8587. c++;
  8588. }
  8589. sstr[c] = '\0';
  8590. connectorIdInt = atoi(sstr);
  8591. //***(2)expiryDate ****/
  8592. loc = strstr(sstrtemp, "expiryDate");
  8593. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8594. c = 0;
  8595. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8596. {
  8597. sstr[c] = loc[3+strlen("expiryDate")+c];
  8598. c++;
  8599. }
  8600. sstr[c] = '\0';
  8601. strcpy(expiryDatestr, sstr);
  8602. //***(3)idTag ****/
  8603. loc = strstr(sstrtemp, "idTag");
  8604. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8605. c = 0;
  8606. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8607. {
  8608. sstr[c] = loc[3+strlen("idTag")+c];
  8609. c++;
  8610. }
  8611. sstr[c] = '\0';
  8612. strcpy(idTagstr, sstr);
  8613. //***(4)parentIdTag ****/
  8614. loc = strstr(sstrtemp, "parentIdTag");
  8615. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8616. c = 0;
  8617. if(loc == NULL)
  8618. {
  8619. strcpy(parentIdTagstr, "");
  8620. }
  8621. else
  8622. {
  8623. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8624. {
  8625. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8626. c++;
  8627. }
  8628. sstr[c] = '\0';
  8629. strcpy(parentIdTagstr, sstr);
  8630. }
  8631. //***(5)reservationId ****/
  8632. c=0;
  8633. loc = strstr(sstrtemp, "reservationId");
  8634. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8635. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8636. {
  8637. sstr[c] = loc[strlen("reservationId")+2+c];
  8638. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8639. c++;
  8640. }
  8641. sstr[c] = '\0';
  8642. reservationIdInt = atoi(sstr);
  8643. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8644. /*
  8645. enum SYSTEM_STATUS
  8646. {
  8647. SYS_MODE_BOOTING = 0,
  8648. SYS_MODE_IDLE = 1,
  8649. SYS_MODE_AUTHORIZING = 2,
  8650. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8651. SYS_MODE_REASSIGN = 4,
  8652. SYS_MODE_PREPARING = 5,
  8653. SYS_MODE_PREPARE_FOR_EV = 6,
  8654. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8655. SYS_MODE_CHARGING = 8,
  8656. SYS_MODE_TERMINATING = 9,
  8657. SYS_MODE_COMPLETE = 10,
  8658. SYS_MODE_ALARM = 11,
  8659. SYS_MODE_FAULT = 12,
  8660. SYS_MODE_RESERVATION = 13,
  8661. SYS_MODE_BOOKING = 14,
  8662. SYS_MODE_MAINTAIN = 15,
  8663. SYS_MODE_DEBUG = 16,
  8664. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8665. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8666. SYS_MODE_UPDATE = 19
  8667. };
  8668. */
  8669. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8670. {
  8671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8672. goto end;
  8673. }
  8674. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8675. {
  8676. //check Transaction active
  8677. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8678. {
  8679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8680. {
  8681. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8682. }
  8683. else
  8684. {
  8685. tempIndex = connectorIdInt -1;
  8686. }
  8687. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8688. {
  8689. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8690. {
  8691. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8692. {
  8693. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8694. {
  8695. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8696. {
  8697. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8698. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8699. }
  8700. 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'))
  8701. {
  8702. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8703. }
  8704. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8705. {
  8706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8707. }
  8708. else
  8709. {
  8710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8711. }
  8712. }
  8713. 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
  8714. {
  8715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8716. }
  8717. }
  8718. else
  8719. {
  8720. //replace reservation
  8721. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8723. }
  8724. }
  8725. } // END FOR CHAdeMO_QUANTITY
  8726. }
  8727. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8728. {
  8729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8730. {
  8731. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8732. }
  8733. else
  8734. {
  8735. tempIndex = connectorIdInt -1;
  8736. }
  8737. for (int index = 0; index < CCS_QUANTITY; index++)
  8738. {
  8739. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8740. {
  8741. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8742. {
  8743. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8744. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8745. {
  8746. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8747. {
  8748. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8750. }
  8751. 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'))
  8752. {
  8753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8754. }
  8755. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8756. {
  8757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8758. }
  8759. else
  8760. {
  8761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8762. }
  8763. }
  8764. 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
  8765. {
  8766. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8767. }
  8768. }
  8769. else
  8770. {
  8771. //replace reservation
  8772. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8774. }
  8775. }
  8776. } // END FOR CCS_QUANTITY
  8777. }
  8778. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8779. {
  8780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8781. {
  8782. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8783. }
  8784. else
  8785. {
  8786. tempIndex = connectorIdInt -1;
  8787. }
  8788. for (int index = 0; index < GB_QUANTITY; index++)
  8789. {
  8790. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8791. {
  8792. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8793. {
  8794. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8795. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8796. {
  8797. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8798. {
  8799. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8801. }
  8802. 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'))
  8803. {
  8804. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8805. }
  8806. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8807. {
  8808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8809. }
  8810. else
  8811. {
  8812. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8813. }
  8814. }
  8815. 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
  8816. {
  8817. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8818. }
  8819. }
  8820. else
  8821. {
  8822. //replace reservation
  8823. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8824. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8825. }
  8826. }
  8827. }// END FOR GB_QUANTITY
  8828. }
  8829. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8830. {
  8831. tempIndex = connectorIdInt -1;
  8832. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8833. {
  8834. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8835. {
  8836. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8837. {
  8838. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8839. 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
  8840. {
  8841. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8842. {
  8843. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8845. }
  8846. 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'))
  8847. {
  8848. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8849. }
  8850. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8851. {
  8852. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8853. }
  8854. else
  8855. {
  8856. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8857. }
  8858. }
  8859. 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
  8860. {
  8861. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8862. }
  8863. }
  8864. else
  8865. {
  8866. //replace reservation
  8867. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8868. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8869. }
  8870. }
  8871. }// END FOR GB_QUANTITY
  8872. }
  8873. else
  8874. {
  8875. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8876. {
  8877. tempIndex = 2;
  8878. }
  8879. else
  8880. {
  8881. tempIndex = (connectorIdInt -1);
  8882. }
  8883. for (int index = 0; index < AC_QUANTITY; index++)
  8884. {
  8885. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8886. {
  8887. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8888. {
  8889. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8890. {
  8891. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8892. {
  8893. 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))
  8894. {
  8895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8896. }
  8897. else
  8898. {
  8899. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8901. }
  8902. }
  8903. 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'))
  8904. {
  8905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8906. }
  8907. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8908. {
  8909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8910. }
  8911. else
  8912. {
  8913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8914. }
  8915. }
  8916. 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
  8917. {
  8918. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8919. }
  8920. }
  8921. else
  8922. {
  8923. //replace reservation
  8924. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8925. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8926. }
  8927. }
  8928. } // END FOR AC_QUANTITY
  8929. }
  8930. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8931. }
  8932. else if(connectorIdInt == 0)
  8933. {
  8934. //check Transaction active
  8935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8936. {
  8937. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8938. {
  8939. 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'))
  8940. {
  8941. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8942. goto end;
  8943. }
  8944. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8945. {
  8946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8947. goto end;
  8948. }
  8949. 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
  8950. {
  8951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8952. goto end;
  8953. }
  8954. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8955. {
  8956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8957. goto end;
  8958. }
  8959. }
  8960. }// END FOR CHAdeMO_QUANTITY
  8961. for (int index = 0; index < CCS_QUANTITY; index++)
  8962. {
  8963. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8964. {
  8965. 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'))
  8966. {
  8967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8968. goto end;
  8969. }
  8970. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8971. {
  8972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8973. goto end;
  8974. }
  8975. 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
  8976. {
  8977. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8978. goto end;
  8979. }
  8980. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8981. {
  8982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8983. goto end;
  8984. }
  8985. }
  8986. } // END FOR CCS_QUANTITY
  8987. for (int index = 0; index < GB_QUANTITY; index++)
  8988. {
  8989. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8990. {
  8991. 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'))
  8992. {
  8993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8994. goto end;
  8995. }
  8996. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8997. {
  8998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8999. goto end;
  9000. }
  9001. 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
  9002. {
  9003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9004. goto end;
  9005. }
  9006. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9007. {
  9008. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9009. goto end;
  9010. }
  9011. }
  9012. } // END FOR GB_QUANTITY
  9013. for (int index = 0; index < AC_QUANTITY; index++)
  9014. {
  9015. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9016. {
  9017. 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'))
  9018. {
  9019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9020. goto end;
  9021. }
  9022. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9023. {
  9024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9025. goto end;
  9026. }
  9027. 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
  9028. {
  9029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9030. goto end;
  9031. }
  9032. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9033. {
  9034. 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))
  9035. {
  9036. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9037. goto end;
  9038. }
  9039. }
  9040. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9041. {
  9042. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9043. goto end;
  9044. }
  9045. }
  9046. }// END FOR AC_QUANTITY
  9047. //The connectorId is 0
  9048. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  9049. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9050. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9051. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  9052. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9053. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  9054. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9055. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  9056. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  9057. result = TRUE;
  9058. return result;
  9059. }
  9060. else
  9061. {
  9062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9063. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9064. }
  9065. if(strcmp(comfirmstr,"Accepted") == 0)
  9066. {
  9067. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9068. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9069. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9070. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9071. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9072. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  9073. result = TRUE;
  9074. return result;
  9075. }
  9076. end:
  9077. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9078. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9079. return result;
  9080. }
  9081. int handleResetRequest(char *uuid, char *payload)
  9082. {
  9083. mtrace();
  9084. int result = FAIL;
  9085. char sstr[10]={0},sstrtemp[30]={ 0 };
  9086. char typestr[10]={0};
  9087. char comfirmstr[20]={0};
  9088. int c = 0;
  9089. char *loc;
  9090. DEBUG_INFO("handleResetRequest...\n");
  9091. strcpy(sstrtemp, stringtrimspace(payload));
  9092. loc = strstr(sstrtemp, "type");
  9093. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9094. c = 0;
  9095. while (loc[3+strlen("type")+c] != '\"')
  9096. {
  9097. sstr[c] = loc[3+strlen("type")+c];
  9098. c++;
  9099. }
  9100. sstr[c] = '\0';
  9101. strcpy(typestr,sstr);
  9102. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  9103. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9104. {
  9105. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  9106. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  9107. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9108. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9109. }
  9110. else
  9111. {
  9112. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9113. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9114. result = PASS;
  9115. }
  9116. sendResetConfirmation(uuid, comfirmstr);
  9117. return result;
  9118. }
  9119. int handleSendLocalListRequest(char *uuid, char *payload)
  9120. {
  9121. mtrace();
  9122. int result = FAIL;
  9123. int listVersionInt;
  9124. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9125. char listsearch[]="listVersion";
  9126. char updateTypesearch[]="updateType";
  9127. char localAuthorizationListsearch[]="localAuthorizationList";
  9128. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9129. char CardList[500][160]={0};
  9130. char updateTypestr[15]={0};
  9131. char idTagstr[20]={0};
  9132. char parentIdTag[20]={0};
  9133. char expiryDate[30]={0};
  9134. char idTagstatus[16]={0};
  9135. int c = 0;
  9136. int i = 0;
  9137. char *delim1 = "}";
  9138. char * pch;
  9139. char *loc;
  9140. //char *ptr;
  9141. char comfirmstr[20];
  9142. //int n_localAuthorizations = 0;
  9143. int checkState_Faulted = FALSE;
  9144. DEBUG_INFO("handleSendLocalListRequest...\n");
  9145. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9146. {
  9147. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9148. goto end;
  9149. }
  9150. //check Charge Point state
  9151. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9152. {
  9153. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9154. {
  9155. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9156. }
  9157. }
  9158. for (int index = 0; index < CCS_QUANTITY; index++)
  9159. {
  9160. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9161. {
  9162. checkState_Faulted = TRUE; //OCPP Status
  9163. }
  9164. }
  9165. for (int index = 0; index < GB_QUANTITY; index++)
  9166. {
  9167. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9168. {
  9169. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9170. }
  9171. }
  9172. //check Charge Point state
  9173. for (int index = 0; index < AC_QUANTITY; index++)
  9174. {
  9175. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9176. {
  9177. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9178. }
  9179. }
  9180. if(checkState_Faulted == TRUE)
  9181. {
  9182. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9183. goto end;
  9184. }
  9185. //Filter payload space
  9186. strcpy(sstrtemp, stringtrimspace(payload));
  9187. //listVersion
  9188. c = 0;
  9189. loc = strstr(sstrtemp, listsearch);
  9190. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9191. {
  9192. sstr[c] = loc[strlen("listVersion")+2+c];
  9193. c++;
  9194. }
  9195. sstr[c] = '\0';
  9196. listVersionInt = atoi(sstr);
  9197. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9198. //updateType
  9199. loc = strstr(sstrtemp, updateTypesearch);
  9200. c = 0;
  9201. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9202. {
  9203. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9204. c++;
  9205. }
  9206. sstr[c] = '\0';
  9207. strcpy(updateTypestr, sstr);
  9208. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9209. //localAuthorizationList
  9210. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9211. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9212. if(loc != NULL) // localAuthorizationList is not NULL
  9213. {
  9214. //Check UpdateType
  9215. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9216. {
  9217. //Local list full update
  9218. printf("Local list full update.\n");
  9219. OCPP_getListVerion();
  9220. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9221. {
  9222. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9223. goto end;
  9224. }
  9225. OCPP_cleanLocalList();
  9226. }
  9227. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9228. {
  9229. //Local list different update
  9230. printf("Local list different update.\n");
  9231. OCPP_getListVerion();
  9232. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9233. {
  9234. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9235. goto end;
  9236. }
  9237. }
  9238. else
  9239. {
  9240. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9241. goto end;
  9242. }
  9243. c = 0;
  9244. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9245. {
  9246. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9247. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9248. c++;
  9249. }
  9250. sstr[c] = '\0';
  9251. //DEBUG_INFO("sstr=%s\n", sstr);
  9252. //parsing strings to words
  9253. i = 0;
  9254. pch = strtok(sstr,delim1);
  9255. while (pch != NULL)
  9256. {
  9257. strcpy(CardList[i], pch);
  9258. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9259. pch = strtok (NULL, delim1);
  9260. i = i + 1;
  9261. }
  9262. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9263. //local Authorizations List Numbers
  9264. //n_localAuthorizations = i;
  9265. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9266. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9267. c= 0;
  9268. while(c < i) // i is CardList Number
  9269. {
  9270. //Search "IdToken"
  9271. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9272. loc = strstr(CardList[c], "idTag");
  9273. int j = 0;
  9274. while (loc[3+strlen("idTag")+j] != '\"')
  9275. {
  9276. sstr[j] = loc[3+strlen("idTag")+j];
  9277. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9278. j++;
  9279. }
  9280. sstr[j] = '\0';
  9281. strcpy(idTagstr, sstr);
  9282. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9283. //Search "expiryDate"
  9284. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9285. loc = strstr(CardList[c], "expiryDate");
  9286. j = 0;
  9287. if(loc != NULL)
  9288. {
  9289. while (loc[3+strlen("expiryDate")+j] != '\"')
  9290. {
  9291. sstr[j] = loc[3+strlen("expiryDate")+j];
  9292. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9293. j++;
  9294. }
  9295. sstr[j] = '\0';
  9296. strcpy(expiryDate, sstr);
  9297. }
  9298. else
  9299. {
  9300. strcpy(expiryDate, "");
  9301. }
  9302. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9303. //Search "parentIdTag"
  9304. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9305. loc = strstr(CardList[c], "parentIdTag");
  9306. j = 0;
  9307. if(loc != NULL)
  9308. {
  9309. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9310. {
  9311. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9312. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9313. j++;
  9314. }
  9315. sstr[j] = '\0';
  9316. strcpy(parentIdTag, sstr);
  9317. }
  9318. else
  9319. {
  9320. strcpy(parentIdTag, "");
  9321. }
  9322. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9323. //Search "status"
  9324. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9325. loc = strstr(CardList[c], "status");
  9326. j = 0;
  9327. while (loc[3+strlen("status")+j] != '\"')
  9328. {
  9329. sstr[j] = loc[3+strlen("status")+j];
  9330. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9331. j++;
  9332. }
  9333. sstr[j] = '\0';
  9334. strcpy(idTagstatus, sstr);
  9335. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9336. OCPP_getIdTagFromLocalList(idTagstr);
  9337. //OCPP_getIdTagFromLocalList("test"); For Test
  9338. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9339. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9340. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9341. {
  9342. //Local list full update
  9343. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9344. // update list
  9345. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9346. //DEBUG_INFO("Local list full update. 1\n");
  9347. //OCPP_get_TableAuthlocalAllData();
  9348. //DEBUG_INFO("Local list full update. 2\n");
  9349. }
  9350. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9351. {
  9352. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9353. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9354. }
  9355. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9356. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9357. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9358. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9359. c++;
  9360. }
  9361. }
  9362. else
  9363. {
  9364. //Check UpdateType
  9365. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9366. {
  9367. //Local list full update
  9368. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9369. OCPP_cleanLocalList();
  9370. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9371. goto end;
  9372. }
  9373. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9374. {
  9375. //Local list different update
  9376. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9377. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9378. goto end;
  9379. }
  9380. }
  9381. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9382. end:
  9383. sendSendLocalListConfirmation(uuid, comfirmstr);
  9384. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9385. return result;
  9386. }
  9387. #define MAX 200
  9388. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9389. {
  9390. mtrace();
  9391. int result = FAIL;
  9392. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9393. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9394. char chargingProfilePurposeStr[30]={0};
  9395. char chargingProfileKindStr[16]={0};
  9396. char recurrencyKindStr[10]={0};
  9397. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9398. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9399. int chargingSchedulePeriodCount = 0;
  9400. char comfirmstr[20]={0};
  9401. int meet= FALSE;
  9402. FILE *fptr1;
  9403. char filename[MAX]={0};
  9404. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9405. char rmFileCmd[50]={0};
  9406. char tempchargingProfilePurposeStr[30]={0};
  9407. char word[1600]={0};
  9408. int n_chargingProfile = 0;
  9409. json_object *SetChargingProfile;
  9410. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9411. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9412. SetChargingProfile = json_tokener_parse(payload);
  9413. if(!is_error(SetChargingProfile))
  9414. {
  9415. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9416. {
  9417. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9418. if(connectorIdInt == 0)
  9419. {
  9420. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9421. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9422. }
  9423. else
  9424. {
  9425. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9426. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9427. }
  9428. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9429. }
  9430. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9431. {
  9432. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9433. {
  9434. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9435. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9436. {
  9437. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9438. }
  9439. else
  9440. {
  9441. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9442. }
  9443. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9444. }
  9445. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9446. {
  9447. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9448. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9449. {
  9450. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9451. }
  9452. else
  9453. {
  9454. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9455. }
  9456. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9457. }
  9458. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9459. {
  9460. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9461. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9462. {
  9463. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9464. }
  9465. else
  9466. {
  9467. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9468. }
  9469. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9470. }
  9471. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9472. {
  9473. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9474. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9475. {
  9476. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9477. }
  9478. else
  9479. {
  9480. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9481. }
  9482. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9483. }
  9484. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9485. {
  9486. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9487. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9488. {
  9489. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9490. }
  9491. else
  9492. {
  9493. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9494. }
  9495. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9496. }
  9497. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9498. {
  9499. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9500. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9501. {
  9502. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9503. }
  9504. else
  9505. {
  9506. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9507. }
  9508. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9509. }
  9510. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9511. {
  9512. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9513. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9514. {
  9515. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9516. }
  9517. else
  9518. {
  9519. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9520. }
  9521. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9522. }
  9523. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9524. {
  9525. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9526. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9527. {
  9528. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9529. }
  9530. else
  9531. {
  9532. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9533. }
  9534. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9535. }
  9536. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9537. {
  9538. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9539. {
  9540. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9541. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9542. {
  9543. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9544. }
  9545. else
  9546. {
  9547. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9548. }
  9549. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9550. }
  9551. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9552. {
  9553. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9554. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9555. {
  9556. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9557. }
  9558. else
  9559. {
  9560. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9561. }
  9562. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9563. }
  9564. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9565. {
  9566. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9567. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9568. {
  9569. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9570. }
  9571. else
  9572. {
  9573. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9574. }
  9575. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9576. }
  9577. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9578. {
  9579. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9580. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9581. {
  9582. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9583. }
  9584. else
  9585. {
  9586. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9587. }
  9588. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9589. }
  9590. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9591. {
  9592. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9593. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9594. if(chargingSchedulePeriodCount <= 10)
  9595. {
  9596. 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++)
  9597. {
  9598. 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)
  9599. {
  9600. 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"));
  9601. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9602. {
  9603. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9604. }
  9605. else
  9606. {
  9607. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9608. }
  9609. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9610. }
  9611. 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)
  9612. {
  9613. 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"));
  9614. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9615. {
  9616. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9617. }
  9618. else
  9619. {
  9620. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9621. }
  9622. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9623. }
  9624. 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)
  9625. {
  9626. 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"));
  9627. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9628. {
  9629. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9630. }
  9631. else
  9632. {
  9633. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9634. }
  9635. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9636. }
  9637. }
  9638. }
  9639. }
  9640. }
  9641. }
  9642. }
  9643. json_object_put(SetChargingProfile);
  9644. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9645. {
  9646. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9647. goto end;
  9648. }
  9649. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9650. {
  9651. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9652. if(connectorIdInt != 0)
  9653. {
  9654. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9655. goto end;
  9656. }
  9657. strcpy(filename, ChargePointMaxProfile_JSON );
  9658. fptr1 = fopen(filename, "r");
  9659. if (!fptr1)
  9660. {
  9661. //file not exist
  9662. DEBUG_INFO("Unable to open the input file!!\n");
  9663. fptr1 = fopen(filename, "w+");
  9664. }
  9665. else
  9666. {
  9667. //Check Charging Profile Count
  9668. while(fscanf(fptr1, "%s", word) != EOF)
  9669. {
  9670. //DEBUG_INFO("word=%s\n",word);
  9671. if(strstr(word, "chargingProfileId")!= NULL)
  9672. {
  9673. //DEBUG_INFO("test chargingProfileId \n");
  9674. n_chargingProfile = n_chargingProfile + 1;
  9675. //DEBUG_INFO("chargingProfileId Found\n");
  9676. }
  9677. }
  9678. }
  9679. fclose(fptr1);
  9680. }
  9681. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9682. {
  9683. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9684. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9685. {
  9686. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9687. goto end;
  9688. }
  9689. memset(filename, 0, ARRAY_SIZE(filename));
  9690. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9691. fptr1 = fopen(filename, "r");
  9692. if (!fptr1)
  9693. {
  9694. //file not exist
  9695. //DEBUG_INFO("Unable to open the input file!!\n");
  9696. fptr1 = fopen(filename, "w+");
  9697. }
  9698. else
  9699. {
  9700. //Check Charging Profile Count
  9701. while(fscanf(fptr1, "%s", word) != EOF)
  9702. {
  9703. //DEBUG_INFO("word=%s\n",word);
  9704. if(strstr(word, "chargingProfileId")!= NULL)
  9705. {
  9706. //DEBUG_INFO("test chargingProfileId \n");
  9707. n_chargingProfile = n_chargingProfile + 1;
  9708. //DEBUG_INFO("chargingProfileId Found\n");
  9709. }
  9710. }
  9711. }
  9712. fclose(fptr1);
  9713. }
  9714. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9715. {
  9716. //printf("set chargingProfile 1-4\n");
  9717. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9718. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9719. if(connectorIdInt == 0)
  9720. {
  9721. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9722. goto end;
  9723. }
  9724. int tempIndex = 0;
  9725. //check Transaction active
  9726. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9727. {
  9728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9729. {
  9730. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9731. }
  9732. else
  9733. {
  9734. tempIndex = connectorIdInt -1;
  9735. }
  9736. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9737. {
  9738. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9739. {
  9740. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9741. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9742. {
  9743. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9744. {
  9745. meet = TRUE;
  9746. break;
  9747. }
  9748. }
  9749. }
  9750. }
  9751. }
  9752. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9753. {
  9754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9755. {
  9756. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9757. }
  9758. else
  9759. {
  9760. tempIndex = connectorIdInt -1;
  9761. }
  9762. for (int index = 0; index < CCS_QUANTITY; index++)
  9763. {
  9764. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9765. {
  9766. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9767. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9768. {
  9769. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9770. {
  9771. meet = TRUE;
  9772. break;
  9773. }
  9774. }
  9775. }
  9776. }
  9777. }
  9778. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9779. {
  9780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9781. {
  9782. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9783. }
  9784. else
  9785. {
  9786. tempIndex = connectorIdInt -1;
  9787. }
  9788. for (int index = 0; index < GB_QUANTITY; index++)
  9789. {
  9790. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9791. {
  9792. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9793. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9794. {
  9795. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9796. {
  9797. meet = TRUE;
  9798. break;
  9799. }
  9800. }
  9801. }
  9802. }
  9803. }
  9804. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9805. {
  9806. tempIndex = connectorIdInt -1;
  9807. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9808. {
  9809. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9810. {
  9811. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9812. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9813. {
  9814. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9815. {
  9816. meet = TRUE;
  9817. break;
  9818. }
  9819. }
  9820. }
  9821. }
  9822. }
  9823. else
  9824. {
  9825. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9826. {
  9827. tempIndex = 2;
  9828. }
  9829. else
  9830. {
  9831. tempIndex = (connectorIdInt -1);
  9832. }
  9833. for (int index = 0; index < AC_QUANTITY; index++)
  9834. {
  9835. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9836. {
  9837. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9838. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9839. {
  9840. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9841. {
  9842. meet = TRUE;
  9843. break;
  9844. }
  9845. }
  9846. }
  9847. }
  9848. }
  9849. //check Transaction active
  9850. if(meet == FALSE)
  9851. {
  9852. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9853. goto end;
  9854. }
  9855. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9856. {
  9857. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9858. goto end;
  9859. }
  9860. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9861. fptr1 = fopen(filename, "r");
  9862. if (!fptr1)
  9863. {
  9864. //file not exist
  9865. DEBUG_INFO("Unable to open the input file!!\n");
  9866. fptr1 = fopen(filename, "w+");
  9867. }
  9868. else
  9869. {
  9870. //Check Charging Profile Count
  9871. while(fscanf(fptr1, "%s", word) != EOF)
  9872. {
  9873. //DEBUG_INFO("word=%s\n",word);
  9874. if(strstr(word, "chargingProfileId")!= NULL)
  9875. {
  9876. //DEBUG_INFO("test chargingProfileId \n");
  9877. n_chargingProfile = n_chargingProfile + 1;
  9878. //DEBUG_INFO("chargingProfileId Found\n");
  9879. }
  9880. }
  9881. }
  9882. fclose(fptr1);
  9883. }
  9884. // Check ChargeProfileMaxStackLevel
  9885. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9886. {
  9887. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9888. goto end;
  9889. }
  9890. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9891. {
  9892. int i = 0;
  9893. char fnametemp[200]={0};
  9894. n_chargingProfile = 0;
  9895. //Check ChargePointMaxProfile.json exit
  9896. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9897. {
  9898. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9899. //Check Charging Profile Count
  9900. while(fscanf(fptr1, "%s", word) != EOF)
  9901. {
  9902. //DEBUG_INFO("word=%s\n",word);
  9903. if(strstr(word, "chargingProfileId")!= NULL)
  9904. {
  9905. //DEBUG_INFO("test chargingProfileId \n");
  9906. n_chargingProfile = n_chargingProfile + 1;
  9907. i = i + 1;
  9908. //DEBUG_INFO("chargingProfileId Found\n");
  9909. }
  9910. memset(word, 0, ARRAY_SIZE(word));
  9911. }
  9912. fclose(fptr1);
  9913. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9914. }
  9915. //Check TxDefaultProfile_0.json exit
  9916. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9917. {
  9918. i = 0;
  9919. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9920. //Check Charging Profile Count
  9921. while(fscanf(fptr1, "%s", word) != EOF)
  9922. {
  9923. //DEBUG_INFO("word=%s\n",word);
  9924. if(strstr(word, "chargingProfileId")!= NULL)
  9925. {
  9926. //DEBUG_INFO("test chargingProfileId \n");
  9927. n_chargingProfile = n_chargingProfile + 1;
  9928. i = i + 1;
  9929. //DEBUG_INFO("chargingProfileId Found\n");
  9930. }
  9931. memset(word, 0, ARRAY_SIZE(word));
  9932. }
  9933. fclose(fptr1);
  9934. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9935. }
  9936. //Check TxDefaultProfile_%d.json
  9937. for(int j=1; j <= gunTotalNumber; j++)
  9938. {
  9939. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9940. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9941. if((access(fnametemp,F_OK))!=-1)
  9942. {
  9943. i = 0;
  9944. fptr1 = fopen(fnametemp, "r");
  9945. //Check Charging Profile Count
  9946. while(fscanf(fptr1, "%s", word) != EOF)
  9947. {
  9948. //DEBUG_INFO("word=%s\n",word);
  9949. if(strstr(word, "chargingProfileId")!= NULL)
  9950. {
  9951. //DEBUG_INFO("test chargingProfileId \n");
  9952. n_chargingProfile = n_chargingProfile + 1;
  9953. i = i + 1;
  9954. //DEBUG_INFO("chargingProfileId Found\n");
  9955. }
  9956. memset(word, 0, ARRAY_SIZE(word));
  9957. }
  9958. fclose(fptr1);
  9959. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9960. }
  9961. }
  9962. //Check TxProfile_%d.json
  9963. for(int j=1; j <= gunTotalNumber; j++)
  9964. {
  9965. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9966. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9967. if((access(fnametemp,F_OK))!=-1)
  9968. {
  9969. i = 0;
  9970. fptr1 = fopen(fnametemp, "r");
  9971. //Check Charging Profile Count
  9972. while(fscanf(fptr1, "%s", word) != EOF)
  9973. {
  9974. //DEBUG_INFO("word=%s\n",word);
  9975. if(strstr(word, "chargingProfileId")!= NULL)
  9976. {
  9977. //DEBUG_INFO("test chargingProfileId \n");
  9978. n_chargingProfile = n_chargingProfile + 1;
  9979. i = i + 1;
  9980. //DEBUG_INFO("chargingProfileId Found\n");
  9981. }
  9982. memset(word, 0, ARRAY_SIZE(word));
  9983. }
  9984. fclose(fptr1);
  9985. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9986. }
  9987. }
  9988. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9989. {
  9990. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9991. goto end;
  9992. }
  9993. }
  9994. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9995. //**********************************Write to File********************************************************/
  9996. FILE *infile;
  9997. FILE *outfile;
  9998. infile = fopen (filename, "r");
  9999. outfile = fopen (tempfile, "w");
  10000. int d =0;
  10001. d = fgetc(infile);
  10002. rewind(infile);
  10003. if(d == EOF)
  10004. {
  10005. // Profile is empty
  10006. fprintf(outfile,"%s\n",payload);
  10007. fclose(infile);
  10008. fclose(outfile);
  10009. sprintf(rmFileCmd,"rm -f %s",filename);
  10010. system(rmFileCmd);
  10011. rename(tempfile, filename);
  10012. }
  10013. else
  10014. {
  10015. // Profile is not empty
  10016. char buf[2048]={0};
  10017. int ChargingProfileAdded = FALSE;
  10018. while (fgets(buf, sizeof(buf), infile) != NULL)
  10019. {
  10020. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10021. json_object *tmpChargingProfile;
  10022. tmpChargingProfile = json_tokener_parse(buf);
  10023. if(!is_error(SetChargingProfile))
  10024. {
  10025. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10026. {
  10027. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10028. }
  10029. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10030. {
  10031. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10032. {
  10033. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10034. }
  10035. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10036. {
  10037. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10038. }
  10039. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10040. {
  10041. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10042. }
  10043. }
  10044. }
  10045. json_object_put(tmpChargingProfile);
  10046. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10047. {
  10048. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10049. {
  10050. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10051. if(ChargingProfileAdded == FALSE)
  10052. {
  10053. fprintf(outfile,"%s\n",payload);
  10054. ChargingProfileAdded = TRUE;
  10055. }
  10056. }
  10057. else
  10058. {
  10059. if(tempstackLevelInt < stackLevelInt)
  10060. {
  10061. if(ChargingProfileAdded == FALSE)
  10062. {
  10063. fprintf(outfile,"%s\n",buf);
  10064. fprintf(outfile,"%s\n",payload);
  10065. ChargingProfileAdded = TRUE;
  10066. }
  10067. else
  10068. {
  10069. fprintf(outfile,"%s\n",buf);
  10070. }
  10071. }
  10072. else
  10073. {
  10074. if(ChargingProfileAdded == FALSE)
  10075. {
  10076. fprintf(outfile,"%s\n",buf);
  10077. fprintf(outfile,"%s\n",payload);
  10078. ChargingProfileAdded = TRUE;
  10079. }
  10080. else
  10081. {
  10082. fprintf(outfile,"%s\n",buf);
  10083. }
  10084. }
  10085. }
  10086. }
  10087. else
  10088. {
  10089. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10090. {
  10091. if(ChargingProfileAdded == FALSE)
  10092. {
  10093. fprintf(outfile,"%s\n",buf);
  10094. fprintf(outfile,"%s\n",payload);
  10095. ChargingProfileAdded = TRUE;
  10096. }
  10097. else
  10098. {
  10099. fprintf(outfile,"%s\n",buf);
  10100. }
  10101. }
  10102. else if(tempstackLevelInt < stackLevelInt)
  10103. {
  10104. if(ChargingProfileAdded == FALSE)
  10105. {
  10106. fprintf(outfile,"%s\n",buf);
  10107. fprintf(outfile,"%s\n",payload);
  10108. ChargingProfileAdded = TRUE;
  10109. }
  10110. else
  10111. {
  10112. fprintf(outfile,"%s\n",buf);
  10113. }
  10114. }
  10115. else
  10116. {
  10117. if(ChargingProfileAdded == FALSE)
  10118. {
  10119. fprintf(outfile,"%s\n",buf);
  10120. fprintf(outfile,"%s\n",payload);
  10121. ChargingProfileAdded = TRUE;
  10122. }
  10123. else
  10124. {
  10125. fprintf(outfile,"%s\n",buf);
  10126. }
  10127. }
  10128. }
  10129. } // end of while loop
  10130. fclose(infile);
  10131. fclose(outfile);
  10132. sprintf(rmFileCmd,"rm -f %s",filename);
  10133. system(rmFileCmd);
  10134. rename(tempfile, filename);
  10135. }
  10136. sleep(1);
  10137. result = TRUE;
  10138. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10139. end:
  10140. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10141. {
  10142. if(connectorIdInt == 0)
  10143. {
  10144. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10145. {
  10146. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10147. }
  10148. }
  10149. else
  10150. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10151. }
  10152. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10153. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10154. return result;
  10155. }
  10156. int handleTriggerMessageRequest(char *uuid, char *payload)
  10157. {
  10158. mtrace();
  10159. int result = FAIL;
  10160. int connectorIdIsNULL = FALSE;
  10161. int connectorIdInt =0;
  10162. char sstr[40]={0},sstrtemp[100]={ 0 };
  10163. char requestedMessagestr[40]={0};
  10164. char comfirmstr[20]={0};
  10165. int c = 0;
  10166. char *loc;
  10167. DEBUG_INFO("handleTriggerMessageRequest\n");
  10168. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10169. strcpy(sstrtemp, stringtrimspace(payload));
  10170. c = 0;
  10171. loc = strstr(sstrtemp, "requestedMessage");
  10172. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10173. {
  10174. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10175. c++;
  10176. }
  10177. sstr[c] = '\0';
  10178. strcpy(requestedMessagestr, sstr);
  10179. c = 0;
  10180. loc = strstr(sstrtemp, "connectorId");
  10181. if(loc == NULL)
  10182. {
  10183. connectorIdIsNULL = TRUE;
  10184. }
  10185. else
  10186. {
  10187. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10188. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10189. {
  10190. sstr[c] = loc[strlen("connectorId")+2+c];
  10191. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10192. c++;
  10193. }
  10194. sstr[c] = '\0';
  10195. connectorIdInt = atoi(sstr);
  10196. }
  10197. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10198. {
  10199. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10200. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10201. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10202. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10203. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10204. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10205. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10206. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10207. {
  10208. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10209. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10210. return TRUE;
  10211. }
  10212. else
  10213. {
  10214. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10215. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10216. }
  10217. }
  10218. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10219. {
  10220. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10221. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10222. return TRUE;
  10223. }
  10224. //==========================
  10225. // Trigger message
  10226. //==========================
  10227. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10228. {
  10229. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10230. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10231. {
  10232. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10233. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10234. }
  10235. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10236. }
  10237. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10238. {
  10239. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10240. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10241. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10242. }
  10243. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10244. {
  10245. //sendBootNotificationRequest();
  10246. server_sign = FALSE;
  10247. }
  10248. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10249. {
  10250. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10251. }
  10252. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10253. {
  10254. if(connectorIdIsNULL == FALSE)
  10255. {
  10256. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10257. {
  10258. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10259. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10260. }
  10261. }
  10262. else
  10263. {
  10264. for(int idx=0;idx< gunTotalNumber;idx++)
  10265. {
  10266. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10267. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10268. }
  10269. }
  10270. }
  10271. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10272. {
  10273. if(connectorIdIsNULL == FALSE)
  10274. {
  10275. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10276. {
  10277. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10278. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10279. }
  10280. }
  10281. else
  10282. {
  10283. for(int idx=0;idx< gunTotalNumber;idx++)
  10284. {
  10285. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10286. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10287. }
  10288. }
  10289. }
  10290. return result;
  10291. }
  10292. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10293. {
  10294. mtrace();
  10295. int result = FAIL;
  10296. int connectorIdInt =0;
  10297. char comfirmstr[20]={0};
  10298. int tempIndex = 0;
  10299. json_object *UnlockConnector;
  10300. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10301. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10302. UnlockConnector = json_tokener_parse(payload);
  10303. if(!is_error(UnlockConnector))
  10304. {
  10305. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10306. {
  10307. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10308. }
  10309. }
  10310. json_object_put(UnlockConnector);
  10311. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10312. if(gunTotalNumber == 0)
  10313. {
  10314. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10315. goto end;
  10316. }
  10317. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10318. {
  10319. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10320. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10321. goto end;
  10322. }
  10323. else
  10324. {
  10325. //check Transaction active
  10326. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10327. {
  10328. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10329. {
  10330. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10331. }
  10332. else
  10333. {
  10334. tempIndex = connectorIdInt -1;
  10335. }
  10336. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10337. {
  10338. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10339. {
  10340. //stop Transaction
  10341. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10342. }
  10343. }
  10344. }
  10345. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10346. {
  10347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10348. {
  10349. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10350. }
  10351. else
  10352. {
  10353. tempIndex = connectorIdInt -1;
  10354. }
  10355. for (int index = 0; index < CCS_QUANTITY; index++)
  10356. {
  10357. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10358. {
  10359. //stop Transaction
  10360. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10361. }
  10362. }
  10363. }
  10364. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10365. {
  10366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10367. {
  10368. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10369. }
  10370. else
  10371. {
  10372. tempIndex = connectorIdInt -1;
  10373. }
  10374. for (int index = 0; index < GB_QUANTITY; index++)
  10375. {
  10376. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10377. {
  10378. //stop Transaction
  10379. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10380. }
  10381. }
  10382. }
  10383. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10384. {
  10385. tempIndex = connectorIdInt -1;
  10386. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10387. {
  10388. 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)))
  10389. {
  10390. //stop Transaction
  10391. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10392. }
  10393. }
  10394. }
  10395. else
  10396. {
  10397. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10398. {
  10399. tempIndex = 2;
  10400. }
  10401. else
  10402. {
  10403. tempIndex = connectorIdInt-1;
  10404. }
  10405. for (int index = 0; index < AC_QUANTITY; index++)
  10406. {
  10407. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10408. {
  10409. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10410. }
  10411. }
  10412. }
  10413. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10414. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10415. result = TRUE;
  10416. return result;
  10417. }
  10418. end:
  10419. //json_object_put(obj); --- remove temporally
  10420. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10421. return result;
  10422. }
  10423. static char UpdateFirmwarepayloadData[300]={0};
  10424. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10425. {
  10426. mtrace();
  10427. int result = FAIL;
  10428. pthread_t t;
  10429. sendUpdateFirmwareConfirmation(uuid);
  10430. memset(UpdateFirmwarepayloadData, 0, 300);
  10431. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10432. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10433. ////pthread_join(t, NULL); //
  10434. //pthread_detach(t);
  10435. //sendUpdateFirmwareConfirmation(uuid);
  10436. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10437. return result;
  10438. }
  10439. void *UpdateFirmwareProcess(void *data)
  10440. {
  10441. pthread_detach(pthread_self());
  10442. mtrace();
  10443. int retriesInt =0, retryIntervalInt=0;
  10444. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  10445. int port=0;
  10446. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  10447. int isSuccess = 0;
  10448. char ftpbuf[1024];
  10449. char temp[1024];
  10450. char * pch;
  10451. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10452. json_object *UpdateFirmware;
  10453. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10454. if(!is_error(UpdateFirmware))
  10455. {
  10456. // Required data
  10457. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10458. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10459. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10460. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10461. // Optional data
  10462. if(json_object_object_get(UpdateFirmware, "retries"))
  10463. {
  10464. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10465. }
  10466. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10467. {
  10468. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10469. }
  10470. }
  10471. json_object_put(UpdateFirmware);
  10472. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10473. memset(path, 0, ARRAY_SIZE(path));
  10474. // Wait retrieveData
  10475. if(strlen(retrieveDatestr) > 10)
  10476. {
  10477. do
  10478. {
  10479. sleep(1);
  10480. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10481. }
  10482. // Ready to download
  10483. system("rm -f /mnt/*");
  10484. if(strncmp(locationstr,"http", 4) == 0)
  10485. {
  10486. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10487. sprintf(ftppath,"/%s", path);
  10488. DEBUG_INFO("locationstr: %s\n", locationstr);
  10489. DEBUG_INFO("protocol: %s\n",protocol);
  10490. DEBUG_INFO("host: %s\n",host);
  10491. DEBUG_INFO("path: %s\n",path);
  10492. DEBUG_INFO("ftppath: %s\n",ftppath);
  10493. int ftppathlen=strlen(ftppath);
  10494. int i=1;
  10495. char filenametemp[50];
  10496. while(i < ftppathlen)
  10497. {
  10498. int len=ftppathlen-i;
  10499. if(ftppath[len]== 47) // '/' ascll code: 47
  10500. {
  10501. DEBUG_INFO("compare '/' all right\n");
  10502. break;
  10503. }
  10504. i=i+1;
  10505. }
  10506. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10507. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10508. filenametemp[i+1] = 0;
  10509. do
  10510. {
  10511. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10512. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10513. sleep(1);
  10514. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10515. if(!isSuccess)
  10516. {
  10517. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10518. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10519. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10520. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10521. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10522. }
  10523. else
  10524. {
  10525. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10526. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10527. }
  10528. retriesInt--;
  10529. }while((isSuccess == 0)&&(retriesInt >= 0));
  10530. }
  10531. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10532. {
  10533. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10534. memset(temp, 0, ARRAY_SIZE(temp));
  10535. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10536. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10537. int ftppathlen=strlen(ftpbuf);
  10538. int i=1;
  10539. char filenametemp[50];
  10540. while(i < ftppathlen)
  10541. {
  10542. int len=ftppathlen-i;
  10543. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10544. {
  10545. DEBUG_INFO(" compare '/' all right\n");
  10546. break;
  10547. }
  10548. i=i+1;
  10549. }
  10550. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10551. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10552. filenametemp[i+1] = 0;
  10553. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10554. pch=strchr(temp,'@');
  10555. if(pch==NULL)
  10556. {
  10557. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10558. protocol, host, &port, path);
  10559. strcpy(user,"anonymous");
  10560. strcpy(password,"");
  10561. }
  10562. else
  10563. {
  10564. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10565. protocol, user, password, host, &port, path);
  10566. }
  10567. sscanf(host,"%[^/]%s",host1, path1);
  10568. sprintf(ftppath,"%s", path1);
  10569. //DEBUG_INFO("protocol =%s\n",protocol);
  10570. //DEBUG_INFO("user =%s\n",user);
  10571. //DEBUG_INFO("password =%s\n",password);
  10572. //DEBUG_INFO("host1 =%s\n",host1);
  10573. //DEBUG_INFO("port =%d\n",port);
  10574. //DEBUG_INFO("path1 =%s\n",path1);
  10575. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10576. //ftpFile(host, user, password, port, ftppath, fname);
  10577. //download firmware pthred
  10578. if(port == 0)
  10579. {
  10580. port = 21;
  10581. }
  10582. do
  10583. {
  10584. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10585. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10586. sleep(1);
  10587. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10588. if(!isSuccess)
  10589. {
  10590. //BulldogUtil.sleepMs(interval*1000);
  10591. DEBUG_INFO("Update firmware request and download file fail.\n");
  10592. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10593. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10594. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10595. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10596. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10597. }
  10598. else
  10599. {
  10600. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10601. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10602. }
  10603. retriesInt--;
  10604. }while((!isSuccess)&&(retriesInt >= 0));
  10605. }
  10606. else
  10607. {
  10608. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10609. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10610. sleep(1);
  10611. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10612. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10613. }
  10614. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10615. pthread_exit(NULL);
  10616. }
  10617. int handleCertificateSignedRequest(char *uuid, char *payload)
  10618. {
  10619. mtrace();
  10620. int result = PASS;
  10621. json_object *CertificateSigned;
  10622. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10623. CertificateSigned = json_tokener_parse(payload);
  10624. if(!is_error(CertificateSigned))
  10625. {
  10626. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10627. }
  10628. json_object_put(CertificateSigned);
  10629. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10630. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10631. fclose(fp);
  10632. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10633. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10634. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10635. sendCertificateSignedConfirmation(uuid);
  10636. return result;
  10637. }
  10638. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10639. {
  10640. mtrace();
  10641. int result = PASS;
  10642. json_object *DeleteCertificate;
  10643. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10644. DeleteCertificate = json_tokener_parse(payload);
  10645. if(!is_error(DeleteCertificate))
  10646. {
  10647. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10648. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10649. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10650. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10651. }
  10652. json_object_put(DeleteCertificate);
  10653. /*
  10654. * TODO: Delete certificateSigned process
  10655. */
  10656. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10657. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10658. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10659. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10660. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10661. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10662. sendDeleteCertificateConfirmation(uuid);
  10663. return result;
  10664. }
  10665. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10666. {
  10667. mtrace();
  10668. int result = PASS;
  10669. json_object *ExtendedTriggerMessage;
  10670. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10671. ExtendedTriggerMessage = json_tokener_parse(payload);
  10672. if(!is_error(ExtendedTriggerMessage))
  10673. {
  10674. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10675. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10676. {
  10677. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10678. }
  10679. else
  10680. {
  10681. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10682. }
  10683. }
  10684. json_object_put(ExtendedTriggerMessage);
  10685. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10686. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10687. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10688. {
  10689. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10690. }
  10691. else
  10692. {
  10693. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10694. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10695. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10696. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10697. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10698. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10699. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10700. {
  10701. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10702. }
  10703. else
  10704. {
  10705. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10706. }
  10707. }
  10708. sendExtendedTriggerMessageConfirmation(uuid);
  10709. //==========================
  10710. // Trigger message
  10711. //==========================
  10712. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10713. {
  10714. //sendBootNotificationRequest();
  10715. server_sign = FALSE;
  10716. }
  10717. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10718. {
  10719. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10720. }
  10721. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10722. {
  10723. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10724. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10725. {
  10726. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10727. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10728. }
  10729. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10730. }
  10731. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10732. {
  10733. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10734. }
  10735. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10736. {
  10737. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10738. {
  10739. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10740. }
  10741. else
  10742. {
  10743. for(int idx=0;idx< gunTotalNumber;idx++)
  10744. {
  10745. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10746. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10747. }
  10748. }
  10749. }
  10750. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10751. {
  10752. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10753. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10754. {
  10755. 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\" &");
  10756. }
  10757. }
  10758. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10759. {
  10760. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10761. {
  10762. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10763. }
  10764. else
  10765. {
  10766. for(int idx=0;idx< gunTotalNumber;idx++)
  10767. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10768. }
  10769. }
  10770. return result;
  10771. }
  10772. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10773. {
  10774. mtrace();
  10775. int result = PASS;
  10776. json_object *GetInstalledCertificateIds;
  10777. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10778. GetInstalledCertificateIds = json_tokener_parse(payload);
  10779. if(!is_error(GetInstalledCertificateIds))
  10780. {
  10781. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10782. }
  10783. json_object_put(GetInstalledCertificateIds);
  10784. /*
  10785. * TODO: Return installed certificate process
  10786. */
  10787. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10788. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10789. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10790. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10791. sendGetInstalledCertificateIdsConfirmation(uuid);
  10792. return result;
  10793. }
  10794. int handleGetLogRequest(char *uuid, char *payload)
  10795. {
  10796. mtrace();
  10797. int result = PASS;
  10798. json_object *GetLog;
  10799. DEBUG_INFO("handleGetLogRequest...\n");
  10800. GetLog = json_tokener_parse(payload);
  10801. if(!is_error(GetLog))
  10802. {
  10803. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10804. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10805. if(json_object_object_get(GetLog, "retries") != NULL)
  10806. {
  10807. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10808. }
  10809. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10810. {
  10811. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10812. }
  10813. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10814. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10815. {
  10816. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10817. }
  10818. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10819. {
  10820. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10821. }
  10822. }
  10823. json_object_put(GetLog);
  10824. /*
  10825. * TODO: Upload log process
  10826. */
  10827. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10828. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10829. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10830. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10831. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10832. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10833. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10834. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10835. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10836. sendGetLogConfirmation(uuid);
  10837. return result;
  10838. }
  10839. int handleInstallCertificateRequest(char *uuid, char *payload)
  10840. {
  10841. mtrace();
  10842. int result = PASS;
  10843. json_object *InstallCertificate;
  10844. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10845. InstallCertificate = json_tokener_parse(payload);
  10846. if(!is_error(InstallCertificate))
  10847. {
  10848. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10849. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10850. /*
  10851. * TODO: Install certificate process
  10852. */
  10853. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10854. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10855. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10856. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10857. sendInstallCertificateConfirmation(uuid);
  10858. }
  10859. json_object_put(InstallCertificate);
  10860. return result;
  10861. }
  10862. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10863. {
  10864. mtrace();
  10865. int result = PASS;
  10866. json_object *SignedUpdateFirmware;
  10867. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10868. SignedUpdateFirmware = json_tokener_parse(payload);
  10869. if(!is_error(SignedUpdateFirmware))
  10870. {
  10871. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10872. {
  10873. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10874. }
  10875. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10876. {
  10877. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10878. }
  10879. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10880. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10881. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10882. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10883. {
  10884. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10885. }
  10886. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10887. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10888. }
  10889. json_object_put(SignedUpdateFirmware);
  10890. /*
  10891. * TODO: Upgrade firmware process
  10892. */
  10893. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10894. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10895. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10896. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10897. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10898. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10899. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10900. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10901. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10902. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10903. sendInstallCertificateConfirmation(uuid);
  10904. return result;
  10905. }
  10906. int handleUnknownRequest(char *uuid, char *payload)
  10907. {
  10908. mtrace();
  10909. int result = PASS;
  10910. DEBUG_INFO("handleUnknownRequest...\n");
  10911. sendUnknownConfirmation(uuid);
  10912. result = PASS;
  10913. return result;
  10914. }
  10915. //==========================================
  10916. // Handle server response routine
  10917. //==========================================
  10918. void handleAuthorizeResponse(char *payload, int gun_index)
  10919. {
  10920. mtrace();
  10921. char expiryDatestr[30]={0};
  10922. char parentIdTagstr[20]={0};
  10923. char statusstr[20]={0};
  10924. int expiryDateISNULL=FALSE;
  10925. int parentIdTagISNULL=FALSE;
  10926. DEBUG_INFO("handleAuthorizeResponse...\n");
  10927. json_object *Authorize;
  10928. Authorize = json_tokener_parse(payload);
  10929. if(!is_error(Authorize))
  10930. {
  10931. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10932. {
  10933. // Required data
  10934. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10935. // Optional data
  10936. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10937. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10938. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10939. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10940. }
  10941. }
  10942. json_object_put(Authorize);
  10943. if(expiryDateISNULL == FALSE)
  10944. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10945. if(parentIdTagISNULL == FALSE)
  10946. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10947. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10948. //Update idTag information to authorization cache if supproted
  10949. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10950. {
  10951. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10952. }
  10953. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10954. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10955. authorizeRetryTimes = 0;
  10956. }
  10957. void handleBootNotificationResponse(char *payload, int gun_index)
  10958. {
  10959. mtrace();
  10960. char statusStr[12]={0};
  10961. char currentTimeStr[30]={0};
  10962. int intervalInt = 0;
  10963. DEBUG_INFO("handleBootNotificationResponse...\n");
  10964. json_object *BootNotification;
  10965. BootNotification = json_tokener_parse(payload);
  10966. if(!is_error(BootNotification))
  10967. {
  10968. // Required data
  10969. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10970. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10971. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10972. }
  10973. json_object_put(BootNotification);
  10974. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10975. BootNotificationInterval = intervalInt;
  10976. HeartBeatWaitTime = intervalInt;
  10977. //write back to ShmOCPP16Data->BootNotification
  10978. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10979. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10980. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10981. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10982. {
  10983. server_sign = TRUE;
  10984. server_pending =FALSE;
  10985. }
  10986. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10987. {
  10988. server_pending = TRUE;
  10989. }
  10990. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  10991. srand(time(NULL));
  10992. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10993. SetOcppConnStatus(TRUE);
  10994. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10995. }
  10996. void handleDataTransferResponse(char *payload, int gun_index)
  10997. {
  10998. char sstr[160]={0};//sstr[200]={ 0 };
  10999. int c = 0;
  11000. char *loc;
  11001. DEBUG_INFO("handleDataTransferResponse ...\n");
  11002. loc = strstr(payload, "status");
  11003. printf("loc=%s\n",loc);
  11004. c = 0;
  11005. while (loc[3+strlen("status")+c] != '\"')
  11006. {
  11007. sstr[c] = loc[3+strlen("status")+c];
  11008. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11009. c++;
  11010. }
  11011. sstr[c] = '\0';
  11012. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11013. }
  11014. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11015. {
  11016. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11017. //struct json_object *obj;
  11018. // obj = json_tokener_parse(payload);
  11019. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11020. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11021. //No fields are defined.
  11022. }
  11023. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11024. {
  11025. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11026. //struct json_object *obj;
  11027. // obj = json_tokener_parse(payload);
  11028. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11029. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11030. //No fields are defined.
  11031. }
  11032. void handleHeartbeatResponse(char *payload, int gun_index)
  11033. {
  11034. mtrace();
  11035. DEBUG_INFO("handleHeartbeatResponse...\n");
  11036. json_object *Heartbeat;
  11037. Heartbeat = json_tokener_parse(payload);
  11038. if(!is_error(Heartbeat))
  11039. {
  11040. // Required data
  11041. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11042. }
  11043. json_object_put(Heartbeat);
  11044. if(FirstHeartBeat == 0)
  11045. {
  11046. FirstHeartBeat = 1;
  11047. DEBUG_INFO("FirstHeartBeat \n");
  11048. }
  11049. HeartBeatWithNOResponse = 0;
  11050. clientTime.Heartbeat=time((time_t*)NULL);
  11051. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11052. }
  11053. void handleMeterValuesResponse(char *payload, int gun_index)
  11054. {
  11055. mtrace();
  11056. DEBUG_INFO("handleMeterValuesResponse...\n");
  11057. }
  11058. void handleStartTransactionResponse(char *payload, int gun_index)
  11059. {
  11060. mtrace();
  11061. //int transactionIdInt = 0;
  11062. FILE *outfile;
  11063. char data[100]={0};
  11064. DEBUG_INFO("handleStartTransactionResponse...\n");
  11065. json_object *StartTransaction;
  11066. StartTransaction = json_tokener_parse(payload);
  11067. if(!is_error(StartTransaction))
  11068. {
  11069. // Required data
  11070. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11071. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11072. // Optional data
  11073. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11074. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11075. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11076. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11077. }
  11078. json_object_put(StartTransaction);
  11079. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11080. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11081. //-----------Start : write to the Queue TransactionId file -----------------//
  11082. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11083. {}
  11084. else
  11085. {
  11086. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11087. if(log == NULL)
  11088. {
  11089. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11090. return ;
  11091. }
  11092. else
  11093. {
  11094. fclose(log);
  11095. }
  11096. }
  11097. // open file for writing
  11098. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11099. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11100. {
  11101. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11102. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11103. fputs(data, outfile);
  11104. fclose (outfile);
  11105. }
  11106. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11107. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11108. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11109. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11110. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11111. }
  11112. void handleStatusNotificationResponse(char *payload, int gun_index)
  11113. {
  11114. mtrace();
  11115. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11116. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11117. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11118. }
  11119. void handleStopTransactionnResponse(char *payload, int gun_index)
  11120. {
  11121. mtrace();
  11122. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11123. json_object *StopTransaction;
  11124. StopTransaction = json_tokener_parse(payload);
  11125. if(!is_error(StopTransaction))
  11126. {
  11127. // Optional data
  11128. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11129. {
  11130. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11131. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11132. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11133. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11134. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11135. }
  11136. }
  11137. json_object_put(StopTransaction);
  11138. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11139. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11140. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11141. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11142. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11143. }
  11144. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11145. {
  11146. mtrace();
  11147. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11148. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11149. }
  11150. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11151. {
  11152. mtrace();
  11153. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11154. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11155. }
  11156. void handleSignCertificateResponse(char *payload, int gun_index)
  11157. {
  11158. mtrace();
  11159. DEBUG_INFO("handleSignCertificateResponse...\n");
  11160. json_object *SignCertificate;
  11161. SignCertificate = json_tokener_parse(payload);
  11162. if(!is_error(SignCertificate))
  11163. {
  11164. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11165. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11166. }
  11167. json_object_put(SignCertificate);
  11168. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11169. }
  11170. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11171. {
  11172. mtrace();
  11173. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11174. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11175. }
  11176. //==========================================
  11177. // Handle Error routine
  11178. //==========================================
  11179. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11180. {
  11181. mtrace();
  11182. #ifdef SystemLogMessage
  11183. DEBUG_INFO("errorCode: %s\n", errorCode);
  11184. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11185. DEBUG_INFO("errorDetails: %s\n", payload);
  11186. #endif
  11187. }
  11188. //===============================================
  11189. // Common routine
  11190. //===============================================
  11191. int initialConfigurationTable(void)
  11192. {
  11193. //clock_t start_t, end_t, total_t;
  11194. FILE *fp;
  11195. FILE *outfile;
  11196. char str[512]={0};
  11197. char sstr[256]={0};
  11198. int c = 0;
  11199. char *loc;
  11200. int confVersion = 2;
  11201. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11202. //start_t = clock();
  11203. //printf("Starting of the program, start_t = %ld\n", start_t);
  11204. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11205. // Check configuration file size is correct
  11206. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11207. {
  11208. struct stat st;
  11209. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11210. if(st.st_size < 3100)
  11211. {
  11212. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11213. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11214. }
  11215. }
  11216. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11217. {
  11218. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11219. if(outfile == NULL)
  11220. {
  11221. DEBUG_INFO("Error opening file\n");
  11222. return FALSE;
  11223. }
  11224. /*Core Profile*/
  11225. //AllowOfflineTxForUnknownId
  11226. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11230. //AuthorizationCacheEnabled
  11231. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11235. //AuthorizeRemoteTxRequests
  11236. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11240. //BlinkRepeat
  11241. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11245. //ClockAlignedDataInterval
  11246. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11250. //ConnectionTimeOut
  11251. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11255. //GetConfigurationMaxKeys
  11256. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11260. // HeartbeatInterval
  11261. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11265. // LightIntensity
  11266. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11270. // LocalAuthorizeOffline
  11271. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11275. // LocalPreAuthorize
  11276. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11280. // MaxEnergyOnInvalidId
  11281. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11285. // MeterValuesAlignedData
  11286. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11288. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11290. else
  11291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11293. // MeterValuesAlignedDataMaxLength
  11294. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11296. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11298. else
  11299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11301. // MeterValuesSampledData
  11302. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11304. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11306. else
  11307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11309. // MeterValuesSampledDataMaxLength
  11310. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11314. else
  11315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11317. // MeterValueSampleInterval
  11318. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11322. // MinimumStatusDuration
  11323. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11326. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11328. // NumberOfConnectors
  11329. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11332. {
  11333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11334. }
  11335. else
  11336. {
  11337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11338. }
  11339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11340. // ResetRetries
  11341. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11345. // ConnectorPhaseRotation
  11346. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11350. // ConnectorPhaseRotationMaxLength
  11351. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11355. // StopTransactionOnEVSideDisconnect
  11356. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11360. // StopTransactionOnInvalidId
  11361. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11365. // StopTxnAlignedData
  11366. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11370. // StopTxnAlignedDataMaxLength
  11371. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11375. // StopTxnSampledData
  11376. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11378. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11380. else
  11381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11383. // StopTxnSampledDataMaxLength
  11384. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11387. {
  11388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11389. }
  11390. else
  11391. {
  11392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11393. }
  11394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11395. // SupportedFeatureProfiles
  11396. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11400. // SupportedFeatureProfilesMaxLength
  11401. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11405. // TransactionMessageAttempts
  11406. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11409. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11411. // TransactionMessageRetryInterval
  11412. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11415. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11417. // UnlockConnectorOnEVSideDisconnect
  11418. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11422. // WebSocketPingInterval
  11423. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11427. // QueueOffLineStartTransactionMessage
  11428. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11432. // AuthorizationKey
  11433. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11437. // SecurityProfile
  11438. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11442. // DefaultPrice
  11443. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11447. // CustomDisplayCostAndPrice
  11448. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11452. // CustomIdleFeeAfterStop
  11453. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11457. // Configuration Version
  11458. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11462. //* Local Auth List Management Profile*/
  11463. #if 0
  11464. //For OCTT Test Case
  11465. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11468. #endif
  11469. #if 1
  11470. //LocalAuthListEnabled
  11471. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11475. #endif
  11476. //LocalAuthListMaxLength
  11477. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11481. //SendLocalListMaxLength
  11482. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11486. //ReserveConnectorZeroSupported
  11487. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11491. //* Smart Charging Profile */
  11492. //ChargeProfileMaxStackLevel
  11493. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11497. // ChargingScheduleAllowedChargingRateUnit
  11498. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11502. // ChargingScheduleMaxPeriods
  11503. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11507. // ConnectorSwitch3to1PhaseSupported
  11508. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11512. // MaxChargingProfilesInstalled
  11513. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11517. fclose(outfile);
  11518. }
  11519. else
  11520. {
  11521. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11522. char keystr[60]={0};
  11523. char readonlystr[10]={0};
  11524. char valuestr[256]={0};
  11525. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11526. if(fp == NULL) {
  11527. DEBUG_INFO("Error opening file");
  11528. return FALSE;
  11529. }
  11530. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11531. {
  11532. //DEBUG_INFO("Get Configuration \n");
  11533. if(strlen(str) > 0)
  11534. {
  11535. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11536. //*************************key*********************************/
  11537. if(strstr(str, "key") != NULL)
  11538. {
  11539. loc = strstr(str, "key");
  11540. c = 0;
  11541. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11542. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11543. {
  11544. sstr[c] = loc[strlen("key")+3+c];
  11545. c++;
  11546. }
  11547. sstr[c] = '\0';
  11548. strcpy(keystr,sstr);
  11549. }
  11550. //*************************readonly*********************************/
  11551. if(strstr(str, "readonly") != NULL)
  11552. {
  11553. loc = strstr(str, "readonly");
  11554. c = 0;
  11555. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11556. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11557. {
  11558. sstr[c] = loc[strlen("readonly")+2+c];
  11559. c++;
  11560. }
  11561. sstr[c] = '\0';
  11562. strcpy(readonlystr,sstr);
  11563. }
  11564. //*************************value*********************************/
  11565. if(strstr(str, "value") != NULL)
  11566. {
  11567. loc = strstr(str, "value");
  11568. c = 0;
  11569. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11570. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11571. {
  11572. sstr[c] = loc[strlen("value")+3+c];
  11573. c++;
  11574. }
  11575. sstr[c] = '\0';
  11576. strcpy(valuestr,sstr);
  11577. }
  11578. // DEBUG_INFO("keystr=%s\n",keystr);
  11579. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11580. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11581. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11582. {
  11583. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11584. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11586. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11587. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11588. }
  11589. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11590. {
  11591. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11592. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11594. }
  11595. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11596. {
  11597. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11599. }
  11600. if(strcmp(keystr, "BlinkRepeat") == 0)
  11601. {
  11602. //Charger.BlinkRepeat = Integer.parseInt(value);
  11603. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11605. }
  11606. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11607. {
  11608. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11610. }
  11611. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11612. {
  11613. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11615. }
  11616. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11617. {
  11618. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11620. }
  11621. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11622. {
  11623. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11625. HeartBeatWaitTime = atoi(valuestr);
  11626. }
  11627. if(strcmp(keystr, "LightIntensity") == 0)
  11628. {
  11629. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11631. }
  11632. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11633. {
  11634. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11636. }
  11637. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11638. {
  11639. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11641. }
  11642. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11643. {
  11644. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11646. }
  11647. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11648. {
  11649. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11651. }
  11652. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11653. {
  11654. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11656. }
  11657. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11658. {
  11659. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11661. }
  11662. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11663. {
  11664. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11666. }
  11667. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11668. {
  11669. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11671. }
  11672. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11673. {
  11674. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11676. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11677. }
  11678. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11679. {
  11680. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11682. }
  11683. if(strcmp(keystr, "ResetRetries") == 0)
  11684. {
  11685. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11687. }
  11688. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11689. {
  11690. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11692. }
  11693. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11694. {
  11695. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11697. }
  11698. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11699. {
  11700. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11702. }
  11703. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11704. {
  11705. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11707. }
  11708. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11709. {
  11710. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11712. }
  11713. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11714. {
  11715. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11717. }
  11718. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11719. {
  11720. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11722. }
  11723. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11724. {
  11725. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11727. }
  11728. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11729. {
  11730. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11732. }
  11733. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11734. {
  11735. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11737. }
  11738. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11739. {
  11740. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11742. TransactionMessageAttemptsValue = atoi(valuestr);
  11743. }
  11744. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11745. {
  11746. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11748. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11749. }
  11750. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11751. {
  11752. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11754. }
  11755. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11756. {
  11757. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11759. }
  11760. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11761. {
  11762. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11764. }
  11765. if(strcmp(keystr, "AuthorizationKey") == 0)
  11766. {
  11767. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11768. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11770. }
  11771. if(strcmp(keystr, "SecurityProfile") == 0)
  11772. {
  11773. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11775. }
  11776. if(strcmp(keystr, "DefaultPrice") == 0)
  11777. {
  11778. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11780. }
  11781. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11782. {
  11783. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11785. }
  11786. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11787. {
  11788. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11790. }
  11791. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11792. {
  11793. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11795. }
  11796. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11797. {
  11798. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11800. }
  11801. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11802. {
  11803. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11805. }
  11806. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11807. {
  11808. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11810. }
  11811. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11812. {
  11813. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11815. }
  11816. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11817. {
  11818. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11820. }
  11821. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11822. {
  11823. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11825. }
  11826. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11827. {
  11828. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11830. }
  11831. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11832. {
  11833. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11835. }
  11836. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11837. {
  11838. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11840. }
  11841. }
  11842. }
  11843. fclose(fp);
  11844. }
  11845. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11846. {
  11847. return PASS;
  11848. }
  11849. else
  11850. {
  11851. return FAIL;
  11852. }
  11853. }
  11854. void StoreConfigurationTable(void)
  11855. {
  11856. FILE *outfile;
  11857. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11858. if(outfile == NULL)
  11859. {
  11860. DEBUG_INFO("Error opening file");
  11861. return ;
  11862. }
  11863. /*Core Profile*/
  11864. //AllowOfflineTxForUnknownId
  11865. /*
  11866. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11867. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11870. */
  11871. //DEBUG_INFO("data=%s\n",data);
  11872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11873. //AuthorizationCacheEnabled
  11874. /*
  11875. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11878. */
  11879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11880. //AuthorizeRemoteTxRequests
  11881. /*
  11882. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11885. */
  11886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11887. //BlinkRepeat
  11888. /*
  11889. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11892. */
  11893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11894. //ClockAlignedDataInterval
  11895. /*
  11896. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11899. */
  11900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11901. //ConnectionTimeOut
  11902. /*
  11903. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11906. */
  11907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11908. //GetConfigurationMaxKeys
  11909. /*
  11910. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11913. */
  11914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11915. // HeartbeatInterval
  11916. /*
  11917. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11920. */
  11921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11922. // LightIntensity
  11923. /*
  11924. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11927. */
  11928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11929. // LocalAuthorizeOffline
  11930. /*
  11931. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11934. */
  11935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11936. // LocalPreAuthorize
  11937. /*
  11938. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11941. */
  11942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11943. // MaxEnergyOnInvalidId
  11944. /*
  11945. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11948. */
  11949. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11951. // MeterValuesAlignedData
  11952. /*
  11953. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11956. */
  11957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11958. // MeterValuesAlignedDataMaxLength
  11959. /*
  11960. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11963. */
  11964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11965. // MeterValuesSampledData
  11966. /*
  11967. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11970. */
  11971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11972. // MeterValuesSampledDataMaxLength
  11973. /*
  11974. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11977. */
  11978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11979. // MeterValueSampleInterval
  11980. /*
  11981. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11984. */
  11985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11986. // MinimumStatusDuration
  11987. /*
  11988. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11991. */
  11992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11993. // NumberOfConnectors
  11994. /*
  11995. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11997. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11998. {
  11999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12000. }
  12001. else
  12002. {
  12003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12004. }
  12005. */
  12006. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12007. // ResetRetries
  12008. /*
  12009. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12012. */
  12013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12014. // ConnectorPhaseRotation
  12015. /*
  12016. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12019. */
  12020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12021. // ConnectorPhaseRotationMaxLength
  12022. /*
  12023. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12026. */
  12027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12028. // StopTransactionOnEVSideDisconnect
  12029. /*
  12030. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12033. */
  12034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12035. // StopTransactionOnInvalidId
  12036. /*
  12037. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12040. */
  12041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12042. // StopTxnAlignedData
  12043. /*
  12044. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12047. */
  12048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12049. // StopTxnAlignedDataMaxLength
  12050. /*
  12051. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12054. */
  12055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12056. // StopTxnSampledData
  12057. /*
  12058. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12061. */
  12062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12063. // StopTxnSampledDataMaxLength
  12064. /*
  12065. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12068. */
  12069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12070. // SupportedFeatureProfiles
  12071. /*
  12072. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12075. */
  12076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12077. // SupportedFeatureProfilesMaxLength
  12078. /*
  12079. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12082. */
  12083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12084. // TransactionMessageAttempts
  12085. /*
  12086. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12089. */
  12090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12091. // TransactionMessageRetryInterval
  12092. /*
  12093. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12096. */
  12097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12098. // UnlockConnectorOnEVSideDisconnect
  12099. /*
  12100. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12103. */
  12104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12105. // WebSocketPingInterval
  12106. /*
  12107. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12110. */
  12111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12112. // QueueOffLineStartTransactionMessage
  12113. /*
  12114. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12117. */
  12118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12119. // AuthorizationKey
  12120. /*
  12121. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12124. */
  12125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12126. // SecurityProfile
  12127. /*
  12128. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12131. */
  12132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12133. // DefaultPrice
  12134. /*
  12135. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12138. */
  12139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12140. // CustomDisplayCostAndPrice
  12141. /*
  12142. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12145. */
  12146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12147. // CustomIdleFeeAfterStop
  12148. /*
  12149. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12152. */
  12153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12154. // ConfigurationVersion
  12155. /*
  12156. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12159. */
  12160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12161. //* Local Auth List Management Profile*/
  12162. //LocalAuthListEnabled
  12163. /*
  12164. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12167. */
  12168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12169. //LocalAuthListMaxLength
  12170. /*
  12171. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12174. */
  12175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12176. //SendLocalListMaxLength
  12177. /*
  12178. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12181. */
  12182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12183. //ReserveConnectorZeroSupported
  12184. /*
  12185. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12188. */
  12189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12190. //* Smart Charging Profile */
  12191. //ChargeProfileMaxStackLevel
  12192. /*
  12193. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12196. */
  12197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12198. // ChargingScheduleAllowedChargingRateUnit
  12199. /*
  12200. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12203. */
  12204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12205. // ChargingScheduleMaxPeriods
  12206. /*
  12207. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12210. */
  12211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12212. // ConnectorSwitch3to1PhaseSupported
  12213. /*
  12214. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12217. */
  12218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12219. // MaxChargingProfilesInstalled
  12220. /*
  12221. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12224. */
  12225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12226. fclose(outfile);
  12227. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12228. }
  12229. void getKeyValue(char *keyReq)
  12230. {
  12231. int isEmpty = FALSE;
  12232. int isKnowKey = FALSE;
  12233. DEBUG_INFO("keyReq = %s\n", keyReq);
  12234. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12235. isEmpty = TRUE;
  12236. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12237. {
  12238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12241. {
  12242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12243. }
  12244. else
  12245. {
  12246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12247. }
  12248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12249. isKnowKey = TRUE;
  12250. }
  12251. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12252. {
  12253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12256. {
  12257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12258. }
  12259. else
  12260. {
  12261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12262. }
  12263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12264. isKnowKey = TRUE;
  12265. }
  12266. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12267. {
  12268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12271. {
  12272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12273. }
  12274. else
  12275. {
  12276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12277. }
  12278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12279. isKnowKey = TRUE;
  12280. }
  12281. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12282. {
  12283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12286. {
  12287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12288. }
  12289. else
  12290. {
  12291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12292. }
  12293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12294. isKnowKey = TRUE;
  12295. }
  12296. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12297. {
  12298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12301. {
  12302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12303. }
  12304. else
  12305. {
  12306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12307. }
  12308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12309. isKnowKey = TRUE;
  12310. }
  12311. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12312. {
  12313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12316. {
  12317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12318. }
  12319. else
  12320. {
  12321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12322. }
  12323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12324. isKnowKey = TRUE;
  12325. }
  12326. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12327. {
  12328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12331. {
  12332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12333. }
  12334. else
  12335. {
  12336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12337. }
  12338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12339. isKnowKey = TRUE;
  12340. }
  12341. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12342. {
  12343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12346. {
  12347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12348. }
  12349. else
  12350. {
  12351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12352. }
  12353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12354. isKnowKey = TRUE;
  12355. }
  12356. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12357. {
  12358. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12361. {
  12362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12363. }
  12364. else
  12365. {
  12366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12367. }
  12368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12369. isKnowKey = TRUE;
  12370. }
  12371. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12372. {
  12373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12376. {
  12377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12378. }
  12379. else
  12380. {
  12381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12382. }
  12383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12384. isKnowKey = TRUE;
  12385. }
  12386. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12387. {
  12388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12391. {
  12392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12393. }
  12394. else
  12395. {
  12396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12397. }
  12398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12399. isKnowKey = TRUE;
  12400. }
  12401. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12402. {
  12403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12406. {
  12407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12408. }
  12409. else
  12410. {
  12411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12412. }
  12413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12414. isKnowKey = TRUE;
  12415. }
  12416. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12417. {
  12418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12421. {
  12422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12423. }
  12424. else
  12425. {
  12426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12427. }
  12428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12429. isKnowKey = TRUE;
  12430. }
  12431. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12432. {
  12433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12436. {
  12437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12438. }
  12439. else
  12440. {
  12441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12442. }
  12443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12444. isKnowKey = TRUE;
  12445. }
  12446. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12447. {
  12448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12451. {
  12452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12453. }
  12454. else
  12455. {
  12456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12457. }
  12458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12459. isKnowKey = TRUE;
  12460. }
  12461. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12462. {
  12463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12466. {
  12467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12468. }
  12469. else
  12470. {
  12471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12472. }
  12473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12474. isKnowKey = TRUE;
  12475. }
  12476. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12477. {
  12478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12481. {
  12482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12483. }
  12484. else
  12485. {
  12486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12487. }
  12488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12489. isKnowKey = TRUE;
  12490. }
  12491. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12492. {
  12493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12496. {
  12497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12498. }
  12499. else
  12500. {
  12501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12502. }
  12503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12504. isKnowKey = TRUE;
  12505. }
  12506. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12507. {
  12508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12511. {
  12512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12513. }
  12514. else
  12515. {
  12516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12517. }
  12518. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12520. isKnowKey = TRUE;
  12521. }
  12522. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12523. {
  12524. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12527. {
  12528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12529. }
  12530. else
  12531. {
  12532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12533. }
  12534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12535. isKnowKey = TRUE;
  12536. }
  12537. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12538. {
  12539. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12542. {
  12543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12544. }
  12545. else
  12546. {
  12547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12548. }
  12549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12550. isKnowKey = TRUE;
  12551. }
  12552. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12553. {
  12554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12557. {
  12558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12559. }
  12560. else
  12561. {
  12562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12563. }
  12564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12565. isKnowKey = TRUE;
  12566. }
  12567. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12568. {
  12569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12572. {
  12573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12574. }
  12575. else
  12576. {
  12577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12578. }
  12579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12580. isKnowKey = TRUE;
  12581. }
  12582. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12583. {
  12584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12587. {
  12588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12589. }
  12590. else
  12591. {
  12592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12593. }
  12594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12595. isKnowKey = TRUE;
  12596. }
  12597. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12598. {
  12599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12602. {
  12603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12604. }
  12605. else
  12606. {
  12607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12608. }
  12609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12610. isKnowKey = TRUE;
  12611. }
  12612. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12613. {
  12614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12617. {
  12618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12619. }
  12620. else
  12621. {
  12622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12623. }
  12624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12625. isKnowKey = TRUE;
  12626. }
  12627. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12628. {
  12629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12632. {
  12633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12634. }
  12635. else
  12636. {
  12637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12638. }
  12639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12640. isKnowKey = TRUE;
  12641. }
  12642. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12643. {
  12644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12647. {
  12648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12649. }
  12650. else
  12651. {
  12652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12653. }
  12654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12655. isKnowKey = TRUE;
  12656. }
  12657. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12658. {
  12659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12662. {
  12663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12664. }
  12665. else
  12666. {
  12667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12668. }
  12669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12670. isKnowKey = TRUE;
  12671. }
  12672. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12673. {
  12674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12677. {
  12678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12679. }
  12680. else
  12681. {
  12682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12683. }
  12684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12685. isKnowKey = TRUE;
  12686. }
  12687. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12688. {
  12689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12692. {
  12693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12694. }
  12695. else
  12696. {
  12697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12698. }
  12699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12700. isKnowKey = TRUE;
  12701. }
  12702. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12703. {
  12704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12707. {
  12708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12709. }
  12710. else
  12711. {
  12712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12713. }
  12714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12715. isKnowKey = TRUE;
  12716. }
  12717. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12718. {
  12719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12722. {
  12723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12724. }
  12725. else
  12726. {
  12727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12728. }
  12729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12730. isKnowKey = TRUE;
  12731. }
  12732. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12733. {
  12734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12737. {
  12738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12739. }
  12740. else
  12741. {
  12742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12743. }
  12744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12745. isKnowKey = TRUE;
  12746. }
  12747. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12748. {
  12749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12752. {
  12753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12754. }
  12755. else
  12756. {
  12757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12758. }
  12759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12760. isKnowKey = TRUE;
  12761. }
  12762. /*
  12763. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12764. {
  12765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12768. {
  12769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12770. }
  12771. else
  12772. {
  12773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12774. }
  12775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12776. isKnowKey = TRUE;
  12777. }*/
  12778. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12779. {
  12780. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12783. {
  12784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12785. }
  12786. else
  12787. {
  12788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12789. }
  12790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12791. isKnowKey = TRUE;
  12792. }
  12793. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12794. {
  12795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12798. {
  12799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12800. }
  12801. else
  12802. {
  12803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12804. }
  12805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12806. isKnowKey = TRUE;
  12807. }
  12808. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12809. {
  12810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12813. {
  12814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12815. }
  12816. else
  12817. {
  12818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12819. }
  12820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12821. isKnowKey = TRUE;
  12822. }
  12823. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12824. {
  12825. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12828. {
  12829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12830. }
  12831. else
  12832. {
  12833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12834. }
  12835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12836. isKnowKey = TRUE;
  12837. }
  12838. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12839. {
  12840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12843. {
  12844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12845. }
  12846. else
  12847. {
  12848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12849. }
  12850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12851. isKnowKey = TRUE;
  12852. }
  12853. #if 1
  12854. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12855. {
  12856. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12858. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12859. {
  12860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12861. }
  12862. else
  12863. {
  12864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12865. }
  12866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12867. isKnowKey = TRUE;
  12868. }
  12869. #endif
  12870. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12871. {
  12872. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12874. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12875. {
  12876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12877. }
  12878. else
  12879. {
  12880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12881. }
  12882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12883. isKnowKey = TRUE;
  12884. }
  12885. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12886. {
  12887. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12889. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12890. {
  12891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12892. }
  12893. else
  12894. {
  12895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12896. }
  12897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12898. isKnowKey = TRUE;
  12899. }
  12900. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12901. {
  12902. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12904. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12905. {
  12906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12907. }
  12908. else
  12909. {
  12910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12911. }
  12912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12913. isKnowKey = TRUE;
  12914. }
  12915. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12916. {
  12917. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12919. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12920. {
  12921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12922. }
  12923. else
  12924. {
  12925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12926. }
  12927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12928. isKnowKey = TRUE;
  12929. }
  12930. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12931. {
  12932. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12934. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12935. {
  12936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12937. }
  12938. else
  12939. {
  12940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12941. }
  12942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12943. isKnowKey = TRUE;
  12944. }
  12945. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12946. {
  12947. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12949. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12950. {
  12951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12952. }
  12953. else
  12954. {
  12955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12956. }
  12957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12958. isKnowKey = TRUE;
  12959. }
  12960. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12961. {
  12962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12964. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12965. {
  12966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12967. }
  12968. else
  12969. {
  12970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12971. }
  12972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12973. isKnowKey = TRUE;
  12974. }
  12975. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12976. {
  12977. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12979. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12980. {
  12981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12982. }
  12983. else
  12984. {
  12985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12986. }
  12987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12988. isKnowKey = TRUE;
  12989. }
  12990. //=========================================================
  12991. if(!isEmpty && !isKnowKey)
  12992. {
  12993. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12994. strcpy(unknownkey[UnknownKeynum], keyReq);
  12995. UnknownKeynum = UnknownKeynum + 1;
  12996. }
  12997. }
  12998. void processUnkownKey(void)
  12999. {
  13000. DEBUG_INFO("processUnkownKey...\n");
  13001. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13002. for(int index=0; index < UnknownKeynum; index++)
  13003. {
  13004. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13005. {
  13006. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13007. }
  13008. }
  13009. }
  13010. int setKeyValue(char *key, char *value)
  13011. {
  13012. int isSuccess = NotSupported;
  13013. int check_ascii=0;
  13014. char str[256]={0};
  13015. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13016. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13017. {
  13018. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13020. {
  13021. strcpy(str, (const char*)value);
  13022. for(int i = 0; str[i]; i++){
  13023. str[i] = tolower(str[i]);
  13024. }
  13025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13026. isSuccess = ConfigurationStatus_Accepted;
  13027. }
  13028. else
  13029. {
  13030. isSuccess = ConfigurationStatus_Rejected;
  13031. }
  13032. }
  13033. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13034. {
  13035. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13037. {
  13038. strcpy(str, (const char*)value);
  13039. for(int i = 0; str[i]; i++){
  13040. str[i] = tolower(str[i]);
  13041. }
  13042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13043. isSuccess = ConfigurationStatus_Accepted;
  13044. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  13045. }
  13046. else
  13047. {
  13048. isSuccess = ConfigurationStatus_Rejected;
  13049. }
  13050. }
  13051. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13052. {
  13053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13054. {
  13055. strcpy(str, (const char*)value);
  13056. for(int i = 0; str[i]; i++)
  13057. {
  13058. str[i] = tolower(str[i]);
  13059. }
  13060. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13062. isSuccess = ConfigurationStatus_Accepted;
  13063. }
  13064. else
  13065. {
  13066. isSuccess = ConfigurationStatus_Rejected;
  13067. }
  13068. }
  13069. if(strcmp(key, "BlinkRepeat") == 0)
  13070. {
  13071. //Charger.BlinkRepeat = Integer.parseInt(value);
  13072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13073. {
  13074. check_ascii = value[0];
  13075. if( (check_ascii < 48) || (check_ascii > 57) )
  13076. {
  13077. isSuccess = ConfigurationStatus_Rejected;
  13078. }
  13079. else
  13080. {
  13081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13082. isSuccess = ConfigurationStatus_Accepted;
  13083. }
  13084. }
  13085. else
  13086. {
  13087. isSuccess = ConfigurationStatus_Rejected;
  13088. }
  13089. }
  13090. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13091. {
  13092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13093. {
  13094. check_ascii = value[0];
  13095. if( (check_ascii < 48) || (check_ascii > 57) )
  13096. {
  13097. isSuccess = ConfigurationStatus_Rejected;
  13098. }
  13099. else
  13100. {
  13101. if((atoi(value) == 0) || (atoi(value) >= 10))
  13102. {
  13103. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13105. isSuccess = ConfigurationStatus_Accepted;
  13106. }
  13107. else
  13108. isSuccess = ConfigurationStatus_Rejected;
  13109. }
  13110. }
  13111. else
  13112. {
  13113. isSuccess = ConfigurationStatus_Rejected;
  13114. }
  13115. }
  13116. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13117. {
  13118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13119. {
  13120. check_ascii = value[0];
  13121. if( (check_ascii < 48) || (check_ascii > 57) )
  13122. {
  13123. isSuccess = ConfigurationStatus_Rejected;
  13124. }
  13125. else
  13126. {
  13127. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13129. isSuccess = ConfigurationStatus_Accepted;
  13130. }
  13131. }
  13132. else
  13133. {
  13134. isSuccess = ConfigurationStatus_Rejected;
  13135. }
  13136. }
  13137. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13138. {
  13139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13140. {
  13141. check_ascii = value[0];
  13142. if( (check_ascii < 48) || (check_ascii > 57) )
  13143. {
  13144. isSuccess = ConfigurationStatus_Rejected;
  13145. }
  13146. else
  13147. {
  13148. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13150. isSuccess = ConfigurationStatus_Accepted;
  13151. }
  13152. }
  13153. else
  13154. {
  13155. isSuccess = ConfigurationStatus_Rejected;
  13156. }
  13157. }
  13158. if(strcmp(key, "HeartbeatInterval") == 0)
  13159. {
  13160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13161. {
  13162. check_ascii = value[0];
  13163. if( (check_ascii < 48) || (check_ascii > 57) )
  13164. {
  13165. isSuccess = ConfigurationStatus_Rejected;
  13166. }
  13167. else
  13168. {
  13169. if((atoi(value) == 0) || (atoi(value) >= 10))
  13170. {
  13171. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13173. HeartBeatWaitTime = atoi(value);
  13174. isSuccess = ConfigurationStatus_Accepted;
  13175. }
  13176. else
  13177. {
  13178. isSuccess = ConfigurationStatus_Rejected;
  13179. }
  13180. }
  13181. }
  13182. else
  13183. {
  13184. isSuccess = ConfigurationStatus_Rejected;
  13185. }
  13186. }
  13187. if(strcmp(key, "LightIntensity") == 0)
  13188. {
  13189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13190. {
  13191. check_ascii = value[0];
  13192. if( (check_ascii < 48) || (check_ascii > 57) )
  13193. {
  13194. isSuccess = ConfigurationStatus_Rejected;
  13195. }
  13196. else
  13197. {
  13198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13199. isSuccess = ConfigurationStatus_Accepted;
  13200. }
  13201. }
  13202. else
  13203. {
  13204. isSuccess = ConfigurationStatus_Rejected;
  13205. }
  13206. }
  13207. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13208. {
  13209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13210. {
  13211. strcpy(str, (const char*)value);
  13212. for(int i = 0; str[i]; i++)
  13213. {
  13214. str[i] = tolower(str[i]);
  13215. }
  13216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13217. isSuccess = ConfigurationStatus_Accepted;
  13218. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13219. }
  13220. else
  13221. {
  13222. isSuccess = ConfigurationStatus_Rejected;
  13223. }
  13224. }
  13225. if(strcmp(key, "LocalPreAuthorize") == 0)
  13226. {
  13227. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13228. {
  13229. strcpy(str, (const char*)value);
  13230. for(int i = 0; str[i]; i++)
  13231. {
  13232. str[i] = tolower(str[i]);
  13233. }
  13234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13235. isSuccess = ConfigurationStatus_Accepted;
  13236. }
  13237. else
  13238. {
  13239. isSuccess = ConfigurationStatus_Rejected;
  13240. }
  13241. }
  13242. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13243. {
  13244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13245. {
  13246. check_ascii = value[0];
  13247. if( (check_ascii < 48) || (check_ascii > 57) )
  13248. {
  13249. isSuccess = ConfigurationStatus_Rejected;
  13250. }
  13251. else
  13252. {
  13253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13254. isSuccess = ConfigurationStatus_Accepted;
  13255. }
  13256. }
  13257. else
  13258. {
  13259. isSuccess = ConfigurationStatus_Rejected;
  13260. }
  13261. }
  13262. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13263. {
  13264. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13265. {
  13266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13267. isSuccess = ConfigurationStatus_Accepted;
  13268. }
  13269. else
  13270. {
  13271. isSuccess = ConfigurationStatus_Rejected;
  13272. }
  13273. }
  13274. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13275. {
  13276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13277. {
  13278. check_ascii = value[0];
  13279. if( (check_ascii < 48) || (check_ascii > 57) )
  13280. {
  13281. isSuccess = ConfigurationStatus_Rejected;
  13282. }
  13283. else
  13284. {
  13285. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13287. isSuccess = ConfigurationStatus_Accepted;
  13288. }
  13289. }
  13290. else
  13291. {
  13292. isSuccess = ConfigurationStatus_Rejected;
  13293. }
  13294. }
  13295. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13296. {
  13297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13298. {
  13299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13300. isSuccess = ConfigurationStatus_Accepted;
  13301. }
  13302. else
  13303. {
  13304. isSuccess = ConfigurationStatus_Rejected;
  13305. }
  13306. }
  13307. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13308. {
  13309. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13310. {
  13311. check_ascii = value[0];
  13312. if( (check_ascii < 48) || (check_ascii > 57) )
  13313. {
  13314. isSuccess = ConfigurationStatus_Rejected;
  13315. }
  13316. else
  13317. {
  13318. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13320. isSuccess = ConfigurationStatus_Accepted;
  13321. }
  13322. }
  13323. else
  13324. {
  13325. isSuccess = ConfigurationStatus_Rejected;
  13326. }
  13327. }
  13328. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13329. {
  13330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13331. {
  13332. check_ascii = value[0];
  13333. if( (check_ascii < 48) || (check_ascii > 57) )
  13334. {
  13335. isSuccess = ConfigurationStatus_Rejected;
  13336. }
  13337. else
  13338. {
  13339. if((atoi(value) == 0) || (atoi(value) >= 10))
  13340. {
  13341. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13343. isSuccess = ConfigurationStatus_Accepted;
  13344. }
  13345. else
  13346. {
  13347. isSuccess = ConfigurationStatus_Rejected;
  13348. }
  13349. }
  13350. }
  13351. else
  13352. {
  13353. isSuccess = ConfigurationStatus_Rejected;
  13354. }
  13355. }
  13356. if(strcmp(key, "MinimumStatusDuration") == 0)
  13357. {
  13358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13359. {
  13360. check_ascii = value[0];
  13361. if( (check_ascii < 48) || (check_ascii > 57) )
  13362. {
  13363. isSuccess = ConfigurationStatus_Rejected;
  13364. }
  13365. else
  13366. {
  13367. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13368. {
  13369. isSuccess = ConfigurationStatus_Rejected;
  13370. }
  13371. else
  13372. {
  13373. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13375. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13376. isSuccess = ConfigurationStatus_Accepted;
  13377. }
  13378. }
  13379. }
  13380. else
  13381. {
  13382. isSuccess = ConfigurationStatus_Rejected;
  13383. }
  13384. }
  13385. if(strcmp(key, "NumberOfConnectors") == 0)
  13386. {
  13387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13388. {
  13389. check_ascii = value[0];
  13390. if( (check_ascii < 48) || (check_ascii > 57) )
  13391. {
  13392. isSuccess = ConfigurationStatus_Rejected;
  13393. }
  13394. else
  13395. {
  13396. //Charger.ResetRetries = Integer.parseInt(value);
  13397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13398. isSuccess = ConfigurationStatus_Accepted;
  13399. }
  13400. }
  13401. else
  13402. {
  13403. isSuccess = ConfigurationStatus_Rejected;
  13404. }
  13405. }
  13406. if(strcmp(key, "ResetRetries") == 0)
  13407. {
  13408. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13409. {
  13410. check_ascii = value[0];
  13411. if( (check_ascii < 48) || (check_ascii > 57) )
  13412. {
  13413. isSuccess = ConfigurationStatus_Rejected;
  13414. }
  13415. else
  13416. {
  13417. //Charger.ResetRetries = Integer.parseInt(value);
  13418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13419. isSuccess = ConfigurationStatus_Accepted;
  13420. }
  13421. }
  13422. else
  13423. {
  13424. isSuccess = ConfigurationStatus_Rejected;
  13425. }
  13426. }
  13427. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13428. {
  13429. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13430. {
  13431. strcpy(str, (const char*)value);
  13432. for(int i = 0; str[i]; i++)
  13433. {
  13434. str[i] = tolower(str[i]);
  13435. }
  13436. if(strcmp(str, "notapplicable")== 0)
  13437. {
  13438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13439. isSuccess = ConfigurationStatus_Accepted;
  13440. }
  13441. else if(strcmp(str, "unknown")== 0)
  13442. {
  13443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13444. isSuccess = ConfigurationStatus_Accepted;
  13445. }
  13446. else if(strcmp(str, "rst")== 0)
  13447. {
  13448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13449. isSuccess = ConfigurationStatus_Accepted;
  13450. }
  13451. else if(strcmp(str, "rts")== 0)
  13452. {
  13453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13454. isSuccess = ConfigurationStatus_Accepted;
  13455. }
  13456. else if(strcmp(str, "srt")== 0)
  13457. {
  13458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13459. isSuccess = ConfigurationStatus_Accepted;
  13460. }
  13461. else if(strcmp(str, "str")== 0)
  13462. {
  13463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13464. isSuccess = ConfigurationStatus_Accepted;
  13465. }
  13466. else if(strcmp(str, "trs")== 0)
  13467. {
  13468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13469. isSuccess = ConfigurationStatus_Accepted;
  13470. }
  13471. else if(strcmp(str, "tsr")== 0)
  13472. {
  13473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13474. isSuccess = ConfigurationStatus_Accepted;
  13475. }
  13476. else
  13477. {
  13478. isSuccess = ConfigurationStatus_Rejected;
  13479. }
  13480. }
  13481. else
  13482. {
  13483. isSuccess = ConfigurationStatus_Rejected;
  13484. }
  13485. }
  13486. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13487. {
  13488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13489. {
  13490. check_ascii = value[0];
  13491. if( (check_ascii < 48) || (check_ascii > 57) )
  13492. {
  13493. isSuccess = ConfigurationStatus_Rejected;
  13494. }
  13495. else
  13496. {
  13497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13498. isSuccess = ConfigurationStatus_Accepted;
  13499. }
  13500. }
  13501. else
  13502. {
  13503. isSuccess = ConfigurationStatus_Rejected;
  13504. }
  13505. }
  13506. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13507. {
  13508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13509. {
  13510. strcpy(str, (const char*)value);
  13511. for(int i = 0; str[i]; i++)
  13512. {
  13513. str[i] = tolower(str[i]);
  13514. }
  13515. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13517. isSuccess = ConfigurationStatus_Accepted;
  13518. }
  13519. else
  13520. {
  13521. isSuccess = ConfigurationStatus_Rejected;
  13522. }
  13523. }
  13524. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13525. {
  13526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13527. {
  13528. strcpy(str, (const char*)value);
  13529. for(int i = 0; str[i]; i++)
  13530. {
  13531. str[i] = tolower(str[i]);
  13532. }
  13533. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13535. isSuccess = ConfigurationStatus_Accepted;
  13536. }
  13537. else
  13538. {
  13539. isSuccess = ConfigurationStatus_Rejected;
  13540. }
  13541. }
  13542. if(strcmp(key, "StopTxnAlignedData") == 0)
  13543. {
  13544. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13545. {
  13546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13547. isSuccess = ConfigurationStatus_Accepted;
  13548. }
  13549. else
  13550. {
  13551. isSuccess = ConfigurationStatus_Rejected;
  13552. }
  13553. }
  13554. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13555. {
  13556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13557. {
  13558. check_ascii = value[0];
  13559. if( (check_ascii < 48) || (check_ascii > 57) )
  13560. {
  13561. isSuccess = ConfigurationStatus_Rejected;
  13562. }
  13563. else
  13564. {
  13565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13566. isSuccess = ConfigurationStatus_Accepted;
  13567. }
  13568. }
  13569. else
  13570. {
  13571. isSuccess = ConfigurationStatus_Rejected;
  13572. }
  13573. }
  13574. if(strcmp(key, "StopTxnSampledData") == 0)
  13575. {
  13576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13577. {
  13578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13579. isSuccess = ConfigurationStatus_Accepted;
  13580. }
  13581. else
  13582. {
  13583. isSuccess = ConfigurationStatus_Rejected;
  13584. }
  13585. }
  13586. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13587. {
  13588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13589. {
  13590. check_ascii = value[0];
  13591. if( (check_ascii < 48) || (check_ascii > 57) )
  13592. {
  13593. isSuccess = ConfigurationStatus_Rejected;
  13594. }
  13595. else
  13596. {
  13597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13598. isSuccess = ConfigurationStatus_Accepted;
  13599. }
  13600. }
  13601. else
  13602. {
  13603. isSuccess = ConfigurationStatus_Rejected;
  13604. }
  13605. }
  13606. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13607. {
  13608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13609. {
  13610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13611. isSuccess = ConfigurationStatus_Accepted;
  13612. }
  13613. else
  13614. {
  13615. isSuccess = ConfigurationStatus_Rejected;
  13616. }
  13617. }
  13618. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13619. {
  13620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13621. {
  13622. check_ascii = value[0];
  13623. if( (check_ascii < 48) || (check_ascii > 57) )
  13624. {
  13625. isSuccess = ConfigurationStatus_Rejected;
  13626. }
  13627. else
  13628. {
  13629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13630. isSuccess = ConfigurationStatus_Accepted;
  13631. }
  13632. }
  13633. else
  13634. {
  13635. isSuccess = ConfigurationStatus_Rejected;
  13636. }
  13637. }
  13638. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13639. {
  13640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13641. {
  13642. check_ascii = value[0];
  13643. if( (check_ascii < 48) || (check_ascii > 57) )
  13644. {
  13645. isSuccess = ConfigurationStatus_Rejected;
  13646. }
  13647. else
  13648. {
  13649. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13651. TransactionMessageAttemptsValue = atoi(value);
  13652. isSuccess = ConfigurationStatus_Accepted;
  13653. }
  13654. }
  13655. else
  13656. {
  13657. isSuccess = ConfigurationStatus_Rejected;
  13658. }
  13659. }
  13660. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13661. {
  13662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13663. {
  13664. check_ascii = value[0];
  13665. if( (check_ascii < 48) || (check_ascii > 57) )
  13666. {
  13667. isSuccess = ConfigurationStatus_Rejected;
  13668. }
  13669. else
  13670. {
  13671. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13673. TransactionMessageRetryIntervalValue = atoi(value);
  13674. isSuccess = ConfigurationStatus_Accepted;
  13675. }
  13676. }
  13677. else
  13678. {
  13679. isSuccess = ConfigurationStatus_Rejected;
  13680. }
  13681. }
  13682. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13683. {
  13684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13685. {
  13686. strcpy(str, (const char*)value);
  13687. for(int i = 0; str[i]; i++)
  13688. {
  13689. str[i] = tolower(str[i]);
  13690. }
  13691. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13693. isSuccess = ConfigurationStatus_Accepted;
  13694. }
  13695. else
  13696. {
  13697. isSuccess = ConfigurationStatus_Rejected;
  13698. }
  13699. }
  13700. if(strcmp(key, "WebSocketPingInterval") == 0)
  13701. {
  13702. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13703. {
  13704. check_ascii = value[0];
  13705. if( (check_ascii < 48) || (check_ascii > 57) )
  13706. {
  13707. isSuccess = ConfigurationStatus_Rejected;
  13708. }
  13709. else
  13710. {
  13711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13712. isSuccess = ConfigurationStatus_Accepted;
  13713. }
  13714. }
  13715. else
  13716. {
  13717. isSuccess = ConfigurationStatus_Rejected;
  13718. }
  13719. }
  13720. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13721. {
  13722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13723. {
  13724. strcpy(str, (const char*)value);
  13725. for(int i = 0; str[i]; i++)
  13726. {
  13727. str[i] = tolower(str[i]);
  13728. }
  13729. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13731. isSuccess = ConfigurationStatus_Accepted;
  13732. }
  13733. else
  13734. {
  13735. isSuccess = ConfigurationStatus_Rejected;
  13736. }
  13737. }
  13738. if(strcmp(key, "AuthorizationKey") == 0)
  13739. {
  13740. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13741. {
  13742. strcpy(str, (const char*)value);
  13743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13744. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13745. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  13746. isSuccess = ConfigurationStatus_Accepted;
  13747. }
  13748. else
  13749. {
  13750. isSuccess = ConfigurationStatus_Rejected;
  13751. }
  13752. }
  13753. if(strcmp(key, "SecurityProfile") == 0)
  13754. {
  13755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13756. {
  13757. check_ascii = value[0];
  13758. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13759. {
  13760. isSuccess = ConfigurationStatus_Rejected;
  13761. }
  13762. else if(check_ascii == 0x33)
  13763. {
  13764. isSuccess = NotSupported;
  13765. }
  13766. else
  13767. {
  13768. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13769. {
  13770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13771. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  13772. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  13773. isSuccess = ConfigurationStatus_Accepted;
  13774. }
  13775. else
  13776. isSuccess = ConfigurationStatus_Rejected;
  13777. }
  13778. }
  13779. else
  13780. {
  13781. isSuccess = ConfigurationStatus_Rejected;
  13782. }
  13783. }
  13784. if(strcmp(key, "DefaultPrice") == 0)
  13785. {
  13786. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13787. {
  13788. strcpy(str, (const char*)value);
  13789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13790. isSuccess = ConfigurationStatus_Accepted;
  13791. }
  13792. else
  13793. {
  13794. isSuccess = ConfigurationStatus_Rejected;
  13795. }
  13796. }
  13797. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13798. {
  13799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13800. {
  13801. strcpy(str, (const char*)value);
  13802. for(int i = 0; str[i]; i++)
  13803. {
  13804. str[i] = tolower(str[i]);
  13805. }
  13806. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13808. isSuccess = ConfigurationStatus_Accepted;
  13809. }
  13810. else
  13811. {
  13812. isSuccess = ConfigurationStatus_Rejected;
  13813. }
  13814. }
  13815. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13816. {
  13817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13818. {
  13819. strcpy(str, (const char*)value);
  13820. for(int i = 0; str[i]; i++)
  13821. {
  13822. str[i] = tolower(str[i]);
  13823. }
  13824. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13826. isSuccess = ConfigurationStatus_Accepted;
  13827. }
  13828. else
  13829. {
  13830. isSuccess = ConfigurationStatus_Rejected;
  13831. }
  13832. }
  13833. #if 0
  13834. //For OCPP Test Case
  13835. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13836. {
  13837. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13838. {
  13839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13840. isSuccess = ConfigurationStatus_Accepted;
  13841. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13842. }
  13843. else
  13844. {
  13845. isSuccess = ConfigurationStatus_Rejected;
  13846. }
  13847. }
  13848. #endif
  13849. #if 1
  13850. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13851. {
  13852. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13853. {
  13854. strcpy(str, (const char*)value);
  13855. for(int i = 0; str[i]; i++)
  13856. {
  13857. str[i] = tolower(str[i]);
  13858. }
  13859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13860. isSuccess = ConfigurationStatus_Accepted;
  13861. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13862. }
  13863. else
  13864. {
  13865. isSuccess = ConfigurationStatus_Rejected;
  13866. }
  13867. }
  13868. #endif
  13869. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13870. {
  13871. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13872. {
  13873. check_ascii = value[0];
  13874. if( (check_ascii < 48) || (check_ascii > 57) )
  13875. {
  13876. isSuccess = ConfigurationStatus_Rejected;
  13877. }
  13878. else
  13879. {
  13880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13881. isSuccess = ConfigurationStatus_Accepted;
  13882. }
  13883. }
  13884. else
  13885. {
  13886. isSuccess = ConfigurationStatus_Rejected;
  13887. }
  13888. }
  13889. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13890. {
  13891. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13892. {
  13893. check_ascii = value[0];
  13894. if( (check_ascii < 48) || (check_ascii > 57) )
  13895. {
  13896. isSuccess = ConfigurationStatus_Rejected;
  13897. }
  13898. else
  13899. {
  13900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13901. isSuccess = ConfigurationStatus_Accepted;
  13902. }
  13903. }
  13904. else
  13905. {
  13906. isSuccess = ConfigurationStatus_Rejected;
  13907. }
  13908. }
  13909. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13910. {
  13911. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13912. {
  13913. strcpy(str, (const char*)value);
  13914. for(int i = 0; str[i]; i++)
  13915. {
  13916. str[i] = tolower(str[i]);
  13917. }
  13918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13919. isSuccess = ConfigurationStatus_Accepted;
  13920. }
  13921. else
  13922. {
  13923. isSuccess = ConfigurationStatus_Rejected;
  13924. }
  13925. }
  13926. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13927. {
  13928. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13929. {
  13930. check_ascii = value[0];
  13931. if( (check_ascii < 48) || (check_ascii > 57) )
  13932. {
  13933. isSuccess = ConfigurationStatus_Rejected;
  13934. }
  13935. else
  13936. {
  13937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13938. isSuccess = ConfigurationStatus_Accepted;
  13939. }
  13940. }
  13941. else
  13942. {
  13943. isSuccess = ConfigurationStatus_Rejected;
  13944. }
  13945. }
  13946. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13947. {
  13948. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13949. {
  13950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13951. isSuccess = ConfigurationStatus_Accepted;
  13952. }
  13953. else
  13954. {
  13955. isSuccess = ConfigurationStatus_Rejected;
  13956. }
  13957. }
  13958. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13959. {
  13960. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13961. {
  13962. check_ascii = value[0];
  13963. if( (check_ascii < 48) || (check_ascii > 57) )
  13964. {
  13965. isSuccess = ConfigurationStatus_Rejected;
  13966. }
  13967. else
  13968. {
  13969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13970. isSuccess = ConfigurationStatus_Accepted;
  13971. }
  13972. }
  13973. else
  13974. {
  13975. isSuccess = ConfigurationStatus_Rejected;
  13976. }
  13977. }
  13978. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13979. {
  13980. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13981. {
  13982. strcpy(str, (const char*)value);
  13983. for(int i = 0; str[i]; i++)
  13984. {
  13985. str[i] = tolower(str[i]);
  13986. }
  13987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13988. isSuccess = ConfigurationStatus_Accepted;
  13989. }
  13990. else
  13991. {
  13992. isSuccess = ConfigurationStatus_Rejected;
  13993. }
  13994. }
  13995. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13996. {
  13997. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13998. {
  13999. check_ascii = value[0];
  14000. if( (check_ascii < 48) || (check_ascii > 57) )
  14001. {
  14002. isSuccess = ConfigurationStatus_Rejected;
  14003. }
  14004. else
  14005. {
  14006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14007. isSuccess = ConfigurationStatus_Accepted;
  14008. }
  14009. }
  14010. else
  14011. {
  14012. isSuccess = ConfigurationStatus_Rejected;
  14013. }
  14014. }
  14015. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14016. return isSuccess;
  14017. }
  14018. int TransactionMessageAttemptsGet(void)
  14019. {
  14020. return TransactionMessageAttemptsValue;
  14021. }
  14022. int FirstHeartBeatResponse(void)
  14023. {
  14024. return FirstHeartBeat;
  14025. }
  14026. int TransactionMessageRetryIntervalGet(void)
  14027. {
  14028. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14029. }
  14030. int ReadHttpStatus(int sock)
  14031. {
  14032. //char c;
  14033. char buff[1024]="",*ptr=buff+1;
  14034. int bytes_received, status;
  14035. DEBUG_INFO("Begin Response ..\n");
  14036. while((bytes_received = recv(sock, ptr, 1, 0))){
  14037. if(bytes_received==-1){
  14038. perror("ReadHttpStatus");
  14039. exit(1);
  14040. }
  14041. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14042. ptr++;
  14043. }
  14044. *ptr=0;
  14045. ptr=buff+1;
  14046. sscanf(ptr,"%*s %d ", &status);
  14047. DEBUG_INFO("%s\n",ptr);
  14048. DEBUG_INFO("status=%d\n",status);
  14049. DEBUG_INFO("End Response ..\n");
  14050. return (bytes_received>0)?status:0;
  14051. }
  14052. //the only filed that it parsed is 'Content-Length'
  14053. int ParseHeader(int sock)
  14054. {
  14055. //char c;
  14056. char buff[1024]="",*ptr=buff+4;
  14057. int bytes_received;
  14058. DEBUG_INFO("Begin HEADER ..\n");
  14059. while((bytes_received = recv(sock, ptr, 1, 0))){
  14060. if(bytes_received==-1){
  14061. perror("Parse Header");
  14062. exit(1);
  14063. }
  14064. if(
  14065. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14066. (ptr[-1]=='\r') && (*ptr=='\n' )
  14067. ) break;
  14068. ptr++;
  14069. }
  14070. *ptr=0;
  14071. ptr=buff+4;
  14072. //printf("%s",ptr);
  14073. if(bytes_received){
  14074. ptr=strstr(ptr,"Content-Length:");
  14075. if(ptr){
  14076. sscanf(ptr,"%*s %d",&bytes_received);
  14077. }else
  14078. bytes_received=-1; //unknown size
  14079. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14080. }
  14081. DEBUG_INFO("End HEADER ..\n");
  14082. return bytes_received ;
  14083. }
  14084. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14085. {
  14086. int result = TRUE;
  14087. char rmFileCmd[100]={0};
  14088. char FilePath[100]={0};
  14089. char ftpbuf[200];
  14090. int systemresult;
  14091. //DEBUG_INFO("filename=%s\n",filename);
  14092. //DEBUG_INFO("url=%s\n",url);
  14093. sprintf(FilePath,"/mnt/%s",filename);
  14094. system("ping 8.8.8.8 &");
  14095. if((access(FilePath,F_OK))!=-1)
  14096. {
  14097. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14098. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14099. system(rmFileCmd);
  14100. }
  14101. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14102. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14103. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14104. systemresult = system(ftpbuf);
  14105. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14106. if(systemresult != 0)
  14107. {
  14108. DEBUG_INFO("http DownLoad error!\n");
  14109. result = FALSE;
  14110. }
  14111. system("pkill ping");
  14112. return result;
  14113. }
  14114. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14115. {
  14116. int result = TRUE;
  14117. char rmFileCmd[100]={0};
  14118. char FilePath[100]={0};
  14119. char ftpbuf[200];
  14120. int systemresult;
  14121. //char temp[100];
  14122. sprintf(FilePath,"/mnt/%s",filename);
  14123. system("ping 8.8.8.8 &");
  14124. if((access(FilePath,F_OK))!=-1)
  14125. {
  14126. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14127. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14128. system(rmFileCmd);
  14129. }
  14130. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14131. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14132. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14133. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14134. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14135. systemresult = system(ftpbuf);
  14136. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14137. if(systemresult != 0)
  14138. {
  14139. printf("wget error!\n");
  14140. result = FALSE;
  14141. }
  14142. system("pkill ping");
  14143. return result;
  14144. }
  14145. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14146. {
  14147. char rmFileCmd[100]={0};
  14148. char FilePath[100]={0};
  14149. char buf[512];
  14150. int systemresult = 0;
  14151. //DEBUG_INFO("filename=%s\n",filename);
  14152. //DEBUG_INFO("url=%s\n",url);
  14153. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14154. if((access(FilePath,F_OK))!=-1)
  14155. {
  14156. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14157. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14158. system(rmFileCmd);
  14159. }
  14160. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14161. if(fp == NULL)
  14162. {
  14163. DEBUG_INFO("log is NULL\n");
  14164. return FALSE;
  14165. }
  14166. else
  14167. {
  14168. fprintf(fp, "%s\n", url);
  14169. fprintf(fp, "%s\n", filename);
  14170. fclose(fp);
  14171. }
  14172. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14173. if(phpFP == NULL)
  14174. {
  14175. DEBUG_INFO("PHP upload fail.\n");
  14176. return FALSE;
  14177. }
  14178. else
  14179. {
  14180. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14181. {
  14182. if(strstr(buf, "result") != NULL)
  14183. {
  14184. sscanf(buf, "result: %d", &systemresult);
  14185. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14186. }
  14187. }
  14188. pclose(phpFP);
  14189. }
  14190. if(systemresult != 1)
  14191. {
  14192. DEBUG_INFO("HTTP upload error!\n");
  14193. return FALSE;
  14194. }
  14195. return TRUE;
  14196. }
  14197. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14198. {
  14199. struct hostent* server;
  14200. char *IPbuffer;
  14201. char ftpbuf[200];
  14202. int systemresult;
  14203. // To retrieve host information
  14204. server = gethostbyname(location);
  14205. // To convert an Internet network
  14206. // address into ASCII string
  14207. IPbuffer = inet_ntoa(*((struct in_addr*)
  14208. server->h_addr_list[0]));
  14209. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14210. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14211. /* format : ftpput -u username -p passwd IP target source*/
  14212. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14213. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14214. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14215. systemresult = system(ftpbuf);
  14216. DEBUG_INFO("systemresult=%d\n",systemresult);
  14217. if(systemresult != 0)
  14218. {
  14219. DEBUG_INFO("ftpput error!\n");
  14220. return FALSE;
  14221. }
  14222. return TRUE;
  14223. }
  14224. int GetOcppServerURL()
  14225. {
  14226. int result = FALSE;
  14227. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14228. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14229. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14230. struct yuarel url;
  14231. char urlStr[512];
  14232. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14233. {
  14234. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14235. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14236. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14237. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14238. if(yuarel_parse(&url, urlStr) != -1)
  14239. {
  14240. sprintf(OcppProtocol, "%s", url.scheme);
  14241. sprintf(OcppHost, "%s", url.host);
  14242. if(url.path == NULL)
  14243. OcppTempPath[0] = '\0';
  14244. else
  14245. {
  14246. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14247. {
  14248. sprintf(OcppTempPath, "%s/", url.path);
  14249. }
  14250. else
  14251. {
  14252. sprintf(OcppTempPath, "%s", url.path);
  14253. }
  14254. }
  14255. if(url.port == 0)
  14256. {
  14257. if(strcmp(OcppProtocol, "wss") == 0)
  14258. OcppPort = 443;
  14259. else
  14260. OcppPort = 80;
  14261. }
  14262. else
  14263. OcppPort = url.port;
  14264. result = TRUE;
  14265. }
  14266. }
  14267. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14268. {
  14269. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14270. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14271. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14272. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14273. if(yuarel_parse(&url, urlStr) != -1)
  14274. {
  14275. sprintf(OcppProtocol, "%s", url.scheme);
  14276. sprintf(OcppHost, "%s", url.host);
  14277. if(url.path == NULL)
  14278. OcppTempPath[0] = '\0';
  14279. else
  14280. sprintf(OcppTempPath, "%s", url.path);
  14281. if(url.port == 0)
  14282. {
  14283. if(strcmp(OcppProtocol, "wss") == 0)
  14284. OcppPort = 443;
  14285. else
  14286. OcppPort = 80;
  14287. }
  14288. else
  14289. OcppPort = url.port;
  14290. result = TRUE;
  14291. }
  14292. }
  14293. else
  14294. {
  14295. strcpy(OcppHost,"");
  14296. }
  14297. return result;
  14298. }
  14299. int GetOcppPath()
  14300. {
  14301. int result = FALSE;
  14302. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14303. {
  14304. if(OcppTempPath == NULL)
  14305. {
  14306. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14307. }
  14308. else
  14309. {
  14310. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14311. }
  14312. result = TRUE;
  14313. goto End;
  14314. }
  14315. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14316. {
  14317. if(OcppTempPath == NULL)
  14318. {
  14319. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14320. }
  14321. else
  14322. {
  14323. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14324. }
  14325. result = TRUE;
  14326. goto End;
  14327. }
  14328. else
  14329. {
  14330. strcpy(OcppPath,"");
  14331. }
  14332. End:
  14333. return result;
  14334. }
  14335. int GetOcppPort()
  14336. {
  14337. return OcppPort;
  14338. }
  14339. int GetOcppConnStatus(void)
  14340. {
  14341. return ShmOCPP16Data->OcppConnStatus;
  14342. }
  14343. void SetOcppConnStatus(uint8_t status)
  14344. {
  14345. ShmOCPP16Data->OcppConnStatus = status;
  14346. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14347. }
  14348. int GetHeartBeatWithNOResponse(void)
  14349. {
  14350. return HeartBeatWithNOResponse;
  14351. }
  14352. void SetHeartBeatWithNOResponse(void)
  14353. {
  14354. HeartBeatWithNOResponse = 0;
  14355. }
  14356. void GetStartTransactionIdTag(int gun_index)
  14357. {
  14358. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14359. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14360. }
  14361. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14362. {
  14363. char ch;
  14364. FILE *fptr1;
  14365. int temptransactionId;
  14366. char str[100]={0};
  14367. temptransactionId = 0;
  14368. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14369. {
  14370. DEBUG_INFO("IdTag is empty.\n");
  14371. return temptransactionId;
  14372. }
  14373. /*------ Read the file ----------------*/
  14374. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14375. if (!fptr1)
  14376. {
  14377. DEBUG_INFO("QueueTransactionId file open error.\n");
  14378. //printf(" File not found or unable to open the input file!!\n");
  14379. return temptransactionId;
  14380. }
  14381. ch=fgetc(fptr1);
  14382. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14383. rewind(fptr1);
  14384. if(ch!=EOF)
  14385. {
  14386. // printf("%c",ch);
  14387. while (fgets(str, 100, fptr1) != NULL)
  14388. {
  14389. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14390. if(str[0]=='\0')
  14391. {
  14392. break;
  14393. }
  14394. char *revbuf[8] = {0}; // Variable store string split
  14395. int num = 0;// Quantity after string split
  14396. DEBUG_INFO("Transaction queue data= %s\n", str);
  14397. splitstring(str,",",revbuf,&num); // String split
  14398. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14399. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14400. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14401. DEBUG_INFO("------------------------------\n");
  14402. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14403. {
  14404. if(isStopTransaction)
  14405. {
  14406. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14407. {
  14408. temptransactionId = atoi(revbuf[2]);
  14409. //break;
  14410. }
  14411. }
  14412. else
  14413. {
  14414. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14415. {
  14416. temptransactionId = atoi(revbuf[2]);
  14417. //break;
  14418. }
  14419. }
  14420. }
  14421. }
  14422. }
  14423. else
  14424. DEBUG_INFO("EOF\n");
  14425. fclose(fptr1);
  14426. /*------- End of reading ---------------*/
  14427. return temptransactionId;
  14428. }
  14429. void SetTransactionIdZero(int transactionId)
  14430. {
  14431. char ch;
  14432. FILE *fptr1, *fptr2;
  14433. int temptransactionId = 0;
  14434. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14435. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14436. if (!fptr1)
  14437. {
  14438. //printf(" File not found or unable to open the input file!!\n");
  14439. return ;
  14440. }
  14441. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14442. if (!fptr2)
  14443. {
  14444. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14445. fclose(fptr1);
  14446. return ;
  14447. }
  14448. ch=fgetc(fptr1);
  14449. rewind(fptr1);
  14450. if(ch!=EOF)
  14451. {
  14452. // copy all contents to the temporary file except the specific line
  14453. while (fgets(str, 100, fptr1) != NULL)
  14454. {
  14455. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14456. if(str[0]=='\0')
  14457. {
  14458. break;
  14459. }
  14460. char *revbuf[8] = {0};
  14461. int num = 0;
  14462. strcpy(strtemp, str);
  14463. splitstring(str,",",revbuf,&num);
  14464. if(revbuf[2][0] != '\0')
  14465. {
  14466. temptransactionId = atoi(revbuf[2]);
  14467. if(transactionId != temptransactionId)
  14468. {
  14469. fprintf(fptr2, "%s\n", strtemp);
  14470. }
  14471. }
  14472. }
  14473. }
  14474. fclose(fptr1);
  14475. fclose(fptr2);
  14476. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14477. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14478. /*------ Read the file ----------------*/
  14479. }
  14480. int InternetDisconnect(void)
  14481. {
  14482. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14483. }
  14484. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14485. void storeTempStopTransaction(int gun_index)
  14486. {
  14487. char guid[37]={0};
  14488. int tempIndex = 0;
  14489. char TempStopTransaction[256];
  14490. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14491. DEBUG_INFO("storeTempStopTransaction...\n");
  14492. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14493. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14494. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14495. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14496. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14497. {
  14498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14499. {
  14500. tempIndex = ((gun_index==2) ? 1: 0);
  14501. }
  14502. else
  14503. {
  14504. tempIndex = gun_index;
  14505. }
  14506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14507. {
  14508. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14509. {
  14510. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14511. }
  14512. }// END OF CHAdeMO_QUANTITY
  14513. }
  14514. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14515. {
  14516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14517. {
  14518. tempIndex = ((gun_index==2) ? 1: 0);
  14519. }
  14520. else
  14521. {
  14522. tempIndex = gun_index;
  14523. }
  14524. for (int index = 0; index < CCS_QUANTITY; index++)
  14525. {
  14526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14527. {
  14528. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14529. }
  14530. }// END OF CCS_QUANTITY
  14531. }
  14532. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14533. {
  14534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14535. {
  14536. tempIndex = ((gun_index==2) ? 1: 0);
  14537. }
  14538. else
  14539. {
  14540. tempIndex = gun_index;
  14541. }
  14542. for (int index = 0; index < GB_QUANTITY; index++)
  14543. {
  14544. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14545. {
  14546. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14547. }
  14548. }// END OF GB_QUANTITY
  14549. }
  14550. else if(gunType[gun_index] == GUN_TYPE_DO)
  14551. {
  14552. tempIndex = gun_index;
  14553. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14554. {
  14555. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14556. {
  14557. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14558. }
  14559. }
  14560. }
  14561. else
  14562. {
  14563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14564. {
  14565. tempIndex = 2;
  14566. }
  14567. else
  14568. {
  14569. tempIndex = gun_index;
  14570. }
  14571. for (int index = 0; index < AC_QUANTITY; index++)
  14572. {
  14573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14574. {
  14575. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14576. }
  14577. }// END OF AC_QUANTITY
  14578. }
  14579. //Stop Transaction Time
  14580. struct timeval tmnow;
  14581. struct tm *tm;
  14582. char buf[28];//, usec_buf[6];
  14583. gettimeofday(&tmnow, NULL);
  14584. time_t t;
  14585. t = time(NULL);
  14586. /*UTC time and date*/
  14587. tm = gmtime(&t);
  14588. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14590. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14592. random_uuid(guid);
  14593. /***********************************transactionData******************************************************/
  14594. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14596. //=================================
  14597. //1. Transaction_Begin
  14598. //=================================
  14599. //============================== Energy.Active.Import.Interval ===========================================
  14600. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14601. {
  14602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14605. 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*/]);
  14606. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14607. 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))
  14608. {
  14609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14610. }
  14611. else
  14612. {
  14613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14614. }
  14615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14617. }
  14618. //=================================
  14619. //2. Transaction_End
  14620. //=================================
  14621. //2.1====================================== Current.Import L1 ==============================================
  14622. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14623. {
  14624. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14625. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14626. {
  14627. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14628. {
  14629. tempIndex = ((gun_index==2) ? 1: 0);
  14630. }
  14631. else
  14632. {
  14633. tempIndex = gun_index;
  14634. }
  14635. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14636. {
  14637. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14638. {
  14639. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14640. }
  14641. }// End of for CHAdeMO_QUANTITY
  14642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14643. }
  14644. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14645. {
  14646. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14647. {
  14648. tempIndex = ((gun_index==2) ? 1: 0);
  14649. }
  14650. else
  14651. {
  14652. tempIndex = gun_index;
  14653. }
  14654. for (int index = 0; index < CCS_QUANTITY; index++)
  14655. {
  14656. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14657. {
  14658. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14659. }
  14660. }// End of for CCS_QUANTITY
  14661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14662. }
  14663. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14664. {
  14665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14666. {
  14667. tempIndex = ((gun_index==2) ? 1: 0);
  14668. }
  14669. else
  14670. {
  14671. tempIndex = gun_index;
  14672. }
  14673. for (int index = 0; index < GB_QUANTITY; index++)
  14674. {
  14675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14676. {
  14677. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14678. }
  14679. }// End of for GB_QUANTITY
  14680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14681. }
  14682. else if(gunType[gun_index] == GUN_TYPE_DO)
  14683. {
  14684. tempIndex = gun_index;
  14685. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14686. {
  14687. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14688. {
  14689. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14690. }
  14691. }
  14692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14693. }
  14694. else
  14695. {
  14696. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14697. {
  14698. tempIndex = 2;
  14699. }
  14700. else
  14701. {
  14702. tempIndex = gun_index;
  14703. }
  14704. for (int index = 0; index < AC_QUANTITY; index++)
  14705. {
  14706. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14707. {
  14708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14709. }
  14710. }// End of for AC_QUANTITY
  14711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14712. }
  14713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14716. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14719. }
  14720. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14721. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14722. {
  14723. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14724. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14725. {
  14726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14727. {
  14728. tempIndex = ((gun_index==2) ? 1: 0);
  14729. }
  14730. else
  14731. {
  14732. tempIndex = gun_index;
  14733. }
  14734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14735. {
  14736. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14737. {
  14738. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14739. }
  14740. }// END OF CHAdeMO_QUANTITY
  14741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14742. }
  14743. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14744. {
  14745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14746. {
  14747. tempIndex = ((gun_index==2) ? 1: 0);
  14748. }
  14749. else
  14750. {
  14751. tempIndex = gun_index;
  14752. }
  14753. for (int index = 0; index < CCS_QUANTITY; index++)
  14754. {
  14755. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14756. {
  14757. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14758. }
  14759. }// END OF CCS_QUANTITY
  14760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14761. }
  14762. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14763. {
  14764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14765. {
  14766. tempIndex = ((gun_index==2) ? 1: 0);
  14767. }
  14768. else
  14769. {
  14770. tempIndex = gun_index;
  14771. }
  14772. for (int index = 0; index < GB_QUANTITY; index++)
  14773. {
  14774. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14775. {
  14776. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14777. }
  14778. }// END OF GB_QUANTITY
  14779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14780. }
  14781. else if(gunType[gun_index] == GUN_TYPE_DO)
  14782. {
  14783. tempIndex = gun_index;
  14784. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14785. {
  14786. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14787. {
  14788. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14789. }
  14790. }
  14791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14792. }
  14793. else
  14794. {
  14795. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14796. {
  14797. tempIndex = 2;
  14798. }
  14799. else
  14800. {
  14801. tempIndex = gun_index;
  14802. }
  14803. for (int index = 0; index < AC_QUANTITY; index++)
  14804. {
  14805. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14806. {
  14807. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14808. }
  14809. }// END OF AC_QUANTITY
  14810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14811. }
  14812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14815. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14818. }
  14819. //2.3====================================== Power.Active.Import =========================================
  14820. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14821. {
  14822. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14823. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14824. {
  14825. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14826. {
  14827. tempIndex = ((gun_index==2) ? 1: 0);
  14828. }
  14829. else
  14830. {
  14831. tempIndex = gun_index;
  14832. }
  14833. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14834. {
  14835. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14836. {
  14837. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14838. }
  14839. } // End for CHAdeMO_QUANTITY
  14840. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14841. }
  14842. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14843. {
  14844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14845. {
  14846. tempIndex = ((gun_index==2) ? 1: 0);
  14847. }
  14848. else
  14849. {
  14850. tempIndex = gun_index;
  14851. }
  14852. for (int index = 0; index < CCS_QUANTITY; index++)
  14853. {
  14854. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14855. {
  14856. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14857. }
  14858. } // END for CCS_QUANTITY
  14859. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14860. }
  14861. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14862. {
  14863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14864. {
  14865. tempIndex = ((gun_index==2) ? 1: 0);
  14866. }
  14867. else
  14868. {
  14869. tempIndex = gun_index;
  14870. }
  14871. for (int index = 0; index < GB_QUANTITY; index++)
  14872. {
  14873. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14874. {
  14875. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14876. }
  14877. }// END for GB_QUANTITY
  14878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14879. }
  14880. else if(gunType[gun_index] == GUN_TYPE_DO)
  14881. {
  14882. tempIndex = gun_index;
  14883. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14884. {
  14885. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14886. {
  14887. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14888. }
  14889. }
  14890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14891. }
  14892. else
  14893. {
  14894. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14895. {
  14896. tempIndex = 2;
  14897. }
  14898. else
  14899. {
  14900. tempIndex = gun_index;
  14901. }
  14902. for (int index = 0; index < AC_QUANTITY; index++)
  14903. {
  14904. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14905. {
  14906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14907. }
  14908. } // END for AC_QUANTITY
  14909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14910. }
  14911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14914. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14915. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14917. }
  14918. //2.4====================================== Voltage L1 ====================================================
  14919. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14920. {
  14921. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14922. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14923. {
  14924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14925. {
  14926. tempIndex = ((gun_index==2) ? 1: 0);
  14927. }
  14928. else
  14929. {
  14930. tempIndex = gun_index;
  14931. }
  14932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14933. {
  14934. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14935. {
  14936. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14937. }
  14938. } // END OF FOR CHAdeMO_QUANTITY
  14939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14940. }
  14941. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14942. {
  14943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14944. {
  14945. tempIndex = ((gun_index==2) ? 1: 0);
  14946. }
  14947. else
  14948. {
  14949. tempIndex = gun_index;
  14950. }
  14951. for (int index = 0; index < CCS_QUANTITY; index++)
  14952. {
  14953. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14954. {
  14955. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14956. }
  14957. } // END OF FOR CCS_QUANTITY
  14958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14959. }
  14960. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14961. {
  14962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14963. {
  14964. tempIndex = ((gun_index==2) ? 1: 0);
  14965. }
  14966. else
  14967. {
  14968. tempIndex = gun_index;
  14969. }
  14970. for (int index = 0; index < GB_QUANTITY; index++)
  14971. {
  14972. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14973. {
  14974. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14975. }
  14976. } // END OF FOR GB_QUANTITY
  14977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14978. }
  14979. else if(gunType[gun_index] == GUN_TYPE_DO)
  14980. {
  14981. tempIndex = gun_index;
  14982. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14983. {
  14984. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14985. {
  14986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14987. }
  14988. }
  14989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14990. }
  14991. else
  14992. {
  14993. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14994. {
  14995. tempIndex = 2;
  14996. }
  14997. else
  14998. {
  14999. tempIndex = gun_index;
  15000. }
  15001. for (int index = 0; index < AC_QUANTITY; index++)
  15002. {
  15003. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15004. {
  15005. 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
  15006. }
  15007. } // END OF FOR AC_QUANTITY
  15008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15009. }
  15010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15013. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15016. }
  15017. //2.5============================================== End SoC =========================================================
  15018. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15019. {
  15020. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15021. 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))
  15022. {
  15023. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15024. {
  15025. tempIndex = ((gun_index==2) ? 1: 0);
  15026. }
  15027. else
  15028. {
  15029. tempIndex = gun_index;
  15030. }
  15031. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15032. {
  15033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15034. {
  15035. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15036. {
  15037. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15038. }
  15039. }
  15040. }
  15041. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15042. {
  15043. for (int index = 0; index < CCS_QUANTITY; index++)
  15044. {
  15045. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15046. {
  15047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15048. }
  15049. }
  15050. }
  15051. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15052. {
  15053. for (int index = 0; index < GB_QUANTITY; index++)
  15054. {
  15055. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15056. {
  15057. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15058. }
  15059. }
  15060. }
  15061. else if(gunType[gun_index] == GUN_TYPE_DO)
  15062. {
  15063. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15064. {
  15065. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15066. {
  15067. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15068. }
  15069. }
  15070. }
  15071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15077. } // END FOR DC CASE
  15078. }
  15079. //2.6====================================== Current.Import L2 ==============================================
  15080. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15081. {
  15082. // AC 3 phase L2 current
  15083. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15084. {
  15085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15086. {
  15087. tempIndex = 2;
  15088. }
  15089. else
  15090. {
  15091. tempIndex = gun_index;
  15092. }
  15093. for (int index = 0; index < AC_QUANTITY; index++)
  15094. {
  15095. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15096. {
  15097. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15098. }
  15099. }// End of for AC_QUANTITY
  15100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15101. }
  15102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15107. }
  15108. //2.7====================================== Current.Import L3 ==============================================
  15109. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15110. {
  15111. // AC 3 phase L3 current
  15112. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15113. {
  15114. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15115. {
  15116. tempIndex = 2;
  15117. }
  15118. else
  15119. {
  15120. tempIndex = gun_index;
  15121. }
  15122. for (int index = 0; index < AC_QUANTITY; index++)
  15123. {
  15124. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15125. {
  15126. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15127. }
  15128. }// End of for AC_QUANTITY
  15129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15130. }
  15131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15136. }
  15137. //2.9====================================== Voltage L2 ====================================================
  15138. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15139. {
  15140. // AC 3 phase L2 volatge
  15141. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15142. {
  15143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15144. {
  15145. tempIndex = 2;
  15146. }
  15147. else
  15148. {
  15149. tempIndex = gun_index;
  15150. }
  15151. for (int index = 0; index < AC_QUANTITY; index++)
  15152. {
  15153. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15154. {
  15155. 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
  15156. }
  15157. } // END OF FOR AC_QUANTITY
  15158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15159. }
  15160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15165. }
  15166. //2.10====================================== Voltage L3 ====================================================
  15167. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15168. {
  15169. // AC 3 phase L3 volatge
  15170. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15171. {
  15172. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15173. {
  15174. tempIndex = 2;
  15175. }
  15176. else
  15177. {
  15178. tempIndex = gun_index;
  15179. }
  15180. for (int index = 0; index < AC_QUANTITY; index++)
  15181. {
  15182. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15183. {
  15184. 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
  15185. }
  15186. } // END OF FOR AC_QUANTITY
  15187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15188. }
  15189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15194. }
  15195. //====================== Start SoC ================================
  15196. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15197. {
  15198. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15199. 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))
  15200. {
  15201. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15202. {
  15203. tempIndex = ((gun_index==2) ? 1: 0);
  15204. }
  15205. else
  15206. {
  15207. tempIndex = gun_index;
  15208. }
  15209. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15210. {
  15211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15212. {
  15213. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15214. {
  15215. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15216. }
  15217. }
  15218. }
  15219. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15220. {
  15221. for (int index = 0; index < CCS_QUANTITY; index++)
  15222. {
  15223. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15224. {
  15225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15226. }
  15227. }
  15228. }
  15229. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15230. {
  15231. for (int index = 0; index < GB_QUANTITY; index++)
  15232. {
  15233. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15234. {
  15235. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15236. }
  15237. }
  15238. }
  15239. else if(gunType[gun_index] == GUN_TYPE_DO)
  15240. {
  15241. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15242. {
  15243. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15244. {
  15245. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15246. }
  15247. }
  15248. }
  15249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15251. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15253. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15255. } // END FOR DC CASE
  15256. }
  15257. //======================================== Message create ==============================================
  15258. json_object *StopTransaction = json_object_new_object();
  15259. json_object *transactionDatas = json_object_new_array();
  15260. json_object *sampledValues = json_object_new_array();
  15261. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15262. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15263. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15264. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15265. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15266. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15267. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15268. {
  15269. json_object *transactionData = json_object_new_object();
  15270. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15271. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15272. {
  15273. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15274. {
  15275. json_object *sampledValue = json_object_new_object();
  15276. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15277. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15278. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15279. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15280. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15281. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15282. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15283. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15284. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15285. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15286. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15287. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15288. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15289. json_object_array_add(sampledValues, sampledValue);
  15290. }
  15291. }
  15292. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15293. json_object_array_add(transactionDatas, transactionData);
  15294. }
  15295. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15296. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15297. ,MESSAGE_TYPE_CALL
  15298. ,guid
  15299. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15300. json_object_put(StopTransaction);
  15301. // Check File "TempStopTransaction" Exist
  15302. if((access(TempStopTransaction,F_OK))!=-1)
  15303. {
  15304. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15305. fclose(fopen(TempStopTransaction, "w"));
  15306. }
  15307. else
  15308. {
  15309. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15310. FILE *log = fopen(TempStopTransaction, "w+");
  15311. if(log == NULL)
  15312. {
  15313. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15314. return ;
  15315. }
  15316. else
  15317. {
  15318. fclose(log);
  15319. }
  15320. }
  15321. //Add TempStopTransaction | Update TempStopTransaction
  15322. // open file for writing
  15323. FILE *outfile;
  15324. outfile = fopen (TempStopTransaction, "a");
  15325. //DEBUG_INFO("data = %s\n", queuedata);
  15326. fputs(queuedata, outfile);
  15327. fputs("\n", outfile);
  15328. fclose (outfile);
  15329. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15330. }
  15331. void checkTempStopTransaction(int gun_index)
  15332. {
  15333. FILE *fptr1;
  15334. char ch;
  15335. char str[QUEUE_MESSAGE_LENGTH]={0};
  15336. char guid[37]={0};
  15337. char tempdata[65]={0};
  15338. char connectorStr[2]={0};
  15339. char TempStopTransaction[256];
  15340. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15341. fptr1 = fopen(TempStopTransaction, "r");
  15342. //TempStopTransaction格式: 槍號,StopTransaction封包
  15343. if (!fptr1)
  15344. {
  15345. //printf(" File not found or unable to open the input file!!\n");
  15346. return ;
  15347. }
  15348. ch=fgetc(fptr1);
  15349. //printf(" Now the content of the file %s is : \n",fname);
  15350. rewind(fptr1);
  15351. if(ch!=EOF)
  15352. {
  15353. // copy all contents to the temporary file except the specific line
  15354. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15355. {
  15356. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15357. if(str[0]=='\0')
  15358. {
  15359. break;
  15360. }
  15361. //TempStopTransaction格式: 槍號,StopTransaction封包
  15362. strncpy(connectorStr, str, 1);
  15363. if(atoi(connectorStr) != (gun_index+1))
  15364. {
  15365. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15366. fclose(fptr1);
  15367. return ;
  15368. }
  15369. //random_uuid(guid);
  15370. strncpy(guid, str+6, 36); //copy guid
  15371. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15372. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15373. {
  15374. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15375. }
  15376. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15377. OCPP_insert_transaction_msg(NO, str);
  15378. memset(str,0,ARRAY_SIZE(str));
  15379. }
  15380. }
  15381. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15382. fclose(fptr1);
  15383. remove(TempStopTransaction); // remove the original file
  15384. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15385. }
  15386. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15387. {
  15388. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15389. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15390. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15391. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15392. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15393. }
  15394. int GetWebSocketPingInterval(void)
  15395. {
  15396. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15397. }
  15398. int GetServerSign(void)
  15399. {
  15400. return server_sign;
  15401. }
  15402. uint8_t GetOcppSecurityProfile()
  15403. {
  15404. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15405. }
  15406. void GetOcppChargerBoxId(uint8_t *data)
  15407. {
  15408. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15409. }
  15410. void GetOcppSecurityPassword(uint8_t *data)
  15411. {
  15412. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15413. }
  15414. void SetOcppVersion(uint8_t *version)
  15415. {
  15416. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15417. DEBUG_INFO("ocpp version: %s\n", version);
  15418. if(strstr((char*)version, "ocpp1.6") != NULL)
  15419. {
  15420. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15421. }
  15422. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15423. {
  15424. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15425. system("pkill OcppBackend");
  15426. }
  15427. }
  15428. void SetServerSign(int value)
  15429. {
  15430. server_sign = value;
  15431. }
  15432. int GetBootNotificationInterval(void)
  15433. {
  15434. return BootNotificationInterval;
  15435. }
  15436. int GetInternetConn(void)
  15437. {
  15438. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15439. }
  15440. int GetBackendConnectionTimeout(void)
  15441. {
  15442. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15443. }
  15444. int isConnectorInitMode(int gun_index)
  15445. {
  15446. int tempIndex = 0;
  15447. int result = TRUE;
  15448. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15449. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15450. {
  15451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15452. {
  15453. tempIndex = ((gun_index==2) ? 1: 0);
  15454. }
  15455. else
  15456. {
  15457. tempIndex = gun_index;
  15458. }
  15459. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15460. {
  15461. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15462. {
  15463. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15464. } //end of the same index
  15465. }//end of for CHAdeMO_QUANTITY
  15466. }
  15467. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15468. {
  15469. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15470. {
  15471. tempIndex = ((gun_index==2) ? 1: 0);
  15472. }
  15473. else
  15474. {
  15475. tempIndex = gun_index;
  15476. }
  15477. for (int index = 0; index < CCS_QUANTITY; index++)
  15478. {
  15479. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15480. {
  15481. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15482. } //end of the same index
  15483. } // end of for CCS_QUANTITY
  15484. }
  15485. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15486. {
  15487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15488. {
  15489. tempIndex = ((gun_index==2) ? 1: 0);
  15490. }
  15491. else
  15492. {
  15493. tempIndex = gun_index;
  15494. }
  15495. for (int index = 0; index < GB_QUANTITY; index++)
  15496. {
  15497. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15498. {
  15499. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15500. } //end of the same index
  15501. } // end of for GB_QUANTITY
  15502. }
  15503. else if(gunType[gun_index] == GUN_TYPE_DO)
  15504. {
  15505. tempIndex = gun_index;
  15506. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15507. {
  15508. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15509. {
  15510. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15511. } //end of the same index
  15512. }
  15513. }
  15514. else
  15515. {
  15516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15517. {
  15518. tempIndex = 2;
  15519. }
  15520. else
  15521. {
  15522. tempIndex = gun_index;
  15523. }
  15524. for (int index = 0; index < AC_QUANTITY; index++)
  15525. {
  15526. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15527. {
  15528. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15529. }//end of the same index
  15530. }//end of for AC_QUANTITY
  15531. }
  15532. return result;
  15533. }
  15534. void refreshProcDogTimer()
  15535. {
  15536. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15537. }
  15538. void InitialSystemValue(void)
  15539. {
  15540. int connectorIndex = 0;
  15541. //int valueASCII = 0;
  15542. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15543. gunTotalNumber=0;
  15544. SystemInitial = 0;
  15545. localversion=0;
  15546. BootNotificationInterval = 0;
  15547. authorizeRetryTimes = 0;
  15548. GunStatusInterval = 10;
  15549. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15550. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15551. //Hear Beat
  15552. HeartBeatWithNOResponse = 0;
  15553. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15554. FirstHeartBeat = 0;
  15555. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15556. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15557. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15558. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15559. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15560. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15561. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15562. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15563. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15564. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15565. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15566. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15567. memset(gunType, 0, ARRAY_SIZE(gunType));
  15568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15569. {
  15570. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15571. {
  15572. // DO series
  15573. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15574. {
  15575. SystemInitial = SystemInitial + 1;
  15576. gunTotalNumber = gunTotalNumber + 1;
  15577. gunType[connectorIndex] = GUN_TYPE_DO;
  15578. connectorIndex = connectorIndex + 1;
  15579. }
  15580. }
  15581. else
  15582. {
  15583. // DM, DW, DS series
  15584. //check connector / socket type (index: 8, 9, 10)
  15585. for(int index=7; index <10 ; index++)
  15586. {
  15587. if(index != 8)
  15588. {
  15589. // DC Connector
  15590. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15591. {
  15592. SystemInitial = SystemInitial + 1;
  15593. gunTotalNumber = gunTotalNumber + 1;
  15594. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15595. connectorIndex = connectorIndex + 1;
  15596. }
  15597. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15598. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15599. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15600. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15601. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15602. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15603. {
  15604. SystemInitial = SystemInitial + 1;
  15605. gunTotalNumber = gunTotalNumber + 1;
  15606. gunType[connectorIndex] = GUN_TYPE_CCS;
  15607. connectorIndex = connectorIndex + 1;
  15608. }
  15609. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15610. {
  15611. SystemInitial = SystemInitial + 1;
  15612. gunTotalNumber = gunTotalNumber + 1;
  15613. gunType[connectorIndex] = GUN_TYPE_GBT;
  15614. connectorIndex = connectorIndex + 1;
  15615. }
  15616. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15617. {
  15618. SystemInitial = SystemInitial + 1;
  15619. gunTotalNumber = gunTotalNumber + 1;
  15620. gunType[connectorIndex] = GUN_TYPE_DO;
  15621. connectorIndex = connectorIndex + 1;
  15622. }
  15623. }
  15624. else
  15625. {
  15626. // AC Connector
  15627. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15628. {
  15629. SystemInitial = SystemInitial + 1;
  15630. gunTotalNumber = gunTotalNumber + 1;
  15631. gunType[connectorIndex] = GUN_TYPE_AC;
  15632. connectorIndex = connectorIndex + 1;
  15633. }
  15634. }
  15635. }
  15636. }
  15637. //DEBUG_INFO("DC ...\n");
  15638. }
  15639. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15640. {
  15641. //check connector / socket type (index: 8, 9, 10)
  15642. for(int index=7; index <10 ; index++)
  15643. {
  15644. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15645. {
  15646. SystemInitial = SystemInitial + 1;
  15647. gunTotalNumber = gunTotalNumber + 1;
  15648. gunType[connectorIndex] = GUN_TYPE_AC;
  15649. connectorIndex = connectorIndex + 1;
  15650. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15651. }
  15652. }
  15653. }
  15654. //Status && ConnectorPlugIn Setting
  15655. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15656. {
  15657. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15658. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15659. }
  15660. for (int index = 0; index < CCS_QUANTITY; index++)
  15661. {
  15662. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15663. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15664. }
  15665. for (int index = 0; index < GB_QUANTITY; index++)
  15666. {
  15667. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15668. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15669. }
  15670. for (int index = 0; index < AC_QUANTITY; index++)
  15671. {
  15672. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15673. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15674. }
  15675. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15676. {
  15677. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15678. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15679. }
  15680. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15681. {
  15682. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15683. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15684. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15685. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15686. }
  15687. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15688. clientTime.Heartbeat=time((time_t*)NULL);
  15689. sleep(1);
  15690. }
  15691. void LWS_Send(char *str)
  15692. {
  15693. //=====================================================
  15694. // Check InternetConn 0: disconnected, 1: connected
  15695. //====================================================
  15696. if(GetOcppConnStatus() == 0)
  15697. {
  15698. DEBUG_INFO("offline now !!!\n");
  15699. return;
  15700. }
  15701. // Only disable isWebsocketSendable operation initiated by charger
  15702. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15703. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15704. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15705. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15706. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15707. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15708. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15709. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15710. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15711. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15712. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15713. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15714. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15715. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15716. {
  15717. isWebsocketSendable = 0;
  15718. }
  15719. pthread_mutex_lock(&lock_send);
  15720. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15721. sprintf((char *)SendBuffer, "%s", str);
  15722. SendBufLen = strlen(str);
  15723. pthread_mutex_unlock(&lock_send);
  15724. lws_callback_on_writable(wsi_client);
  15725. //lws_service(context, 0);
  15726. //sleep(1);
  15727. }
  15728. void LWS_SendNow(char *str)
  15729. {
  15730. //=====================================================
  15731. // Check InternetConn 0: disconnected, 1: connected
  15732. //====================================================
  15733. if(GetOcppConnStatus() == 0)
  15734. {
  15735. DEBUG_INFO("offline now !!!\n");
  15736. return;
  15737. }
  15738. // Only disable isWebsocketSendable operation initiated by charger
  15739. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15740. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15741. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15742. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15743. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15744. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15745. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15746. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15747. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15748. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15749. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15750. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15751. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15752. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15753. {
  15754. isWebsocketSendable = 0;
  15755. }
  15756. pthread_mutex_lock(&lock_send);
  15757. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15758. sprintf((char *)SendBuffer, "%s", str);
  15759. SendBufLen = strlen(str);
  15760. pthread_mutex_unlock(&lock_send);
  15761. lws_callback_on_writable(wsi_client);
  15762. lws_service(context, 0);
  15763. //sleep(1);
  15764. }