MessageHandler.c 823 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t 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 TriggerStatusNotificationReq:1; //bit 3,
  116. unsigned char isOnCharging:1; //bit 4.
  117. unsigned char :3; //bit 5~7
  118. }bits[CONNECTOR_QUANTITY];
  119. }CpinitiateMsg;
  120. CpinitiateMsg cpinitateMsg;
  121. //GetConfiguration Array
  122. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  125. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  126. #if 0
  127. static char *ChargePointErrorCodeStr[] = {
  128. MACROSTR(ConnectorLockFailure),
  129. MACROSTR(EVCommunicationError),
  130. MACROSTR(GroundFailure),
  131. MACROSTR(HighTemperature),
  132. MACROSTR(InternalError),
  133. MACROSTR(LocalListConflict),
  134. MACROSTR(NoError),
  135. MACROSTR(OtherError),
  136. MACROSTR(OverCurrentFailure),
  137. MACROSTR(OverVoltage),
  138. MACROSTR(PowerMeterFailure),
  139. MACROSTR(PowerSwitchFailure),
  140. MACROSTR(ReaderFailure),
  141. MACROSTR(ResetFailure),
  142. MACROSTR(UnderVoltage),
  143. MACROSTR(WeakSignal)
  144. };
  145. #endif
  146. static char * ChargePointStatusStr[] = {
  147. MACROSTR(Available),
  148. MACROSTR(Preparing),
  149. MACROSTR(Charging),
  150. MACROSTR(SuspendedEVSE),
  151. MACROSTR(SuspendedEV),
  152. MACROSTR(Finishing),
  153. MACROSTR(Reserved),
  154. MACROSTR(Unavailable),
  155. MACROSTR(Faulted)
  156. };
  157. static char *RegistrationStatusStr[] = {
  158. MACROSTR(Accepted),
  159. MACROSTR(Pending),
  160. MACROSTR(Rejected)
  161. };
  162. static char *AvailabilityTypeStr[] = {
  163. MACROSTR(Inoperative),
  164. MACROSTR(Operative)
  165. };
  166. static char *AvailabilityStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Rejected),
  169. MACROSTR(Scheduled)
  170. };
  171. static char *ConfigurationStatusStr[] = {
  172. MACROSTR(Accepted),
  173. MACROSTR(Rejected),
  174. MACROSTR(RebootRequired),
  175. MACROSTR(NotSupported)
  176. };
  177. static char *ClearCacheStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected)
  180. };
  181. static char *ChargingProfilePurposeTypeStr[] = {
  182. MACROSTR(ChargePointMaxProfile),
  183. MACROSTR(TxDefaultProfile),
  184. MACROSTR(TxProfile)
  185. };
  186. static char *ChargingProfileStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected),
  189. MACROSTR(NotSupported)
  190. };
  191. static char *ClearChargingProfileStatusStr[] = {
  192. MACROSTR(Accepted),
  193. MACROSTR(Unknown)
  194. };
  195. static char *GetCompositeScheduleStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected)
  198. };
  199. static char *UpdateTypeStr[] = {
  200. MACROSTR(Differential),
  201. MACROSTR(Full)
  202. };
  203. static char *UpdateStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Failed),
  206. MACROSTR(NotSupported),
  207. MACROSTR(VersionMismatch)
  208. };
  209. static char *RemoteStartStopStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Rejected)
  212. };
  213. static char *ReservationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Faulted),
  216. MACROSTR(Occupied),
  217. MACROSTR(Rejected),
  218. MACROSTR(Unavailable)
  219. };
  220. static char *ResetTypeStr[] = {
  221. MACROSTR(Hard),
  222. MACROSTR(Soft)
  223. };
  224. static char *ResetStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Rejected)
  227. };
  228. static char * DiagnosticsStatusStr[] = {
  229. MACROSTR(Idle),
  230. MACROSTR(Uploaded),
  231. MACROSTR(UploadFailed),
  232. MACROSTR(Uploading)
  233. };
  234. static char * FirmwareStatusStr[] = {
  235. MACROSTR(Downloaded),
  236. MACROSTR(DownloadFailed),
  237. MACROSTR(Downloading),
  238. MACROSTR(Idle),
  239. MACROSTR(InstallationFailed),
  240. MACROSTR(Installing),
  241. MACROSTR(Installed)
  242. };
  243. static char * MessageTriggerStr[] = {
  244. MACROSTR(BootNotification),
  245. MACROSTR(DiagnosticsStatusNotification),
  246. MACROSTR(FirmwareStatusNotification),
  247. MACROSTR(Heartbeat),
  248. MACROSTR(MeterValues),
  249. MACROSTR(StatusNotification)
  250. };
  251. static char * TriggerMessageStatusStr[] = {
  252. MACROSTR(Accepted),
  253. MACROSTR(Rejected),
  254. MACROSTR(NotImplemented)
  255. };
  256. static char * UnlockStatusStr[] = {
  257. MACROSTR(Unlocked),
  258. MACROSTR(UnlockFailed),
  259. MACROSTR(NotSupported)
  260. };
  261. #if 0
  262. static char * StopTransactionReasonStr[] = {
  263. MACROSTR(EmergencyStop),
  264. MACROSTR(EVDisconnected),
  265. MACROSTR(HardReset),
  266. MACROSTR(Local),
  267. MACROSTR(Other),
  268. MACROSTR(PowerLoss),
  269. MACROSTR(Reboot),
  270. MACROSTR(Remote),
  271. MACROSTR(SoftReset),
  272. MACROSTR(UnlockCommand),
  273. MACROSTR(DeAuthorized)
  274. };
  275. #endif
  276. static char * CancelReservationStatusStr[] = {
  277. MACROSTR(Accepted),
  278. MACROSTR(Rejected)
  279. };
  280. static char * ReadingContextStr[] = {
  281. MACROSTR(Interruption.Begin),
  282. MACROSTR(Interruption.End),
  283. MACROSTR(Other),
  284. MACROSTR(Sample.Clock),
  285. MACROSTR(Sample.Periodic),
  286. MACROSTR(Transaction.Begin),
  287. MACROSTR(Transaction.End),
  288. MACROSTR(Trigger)
  289. };
  290. static char * ValueFormatStr[] = {
  291. MACROSTR(Raw),
  292. MACROSTR(SignedData)
  293. };
  294. static char * MeasurandStr[] = {
  295. MACROSTR(Current.Export),
  296. MACROSTR(Current.Import),
  297. MACROSTR(Current.Offered),
  298. MACROSTR(Energy.Active.Export.Register),
  299. MACROSTR(Energy.Active.Import.Register),
  300. MACROSTR(Energy.Reactive.Export.Register),
  301. MACROSTR(Energy.Reactive.Import.Register),
  302. MACROSTR(Energy.Active.Export.Interval),
  303. MACROSTR(Energy.Active.Import.Interval),
  304. MACROSTR(Energy.Reactive.Export.Interval),
  305. MACROSTR(Energy.Reactive.Import.Interval),
  306. MACROSTR(Frequency),
  307. MACROSTR(Power.Active.Export),
  308. MACROSTR(Power.Active.Import),
  309. MACROSTR(Power.Factor),
  310. MACROSTR(Power.Offered),
  311. MACROSTR(Power.Reactive.ExportMACROSTR),
  312. MACROSTR(Power.Reactive.Import),
  313. MACROSTR(RPM),
  314. MACROSTR(SoC),
  315. MACROSTR(Temperature),
  316. MACROSTR(Voltage)
  317. };
  318. static char * LocationStr[] = {
  319. MACROSTR(Body),
  320. MACROSTR(Cable),
  321. MACROSTR(EV),
  322. MACROSTR(Inlet),
  323. MACROSTR(Outlet)
  324. };
  325. static char * PhaseStr[] = {
  326. MACROSTR(L1),
  327. MACROSTR(L2),
  328. MACROSTR(L3),
  329. MACROSTR(N),
  330. MACROSTR(L1-N),
  331. MACROSTR(L2-N),
  332. MACROSTR(L3-N),
  333. MACROSTR(L1-L2),
  334. MACROSTR(L2-L3),
  335. MACROSTR(L3-L1)
  336. };
  337. static char * UnitOfMeasureStr[] = {
  338. MACROSTR(Wh),
  339. MACROSTR(kWh),
  340. MACROSTR(varh),
  341. MACROSTR(kvarh),
  342. MACROSTR(W),
  343. MACROSTR(kW),
  344. MACROSTR(VA),
  345. MACROSTR(kVA),
  346. MACROSTR(var),
  347. MACROSTR(kvar),
  348. MACROSTR(A),
  349. MACROSTR(V),
  350. MACROSTR(Celsius),
  351. MACROSTR(Fahrenheit),
  352. MACROSTR(K),
  353. MACROSTR(Percent)
  354. };
  355. //=========================================
  356. // Save configuration
  357. //=========================================
  358. int runShellCmd(const char*cmd)
  359. {
  360. int result = FAIL;
  361. char buf[256];
  362. FILE *fp;
  363. fp = popen(cmd, "r");
  364. if(fp != NULL)
  365. {
  366. while(fgets(buf, sizeof(buf), fp) != NULL)
  367. {
  368. DEBUG_INFO("%s\n", buf);
  369. }
  370. result = PASS;
  371. }
  372. pclose(fp);
  373. return result;
  374. }
  375. int StoreUsrConfigData(struct SysConfigData *UsrData)
  376. {
  377. int result = PASS;
  378. int fd,wrd;
  379. unsigned int i,Chk;
  380. unsigned char *ptr, *BufTmp;
  381. int MtdBlockSize = 0x300000;
  382. Chk=0;
  383. ptr=(unsigned char *)UsrData;
  384. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  385. {
  386. memset(BufTmp,0,MtdBlockSize);
  387. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  388. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  389. Chk+=*(BufTmp+i);
  390. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  391. // Output configuration to file.
  392. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  393. if (fd < 0)
  394. {
  395. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  396. free(BufTmp);
  397. return 0;
  398. }
  399. wrd=write(fd, BufTmp, MtdBlockSize);
  400. close(fd);
  401. if(wrd<MtdBlockSize)
  402. {
  403. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  404. free(BufTmp);
  405. return 0;
  406. }
  407. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  408. DEBUG_INFO("Erase /dev/mtd10.\n");
  409. runShellCmd("flash_erase /dev/mtd10 0 0");
  410. DEBUG_INFO("Write /dev/mtd10.\n");
  411. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  412. DEBUG_INFO("Erase /dev/mtd11.\n");
  413. runShellCmd("flash_erase /dev/mtd11 0 0");
  414. DEBUG_INFO("Write /dev/mtd11.\n");
  415. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  416. system("rm -f /mnt/EvseConfig.bin");
  417. DEBUG_INFO("EvseConfig write to flash OK\n");
  418. }
  419. else
  420. {
  421. DEBUG_ERROR("alloc BlockSize NG\r\n");
  422. result = FAIL;
  423. }
  424. if(BufTmp!=NULL)
  425. free(BufTmp);
  426. return result;
  427. }
  428. //=========================================
  429. // Sqlite3 related function
  430. //=========================================
  431. static int selectSqlCount = 0;
  432. static int callback(void *data, int argc, char **argv, char **azColName){
  433. int i;
  434. //printf("%s: ", (const char*)data);
  435. selectSqlCount = argc;
  436. for(i = 0; i<argc; i++){
  437. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  438. }
  439. //printf("\n");
  440. return 0;
  441. }
  442. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  443. //int i;
  444. //printf("%s:\n", (const char*)data);
  445. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  446. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  447. return 0;
  448. }
  449. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  450. //printf("%s:\n", (const char*)data);
  451. //idTag
  452. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  453. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  454. //parentIdTag
  455. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  456. //expir_date
  457. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  458. //status
  459. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  460. //version
  461. if(columenCount > 5)
  462. idTagQuery.listVersionInt = atoi(columnValue[5]);
  463. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  464. return 0;
  465. }
  466. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  467. {
  468. // localversion = argv[5] ? atoi(argv[5]) : 0;
  469. // printf("localversion=%d\n", localversion);
  470. return 0;
  471. }
  472. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  473. {
  474. for (int i = 0; i < n_columns; i++)
  475. {
  476. DEBUG_INFO("%s\t", col_values[i]);
  477. }
  478. DEBUG_INFO("\n");
  479. return 0;
  480. }
  481. int OCPP_cleanLocalCache()
  482. {
  483. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  484. char *errMsg = 0;
  485. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  486. if (SQLITE_OK != rc)
  487. {
  488. DEBUG_INFO("SQL error: %s\n",errMsg);
  489. return FALSE;
  490. }
  491. return TRUE;
  492. }
  493. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  494. {
  495. int isSuccess = TRUE;
  496. int ret = 0;
  497. //const char* data = "Callback function called";
  498. char sql[300];
  499. char zErrMsg[200];
  500. memset(sql, 0, 300);
  501. memset(zErrMsg, 0, 200);
  502. 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);
  503. //* Execute SQL statement */
  504. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  505. if( ret != SQLITE_OK )
  506. {
  507. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  508. isSuccess = FALSE;
  509. }
  510. return isSuccess;
  511. }
  512. void OCPP_getIdTagFromLocalCache(char idTag[])
  513. {
  514. int rc = 0;
  515. char sql[100];
  516. char zErrMsg[100];
  517. memset(sql, 0, 100);
  518. memset(zErrMsg, 0, 100);
  519. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  520. memset(&idTagQuery, 0, sizeof(idTagQuery));
  521. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  522. /* Execute SQL statement */
  523. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  524. if( rc != SQLITE_OK )
  525. {
  526. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  527. }
  528. }
  529. void OCPP_getListVerion()
  530. {
  531. int rc = 0;
  532. // const char* data = "Callback function called";
  533. char sql[100];
  534. char zErrMsg[100];
  535. memset(sql, 0, 100);
  536. memset(zErrMsg, 0, 100);
  537. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. }
  545. void OCPP_get_TableAuthlocalAllData(void)
  546. {
  547. int rc = 0;
  548. char sql[100];
  549. char zErrMsg[100];
  550. memset(sql, 0, 100);
  551. memset(zErrMsg, 0, 100);
  552. sprintf(sql,"select * from ocpp_auth_local ");
  553. /* Execute SQL statement */
  554. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  555. if( rc != SQLITE_OK )
  556. {
  557. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  558. }
  559. //return ver;
  560. }
  561. int OCPP_cleanLocalList()
  562. {
  563. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  564. char *errMsg = 0;
  565. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  566. if (SQLITE_OK != rc)
  567. {
  568. DEBUG_INFO("%s\n",errMsg);
  569. return FALSE;
  570. }
  571. return TRUE;
  572. }
  573. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  574. {
  575. int isSuccess = FALSE;
  576. int ret = 0;
  577. //const char* data = "Callback function called";
  578. char sql[300];
  579. char zErrMsg[200];
  580. memset(sql, 0, 300);
  581. memset(zErrMsg, 0, 200);
  582. 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);
  583. //* Execute SQL statement */
  584. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  585. if( ret != SQLITE_OK )
  586. {
  587. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  588. return isSuccess;
  589. }
  590. memset(sql, 0, 300);
  591. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  592. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  593. if( ret != SQLITE_OK )
  594. {
  595. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  596. return isSuccess;
  597. }
  598. isSuccess = TRUE;
  599. return isSuccess;
  600. }
  601. void OCPP_getIdTagFromLocalList(char idTag[])
  602. {
  603. int rc = 0;
  604. // const char* data = "Callback function called";
  605. char sql[100];
  606. char zErrMsg[100];
  607. memset(sql, 0, 100);
  608. memset(zErrMsg, 0, 100);
  609. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  610. memset(&idTagQuery, 0, sizeof(idTagQuery));
  611. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  612. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  613. /* Execute SQL statement */
  614. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  615. if( rc != SQLITE_OK )
  616. {
  617. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  618. }
  619. //return ver;
  620. }
  621. void OCPP_deleteIdTagFromLocalList(char idTag[])
  622. {
  623. //int ver = 0;
  624. //int isSuccess = FALSE;
  625. int rc = 0;
  626. char sql[100];
  627. char zErrMsg[100];
  628. memset(sql, 0, 100);
  629. memset(zErrMsg, 0, 100);
  630. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  631. //* Execute SQL statement */
  632. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  633. if( rc != SQLITE_OK )
  634. {
  635. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  636. }
  637. }
  638. int getCurrentYear()
  639. {
  640. int result = 0;
  641. time_t CurrentTime;
  642. struct tm *tm;
  643. CurrentTime = time(NULL);
  644. tm=localtime(&CurrentTime);
  645. result = (tm->tm_year + 1900);
  646. return result;
  647. }
  648. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  649. {
  650. int result = PASS;
  651. char* errMsg = NULL;
  652. char sqlStr[8192];
  653. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  654. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  655. {
  656. result = FAIL;
  657. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  658. }
  659. 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));
  660. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  661. {
  662. result = FAIL;
  663. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  664. }
  665. return result;
  666. }
  667. //==========================================
  668. // Check time passed since today
  669. //==========================================
  670. long long DiffTimebWithNow(struct timeb ST)
  671. {
  672. //return milli-second
  673. struct timeb ET;
  674. long long StartTime,StopTime;
  675. ftime(&ET);
  676. StartTime=(long long)ST.time;
  677. StopTime=(long long)ET.time;
  678. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  679. }
  680. int getTimePassSinceToday(uint8_t gun_index)
  681. {
  682. int result = -1;
  683. static time_t lastTime[4];
  684. time_t t;
  685. struct tm *tmStartToday;
  686. struct timeb tbStartToday;
  687. t=time(NULL);
  688. if(difftime(t, lastTime[gun_index])>0)
  689. {
  690. tmStartToday=localtime(&t);
  691. tmStartToday->tm_hour = 0;
  692. tmStartToday->tm_min = 0;
  693. tmStartToday->tm_sec = 0;
  694. tbStartToday.time = mktime(tmStartToday);
  695. tbStartToday.millitm = 0;
  696. result = DiffTimebWithNow(tbStartToday)/1000;
  697. lastTime[gun_index] = t;
  698. }
  699. return result;
  700. }
  701. void getNowDatetime(uint8_t *data)
  702. {
  703. time_t t = time(NULL);
  704. struct tm tm = *localtime(&t);
  705. 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);
  706. }
  707. int syncDateTimeRTC(uint8_t *data)
  708. {
  709. struct ParsingResult
  710. {
  711. int result;
  712. int scanedElement;
  713. int year;
  714. int month;
  715. int mday;
  716. int hour;
  717. int min;
  718. int sec;
  719. int tz_hour;
  720. int tz_min;
  721. float minSec;
  722. }result;
  723. struct tm tmOrg;
  724. struct tm *tmTarget;
  725. struct timeb tbTarget;
  726. char buf[128];
  727. memset(&result, 0x00, sizeof(struct ParsingResult));
  728. result.result = PASS;
  729. if(strstr((char*)data, ".") != NULL)
  730. {
  731. // Original data with mini second
  732. if(strstr((char*)data, "Z") != NULL)
  733. {
  734. // Original data with Z
  735. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  736. &result.year,
  737. &result.month,
  738. &result.mday,
  739. &result.hour,
  740. &result.min,
  741. &result.sec,
  742. &result.minSec);
  743. }
  744. else
  745. {
  746. // Original data without Z
  747. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  748. &result.year,
  749. &result.month,
  750. &result.mday,
  751. &result.hour,
  752. &result.min,
  753. &result.sec,
  754. &result.minSec,
  755. &result.tz_hour,
  756. &result.tz_min);
  757. }
  758. }
  759. else
  760. {
  761. // Original data without mini second
  762. if(strstr((char*)data, "Z") != NULL)
  763. {
  764. // Original data with Z
  765. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  766. &result.year,
  767. &result.month,
  768. &result.mday,
  769. &result.hour,
  770. &result.min,
  771. &result.sec);
  772. }
  773. else
  774. {
  775. // Original data without Z
  776. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  777. &result.year,
  778. &result.month,
  779. &result.mday,
  780. &result.hour,
  781. &result.min,
  782. &result.sec,
  783. &result.tz_hour,
  784. &result.tz_min);
  785. }
  786. }
  787. tmOrg.tm_year = result.year - 1900;
  788. tmOrg.tm_mon = result.month - 1;
  789. tmOrg.tm_mday = result.mday;
  790. tmOrg.tm_hour = result.hour;
  791. tmOrg.tm_min = result.min;
  792. tmOrg.tm_sec = result.sec;
  793. tmOrg.tm_gmtoff = 0;
  794. tbTarget.time = mktime(&tmOrg);
  795. tbTarget.timezone = 0;
  796. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  797. tmTarget = gmtime(&tbTarget.time);
  798. 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);
  799. //DEBUG_INFO(" org date time: %s\n", data);
  800. //DEBUG_INFO("parse date time: %s\n", buf);
  801. system(buf);
  802. system("/sbin/hwclock -w --systohc");
  803. if(result.scanedElement < 6)
  804. result.result = FAIL;
  805. return result.result;
  806. }
  807. //==========================================
  808. // GetCompositeSchedule logic related function
  809. //==========================================
  810. int DiffTimebSec(struct timeb ST, struct timeb ET)
  811. {
  812. //return milli-second
  813. unsigned int StartTime,StopTime;
  814. StartTime=(unsigned int)ST.time;
  815. StopTime=(unsigned int)ET.time;
  816. return (StopTime-StartTime);
  817. }
  818. int DiffTimebWithNowSec(struct timeb ST)
  819. {
  820. //return milli-second
  821. struct timeb ET;
  822. unsigned int StartTime,StopTime;
  823. ftime(&ET);
  824. StartTime=(unsigned int)ST.time;
  825. StopTime=(unsigned int)ET.time;
  826. return (StopTime-StartTime);
  827. }
  828. int getStartStop(uint8_t *start, uint8_t *stop)
  829. {
  830. int result = -1;
  831. struct tm tmStart;
  832. struct timeb tbStart;
  833. struct tm tmStop;
  834. struct timeb tbStop;
  835. 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) &&
  836. (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))
  837. {
  838. //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);
  839. //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);
  840. tmStart.tm_year -= 1900;
  841. tmStart.tm_mon -= 1;
  842. tbStart.time = mktime(&tmStart);
  843. tbStart.millitm = 0;
  844. tmStop.tm_year -= 1900;
  845. tmStop.tm_mon -= 1;
  846. tbStop.time = mktime(&tmStop);
  847. tbStop.millitm = 0;
  848. result = DiffTimebSec(tbStart, tbStop);
  849. //DEBUG_INFO("getStartStop(): %d\n", result);
  850. }
  851. else
  852. {
  853. DEBUG_WARN("Start or stop date parsing error.\r\n");
  854. }
  855. return result;
  856. }
  857. int isOvertNow(uint8_t *start)
  858. {
  859. int result = NO;
  860. struct tm tmStart;
  861. struct timeb tbStart;
  862. 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))
  863. {
  864. //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);
  865. tmStart.tm_year -= 1900;
  866. tmStart.tm_mon -= 1;
  867. tbStart.time = mktime(&tmStart);
  868. tbStart.millitm = 0;
  869. if(DiffTimebWithNowSec(tbStart) <= 0)
  870. result = NO;
  871. else
  872. result = YES;
  873. }
  874. else
  875. {
  876. DEBUG_WARN("Start date parsing error.\n");
  877. }
  878. return result;
  879. }
  880. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  881. {
  882. int result = -1;
  883. struct tm tmStart;
  884. struct timeb tbStart;
  885. struct tm tmStop;
  886. struct timeb tbStop;
  887. 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) &&
  888. (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))
  889. {
  890. tmStart.tm_year -= 1900;
  891. tmStart.tm_mon -= 1;
  892. tbStart.time = mktime(&tmStart);
  893. tbStart.millitm = 0;
  894. tmStop.tm_year -= 1900;
  895. tmStop.tm_mon -= 1;
  896. tbStop.time = mktime(&tmStop);
  897. tbStop.millitm = 0;
  898. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  899. }
  900. return result;
  901. }
  902. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  903. {
  904. FILE *fp;
  905. char profileFileName[128];
  906. char *line = NULL;
  907. size_t len = 0;
  908. time_t CurrentTime;
  909. struct tm *tmComposite;
  910. struct StructChargingProfile maxProfile;
  911. uint8_t limitMax=0;
  912. int compositePeriodIdx = 0;
  913. CurrentTime = time(NULL);
  914. tmComposite=localtime(&CurrentTime);
  915. 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);
  916. if(isUnitA)
  917. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  918. else
  919. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  920. compositeProfile->ChargingSchedule.Duration = durationReq;
  921. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  922. {
  923. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  924. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  925. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  926. }
  927. compositeProfile->ChargingProfileId = 0;
  928. compositeProfile->StackLevel = 99 ;
  929. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  930. maxProfile.ChargingProfileId = -1;
  931. maxProfile.ChargingSchedule.Duration = -1;
  932. system("rm -f /tmp/*.json");
  933. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  934. // Search max profile
  935. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  936. if((access(profileFileName, F_OK))!=-1)
  937. {
  938. fp = fopen(profileFileName, "r");
  939. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  940. {
  941. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  942. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  943. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  944. }
  945. maxProfile.ChargingProfileId = -1;
  946. maxProfile.StackLevel = -1;
  947. while(getline(&line, &len, fp) != -1)
  948. {
  949. json_object *obj = NULL;
  950. obj = json_tokener_parse(line);
  951. if(is_error(obj))
  952. {
  953. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  954. }
  955. else
  956. {
  957. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  958. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  959. )
  960. {
  961. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  962. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  963. )
  964. {
  965. struct tm tmFrom, tmTo;
  966. struct timeb tbFrom, tbTo;
  967. 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) &&
  968. (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))
  969. {
  970. tmFrom.tm_year -= 1900;
  971. tmFrom.tm_mon -= 1;
  972. tbFrom.time = mktime(&tmFrom);
  973. tmTo.tm_year -= 1900;
  974. tmTo.tm_mon -= 1;
  975. tbTo.time = mktime(&tmTo);
  976. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  977. {
  978. if(maxProfile.ChargingProfileId == -1)
  979. DEBUG_INFO("MaxProfile found.\n");
  980. else
  981. DEBUG_INFO("MaxProfile updated.\n");
  982. // Required item
  983. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  984. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  985. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  986. if(isUnitA)
  987. {
  988. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  989. 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++)
  990. {
  991. 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"));
  992. 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?
  993. 3:
  994. 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")));
  995. 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")));
  996. }
  997. }
  998. else
  999. {
  1000. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1001. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1002. {
  1003. 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"));
  1004. 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?
  1005. 3:
  1006. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1007. 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));
  1008. }
  1009. }
  1010. // Optional item
  1011. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1012. {
  1013. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1014. }
  1015. else
  1016. {
  1017. sprintf((char*)maxProfile.ValidFrom, " ");
  1018. }
  1019. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1020. {
  1021. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1022. }
  1023. else
  1024. {
  1025. sprintf((char*)maxProfile.ValidTo, " ");
  1026. }
  1027. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1028. {
  1029. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1030. }
  1031. else
  1032. {
  1033. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1034. }
  1035. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1036. {
  1037. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1038. }
  1039. else
  1040. {
  1041. maxProfile.TransactionId = -1;
  1042. }
  1043. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1044. {
  1045. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1046. }
  1047. else
  1048. {
  1049. maxProfile.ChargingSchedule.Duration = 86400;
  1050. }
  1051. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1052. {
  1053. 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")));
  1054. }
  1055. else
  1056. {
  1057. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1058. }
  1059. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1060. {
  1061. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1062. }
  1063. else
  1064. {
  1065. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1066. }
  1067. }
  1068. }
  1069. }
  1070. else
  1071. {
  1072. if(maxProfile.ChargingProfileId == -1)
  1073. DEBUG_INFO("MaxProfile found.\n");
  1074. else
  1075. DEBUG_INFO("MaxProfile updated.\n");
  1076. // Required item
  1077. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1078. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1079. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1080. if(isUnitA)
  1081. {
  1082. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1083. 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++)
  1084. {
  1085. 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"));
  1086. 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?
  1087. 3:
  1088. 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")));
  1089. 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")));
  1090. }
  1091. }
  1092. else
  1093. {
  1094. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1095. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1096. {
  1097. 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"));
  1098. 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?
  1099. 3:
  1100. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1101. 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));
  1102. }
  1103. }
  1104. // Optional item
  1105. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1106. {
  1107. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1108. }
  1109. else
  1110. {
  1111. sprintf((char*)maxProfile.ValidFrom, " ");
  1112. }
  1113. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1114. {
  1115. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1116. }
  1117. else
  1118. {
  1119. sprintf((char*)maxProfile.ValidTo, " ");
  1120. }
  1121. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1122. {
  1123. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1124. }
  1125. else
  1126. {
  1127. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1128. }
  1129. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1130. {
  1131. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1132. }
  1133. else
  1134. {
  1135. maxProfile.TransactionId = -1;
  1136. }
  1137. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1138. {
  1139. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1140. }
  1141. else
  1142. {
  1143. maxProfile.ChargingSchedule.Duration = 86400;
  1144. }
  1145. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1146. {
  1147. 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")));
  1148. }
  1149. else
  1150. {
  1151. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1152. }
  1153. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1154. {
  1155. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1156. }
  1157. else
  1158. {
  1159. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1160. }
  1161. }
  1162. }
  1163. }
  1164. json_object_put(obj);
  1165. }
  1166. fclose(fp);
  1167. /*
  1168. if(maxProfile.ChargingProfileId !=-1)
  1169. {
  1170. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1171. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1172. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1173. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1174. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1175. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1176. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1177. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1178. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1179. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1180. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1181. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1182. {
  1183. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1184. {
  1185. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1186. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1187. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1188. }
  1189. }
  1190. }
  1191. else
  1192. DEBUG_INFO("MaxProfile not found.\n");
  1193. DEBUG_INFO("------------------------------------\n");*/
  1194. }
  1195. if(maxProfile.ChargingProfileId != -1)
  1196. {
  1197. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1198. {
  1199. if(maxProfile.ChargingSchedule.Duration != -1)
  1200. {
  1201. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1202. 0:
  1203. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1204. }
  1205. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1206. {
  1207. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1208. {
  1209. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1210. 0:
  1211. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1212. if(idxPeriod > 0)
  1213. {
  1214. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1215. {
  1216. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1217. }
  1218. }
  1219. }
  1220. }
  1221. }
  1222. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1223. {
  1224. if(maxProfile.ChargingSchedule.Duration != -1)
  1225. {
  1226. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1227. }
  1228. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1229. {
  1230. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1231. {
  1232. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1233. if(idxPeriod > 0)
  1234. {
  1235. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1236. {
  1237. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1238. }
  1239. }
  1240. }
  1241. }
  1242. }
  1243. else
  1244. {
  1245. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1246. {
  1247. if(maxProfile.ChargingSchedule.Duration != -1)
  1248. {
  1249. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1250. 0:
  1251. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1252. }
  1253. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1254. {
  1255. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1256. {
  1257. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1258. 0:
  1259. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1260. if(idxPeriod > 0)
  1261. {
  1262. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1263. {
  1264. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1265. }
  1266. }
  1267. }
  1268. }
  1269. }
  1270. else
  1271. {
  1272. if(maxProfile.ChargingSchedule.Duration != -1)
  1273. {
  1274. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1275. 0:
  1276. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1277. }
  1278. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1279. {
  1280. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1281. {
  1282. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1283. 0:
  1284. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1285. if(idxPeriod > 0)
  1286. {
  1287. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1288. {
  1289. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }
  1295. }
  1296. /*
  1297. DEBUG_INFO("MaxProfile after align.\n");
  1298. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1299. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1300. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1301. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1302. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1303. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1304. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1305. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1306. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1307. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1308. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1309. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1310. {
  1311. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1312. {
  1313. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1314. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1315. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1316. }
  1317. }
  1318. DEBUG_INFO("------------------------------------\n");*/
  1319. }
  1320. // Find each profile period quantity
  1321. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1322. {
  1323. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1324. limitMax = idx+1;
  1325. }
  1326. if(maxProfile.ChargingProfileId != -1)
  1327. {
  1328. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1329. {
  1330. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1331. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1332. (maxProfile.ChargingSchedule.Duration > 0))
  1333. {
  1334. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1335. {
  1336. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1337. compositePeriodIdx++;
  1338. }
  1339. else
  1340. {
  1341. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1342. }
  1343. }
  1344. }
  1345. }
  1346. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1347. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1348. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1349. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1350. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1351. {
  1352. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1353. {
  1354. compositeProfile->ChargingProfileId = 1;
  1355. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1356. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1357. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1358. }
  1359. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1360. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1361. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1362. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1363. }
  1364. if(line)
  1365. free(line);
  1366. }
  1367. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1368. {
  1369. FILE *fp;
  1370. char profileFileName[128];
  1371. char *line = NULL;
  1372. size_t len = 0;
  1373. time_t CurrentTime;
  1374. struct tm *tmComposite;
  1375. struct StructChargingProfile maxProfile;
  1376. struct StructChargingProfile defaultTxProfile;
  1377. struct StructChargingProfile txProfile;
  1378. struct StructChargingSchedulePeriod tmpPeriod;
  1379. uint8_t limitMax=0;
  1380. uint8_t limitDef=0;
  1381. uint8_t limitTx=0;
  1382. int compositePeriodIdx = 0;
  1383. CurrentTime = time(NULL);
  1384. tmComposite=localtime(&CurrentTime);
  1385. 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);
  1386. if(isUnitA)
  1387. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1388. else
  1389. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1390. compositeProfile->ChargingSchedule.Duration = durationReq;
  1391. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1392. {
  1393. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1394. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1395. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1396. }
  1397. compositeProfile->ChargingProfileId = 0;
  1398. compositeProfile->StackLevel = 99 ;
  1399. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1400. maxProfile.ChargingProfileId = -1;
  1401. defaultTxProfile.ChargingProfileId = -1;
  1402. txProfile.ChargingProfileId = -1;
  1403. maxProfile.ChargingSchedule.Duration = -1;
  1404. defaultTxProfile.ChargingSchedule.Duration = -1;
  1405. txProfile.ChargingSchedule.Duration = -1;
  1406. system("rm -f /tmp/*.json");
  1407. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1408. /*
  1409. * Search valid charging profile
  1410. */
  1411. //DEBUG_INFO("====================================\n");
  1412. // Search tx profile
  1413. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1414. if((access(profileFileName, F_OK))!=-1)
  1415. {
  1416. fp = fopen(profileFileName, "r");
  1417. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1418. {
  1419. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1420. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1421. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1422. }
  1423. txProfile.ChargingProfileId = -1;
  1424. txProfile.StackLevel = -1;
  1425. while(getline(&line, &len, fp) != -1)
  1426. {
  1427. json_object *obj = NULL;
  1428. obj = json_tokener_parse(line);
  1429. if(is_error(obj))
  1430. {
  1431. DEBUG_ERROR("Parse txProfile from file error.\n");
  1432. }
  1433. else
  1434. {
  1435. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1436. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1437. )
  1438. {
  1439. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1440. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1441. )
  1442. {
  1443. struct tm tmFrom, tmTo;
  1444. struct timeb tbFrom, tbTo;
  1445. 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) &&
  1446. (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))
  1447. {
  1448. tmFrom.tm_year -= 1900;
  1449. tmFrom.tm_mon -= 1;
  1450. tbFrom.time = mktime(&tmFrom);
  1451. tmTo.tm_year -= 1900;
  1452. tmTo.tm_mon -= 1;
  1453. tbTo.time = mktime(&tmTo);
  1454. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1455. {
  1456. if(txProfile.ChargingProfileId == -1)
  1457. DEBUG_INFO("TxProfile found.\n");
  1458. else
  1459. DEBUG_INFO("TxProfile updated.\n");
  1460. // Required item
  1461. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1462. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1463. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1464. if(isUnitA)
  1465. {
  1466. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1467. 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++)
  1468. {
  1469. 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"));
  1470. 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?
  1471. 3:
  1472. 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")));
  1473. 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")));
  1474. }
  1475. }
  1476. else
  1477. {
  1478. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1479. 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++)
  1480. {
  1481. 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"));
  1482. 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?
  1483. 3:
  1484. 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")));
  1485. 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));
  1486. }
  1487. }
  1488. // Optional item
  1489. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1490. {
  1491. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1492. }
  1493. else
  1494. {
  1495. sprintf((char*)txProfile.ValidFrom, " ");
  1496. }
  1497. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1498. {
  1499. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1500. }
  1501. else
  1502. {
  1503. sprintf((char*)txProfile.ValidTo, " ");
  1504. }
  1505. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1506. {
  1507. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1508. }
  1509. else
  1510. {
  1511. sprintf((char*)txProfile.RecurrencyKind, " ");
  1512. }
  1513. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1514. {
  1515. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1516. }
  1517. else
  1518. {
  1519. txProfile.TransactionId = -1;
  1520. }
  1521. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1522. {
  1523. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1524. }
  1525. else
  1526. {
  1527. txProfile.ChargingSchedule.Duration = 86400;
  1528. }
  1529. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1530. {
  1531. 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")));
  1532. }
  1533. else
  1534. {
  1535. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1536. }
  1537. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1538. {
  1539. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1540. }
  1541. else
  1542. {
  1543. txProfile.ChargingSchedule.MinChargingRate = -1;
  1544. }
  1545. }
  1546. }
  1547. }
  1548. else
  1549. {
  1550. if(txProfile.ChargingProfileId == -1)
  1551. DEBUG_INFO("TxProfile found.\n");
  1552. else
  1553. DEBUG_INFO("TxProfile updated.\n");
  1554. // Required item
  1555. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1556. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1557. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1558. if(isUnitA)
  1559. {
  1560. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1561. 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++)
  1562. {
  1563. 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"));
  1564. 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?
  1565. 3:
  1566. 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")));
  1567. 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")));
  1568. }
  1569. }
  1570. else
  1571. {
  1572. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1573. 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++)
  1574. {
  1575. 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"));
  1576. 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?
  1577. 3:
  1578. 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")));
  1579. 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));
  1580. }
  1581. }
  1582. // Optional item
  1583. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1584. {
  1585. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1586. }
  1587. else
  1588. {
  1589. sprintf((char*)txProfile.ValidFrom, " ");
  1590. }
  1591. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1592. {
  1593. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1594. }
  1595. else
  1596. {
  1597. sprintf((char*)txProfile.ValidTo, " ");
  1598. }
  1599. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1600. {
  1601. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1602. }
  1603. else
  1604. {
  1605. sprintf((char*)txProfile.RecurrencyKind, " ");
  1606. }
  1607. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1608. {
  1609. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1610. }
  1611. else
  1612. {
  1613. txProfile.TransactionId = -1;
  1614. }
  1615. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1616. {
  1617. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1618. }
  1619. else
  1620. {
  1621. txProfile.ChargingSchedule.Duration = 86400;
  1622. }
  1623. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1624. {
  1625. 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")));
  1626. }
  1627. else
  1628. {
  1629. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1630. }
  1631. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1632. {
  1633. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1634. }
  1635. else
  1636. {
  1637. txProfile.ChargingSchedule.MinChargingRate = -1;
  1638. }
  1639. }
  1640. }
  1641. }
  1642. json_object_put(obj);
  1643. }
  1644. fclose(fp);
  1645. /*
  1646. if(txProfile.ChargingProfileId != -1)
  1647. {
  1648. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1649. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1650. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1651. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1652. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1653. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1654. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1655. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1656. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1657. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1658. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1659. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1660. {
  1661. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1662. {
  1663. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1664. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1665. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1666. }
  1667. }
  1668. }
  1669. else
  1670. DEBUG_INFO("TxProfile not found.\n");*/
  1671. }
  1672. // Search default tx profile
  1673. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1674. if((access(profileFileName, F_OK))==-1)
  1675. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1676. if((access(profileFileName, F_OK))!=-1)
  1677. {
  1678. fp = fopen(profileFileName, "r");
  1679. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1680. {
  1681. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1682. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1683. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1684. }
  1685. defaultTxProfile.ChargingProfileId = -1;
  1686. defaultTxProfile.StackLevel = -1;
  1687. while(getline(&line, &len, fp) != -1)
  1688. {
  1689. json_object *obj = NULL;
  1690. obj = json_tokener_parse(line);
  1691. if(is_error(obj))
  1692. {
  1693. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1694. }
  1695. else
  1696. {
  1697. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1698. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1699. )
  1700. {
  1701. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1702. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1703. )
  1704. {
  1705. struct tm tmFrom, tmTo;
  1706. struct timeb tbFrom, tbTo;
  1707. 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) &&
  1708. (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))
  1709. {
  1710. tmFrom.tm_year -= 1900;
  1711. tmFrom.tm_mon -= 1;
  1712. tbFrom.time = mktime(&tmFrom);
  1713. tmTo.tm_year -= 1900;
  1714. tmTo.tm_mon -= 1;
  1715. tbTo.time = mktime(&tmTo);
  1716. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1717. {
  1718. if(defaultTxProfile.ChargingProfileId == -1)
  1719. DEBUG_INFO("TxDefaultProfile found.\n");
  1720. else
  1721. DEBUG_INFO("TxDefaultProfile updated.\n");
  1722. // Required item
  1723. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1724. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1725. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1726. if(isUnitA)
  1727. {
  1728. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1729. 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++)
  1730. {
  1731. 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"));
  1732. 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?
  1733. 3:
  1734. 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")));
  1735. 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")));
  1736. }
  1737. }
  1738. else
  1739. {
  1740. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1741. 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++)
  1742. {
  1743. 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"));
  1744. 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?
  1745. 3:
  1746. 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")));
  1747. 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));
  1748. }
  1749. }
  1750. // Optional item
  1751. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1752. {
  1753. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1754. }
  1755. else
  1756. {
  1757. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1758. }
  1759. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1760. {
  1761. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1762. }
  1763. else
  1764. {
  1765. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1766. }
  1767. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1768. {
  1769. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1770. }
  1771. else
  1772. {
  1773. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1774. }
  1775. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1776. {
  1777. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1778. }
  1779. else
  1780. {
  1781. defaultTxProfile.TransactionId = -1;
  1782. }
  1783. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1784. {
  1785. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1786. }
  1787. else
  1788. {
  1789. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1790. }
  1791. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1792. {
  1793. 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")));
  1794. }
  1795. else
  1796. {
  1797. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1798. }
  1799. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1800. {
  1801. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1802. }
  1803. else
  1804. {
  1805. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1806. }
  1807. }
  1808. }
  1809. }
  1810. else
  1811. {
  1812. if(defaultTxProfile.ChargingProfileId == -1)
  1813. DEBUG_INFO("TxDefaultProfile found.\n");
  1814. else
  1815. DEBUG_INFO("TxDefaultProfile updated.\n");
  1816. // Required item
  1817. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1818. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1819. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1820. if(isUnitA)
  1821. {
  1822. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1823. 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++)
  1824. {
  1825. 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"));
  1826. 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?
  1827. 3:
  1828. 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")));
  1829. 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")));
  1830. }
  1831. }
  1832. else
  1833. {
  1834. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1835. 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++)
  1836. {
  1837. 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"));
  1838. 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?
  1839. 3:
  1840. 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")));
  1841. 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));
  1842. }
  1843. }
  1844. // Optional item
  1845. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1846. {
  1847. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1848. }
  1849. else
  1850. {
  1851. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1852. }
  1853. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1854. {
  1855. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1856. }
  1857. else
  1858. {
  1859. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1860. }
  1861. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1862. {
  1863. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1864. }
  1865. else
  1866. {
  1867. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1868. }
  1869. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1870. {
  1871. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1872. }
  1873. else
  1874. {
  1875. defaultTxProfile.TransactionId = -1;
  1876. }
  1877. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1878. {
  1879. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1880. }
  1881. else
  1882. {
  1883. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1884. }
  1885. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1886. {
  1887. 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")));
  1888. }
  1889. else
  1890. {
  1891. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1892. }
  1893. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1894. {
  1895. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1896. }
  1897. else
  1898. {
  1899. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1900. }
  1901. }
  1902. }
  1903. }
  1904. json_object_put(obj);
  1905. }
  1906. fclose(fp);
  1907. /*
  1908. if(defaultTxProfile.ChargingProfileId != -1)
  1909. {
  1910. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1911. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1912. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1913. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1914. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1915. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1916. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1917. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1918. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1919. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1920. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1921. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1922. {
  1923. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1924. {
  1925. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1926. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1927. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1928. }
  1929. }
  1930. }
  1931. else
  1932. DEBUG_INFO("TxDefaultProfile not found.\n");
  1933. DEBUG_INFO("------------------------------------\n");*/
  1934. }
  1935. // Search max profile
  1936. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1937. if((access(profileFileName, F_OK))!=-1)
  1938. {
  1939. fp = fopen(profileFileName, "r");
  1940. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1941. {
  1942. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1943. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1944. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1945. }
  1946. maxProfile.ChargingProfileId = -1;
  1947. maxProfile.StackLevel = -1;
  1948. while(getline(&line, &len, fp) != -1)
  1949. {
  1950. json_object *obj = NULL;
  1951. obj = json_tokener_parse(line);
  1952. if(is_error(obj))
  1953. {
  1954. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1955. }
  1956. else
  1957. {
  1958. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1959. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1960. )
  1961. {
  1962. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1963. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1964. )
  1965. {
  1966. struct tm tmFrom, tmTo;
  1967. struct timeb tbFrom, tbTo;
  1968. 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) &&
  1969. (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))
  1970. {
  1971. tmFrom.tm_year -= 1900;
  1972. tmFrom.tm_mon -= 1;
  1973. tbFrom.time = mktime(&tmFrom);
  1974. tmTo.tm_year -= 1900;
  1975. tmTo.tm_mon -= 1;
  1976. tbTo.time = mktime(&tmTo);
  1977. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1978. {
  1979. if(maxProfile.ChargingProfileId == -1)
  1980. DEBUG_INFO("MaxProfile found.\n");
  1981. else
  1982. DEBUG_INFO("MaxProfile updated.\n");
  1983. // Required item
  1984. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1985. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1986. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1987. if(isUnitA)
  1988. {
  1989. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1990. 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++)
  1991. {
  1992. 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"));
  1993. 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?
  1994. 3:
  1995. 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")));
  1996. 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")));
  1997. }
  1998. }
  1999. else
  2000. {
  2001. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2002. 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++)
  2003. {
  2004. 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"));
  2005. 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?
  2006. 3:
  2007. 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")));
  2008. 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));
  2009. }
  2010. }
  2011. // Optional item
  2012. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2013. {
  2014. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2015. }
  2016. else
  2017. {
  2018. sprintf((char*)maxProfile.ValidFrom, " ");
  2019. }
  2020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2021. {
  2022. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2023. }
  2024. else
  2025. {
  2026. sprintf((char*)maxProfile.ValidTo, " ");
  2027. }
  2028. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2029. {
  2030. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2031. }
  2032. else
  2033. {
  2034. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2035. }
  2036. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2037. {
  2038. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2039. }
  2040. else
  2041. {
  2042. maxProfile.TransactionId = -1;
  2043. }
  2044. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2045. {
  2046. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2047. }
  2048. else
  2049. {
  2050. maxProfile.ChargingSchedule.Duration = 86400;
  2051. }
  2052. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2053. {
  2054. 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")));
  2055. }
  2056. else
  2057. {
  2058. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2059. }
  2060. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2061. {
  2062. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2063. }
  2064. else
  2065. {
  2066. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2067. }
  2068. }
  2069. }
  2070. }
  2071. else
  2072. {
  2073. if(maxProfile.ChargingProfileId == -1)
  2074. DEBUG_INFO("MaxProfile found.\n");
  2075. else
  2076. DEBUG_INFO("MaxProfile updated.\n");
  2077. // Required item
  2078. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2079. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2080. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2081. if(isUnitA)
  2082. {
  2083. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2084. 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++)
  2085. {
  2086. 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"));
  2087. 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?
  2088. 3:
  2089. 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")));
  2090. 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")));
  2091. }
  2092. }
  2093. else
  2094. {
  2095. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2096. 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++)
  2097. {
  2098. 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"));
  2099. 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?
  2100. 3:
  2101. 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")));
  2102. 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));
  2103. }
  2104. }
  2105. // Optional item
  2106. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2107. {
  2108. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2109. }
  2110. else
  2111. {
  2112. sprintf((char*)maxProfile.ValidFrom, " ");
  2113. }
  2114. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2115. {
  2116. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2117. }
  2118. else
  2119. {
  2120. sprintf((char*)maxProfile.ValidTo, " ");
  2121. }
  2122. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2123. {
  2124. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2125. }
  2126. else
  2127. {
  2128. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2129. }
  2130. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2131. {
  2132. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2133. }
  2134. else
  2135. {
  2136. maxProfile.TransactionId = -1;
  2137. }
  2138. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2139. {
  2140. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2141. }
  2142. else
  2143. {
  2144. maxProfile.ChargingSchedule.Duration = 86400;
  2145. }
  2146. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2147. {
  2148. 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")));
  2149. }
  2150. else
  2151. {
  2152. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2153. }
  2154. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2155. {
  2156. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2157. }
  2158. else
  2159. {
  2160. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2161. }
  2162. }
  2163. }
  2164. }
  2165. json_object_put(obj);
  2166. }
  2167. fclose(fp);
  2168. /*
  2169. if(maxProfile.ChargingProfileId !=-1)
  2170. {
  2171. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2172. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2173. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2174. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2175. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2176. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2177. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2178. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2179. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2180. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2181. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2182. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2183. {
  2184. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2185. {
  2186. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2187. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2188. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2189. }
  2190. }
  2191. }
  2192. else
  2193. DEBUG_INFO("MaxProfile not found.\n");
  2194. DEBUG_INFO("------------------------------------\n");*/
  2195. }
  2196. /*
  2197. * Align found profile start schedule & periods
  2198. */
  2199. //DEBUG_INFO("====================================\n");
  2200. /*
  2201. // For local test usage, force modify found profile start schedule info
  2202. 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);
  2203. 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);
  2204. 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);
  2205. */
  2206. if(txProfile.ChargingProfileId != -1)
  2207. {
  2208. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2209. {
  2210. if(txProfile.ChargingSchedule.Duration != -1)
  2211. {
  2212. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2213. 0:
  2214. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2215. }
  2216. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2217. {
  2218. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2219. {
  2220. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2221. 0:
  2222. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2223. if(idxPeriod > 0)
  2224. {
  2225. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2226. {
  2227. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2228. }
  2229. }
  2230. }
  2231. }
  2232. }
  2233. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2234. {
  2235. if(txProfile.ChargingSchedule.Duration != -1)
  2236. {
  2237. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2238. 0:
  2239. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2240. }
  2241. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2242. {
  2243. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2244. {
  2245. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2246. 0:
  2247. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2248. if(idxPeriod > 0)
  2249. {
  2250. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2251. {
  2252. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2253. }
  2254. }
  2255. }
  2256. }
  2257. }
  2258. else
  2259. {
  2260. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2261. {
  2262. if(txProfile.ChargingSchedule.Duration != -1)
  2263. {
  2264. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2265. 0:
  2266. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2267. }
  2268. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2269. {
  2270. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2271. {
  2272. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2273. 0:
  2274. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2275. if(idxPeriod > 0)
  2276. {
  2277. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2278. {
  2279. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2280. }
  2281. }
  2282. }
  2283. }
  2284. }
  2285. else
  2286. {
  2287. if(txProfile.ChargingSchedule.Duration != -1)
  2288. {
  2289. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2290. 0:
  2291. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2292. }
  2293. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2294. {
  2295. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2296. {
  2297. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2298. 0:
  2299. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2300. if(idxPeriod > 0)
  2301. {
  2302. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2303. {
  2304. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2305. }
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. /*
  2312. DEBUG_INFO("txProfile after align.\n");
  2313. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2314. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2315. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2316. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2317. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2318. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2319. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2320. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2321. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2322. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2323. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2324. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2325. {
  2326. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2327. {
  2328. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2329. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2330. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2331. }
  2332. }*/
  2333. }
  2334. if(defaultTxProfile.ChargingProfileId != -1)
  2335. {
  2336. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2337. {
  2338. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2339. {
  2340. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2341. 0:
  2342. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2343. }
  2344. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2345. {
  2346. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2347. {
  2348. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2349. 0:
  2350. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2351. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2352. {
  2353. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2354. }
  2355. if(idxPeriod > 0)
  2356. {
  2357. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2358. {
  2359. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2360. }
  2361. }
  2362. }
  2363. }
  2364. }
  2365. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2366. {
  2367. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2368. {
  2369. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2370. 0:
  2371. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2372. }
  2373. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2374. {
  2375. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2376. {
  2377. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2378. 0:
  2379. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2380. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2381. {
  2382. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2383. }
  2384. if(idxPeriod > 0)
  2385. {
  2386. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2387. {
  2388. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2389. }
  2390. }
  2391. }
  2392. }
  2393. }
  2394. else
  2395. {
  2396. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2397. {
  2398. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2399. {
  2400. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2401. 0:
  2402. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2403. }
  2404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2405. {
  2406. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2407. {
  2408. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2409. 0:
  2410. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2411. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2412. {
  2413. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2414. }
  2415. if(idxPeriod > 0)
  2416. {
  2417. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2418. {
  2419. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. else
  2426. {
  2427. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2428. {
  2429. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2430. 0:
  2431. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2432. }
  2433. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2434. {
  2435. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2436. {
  2437. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2438. 0:
  2439. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2440. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2441. {
  2442. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2443. }
  2444. if(idxPeriod > 0)
  2445. {
  2446. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2447. {
  2448. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2449. }
  2450. }
  2451. }
  2452. }
  2453. }
  2454. }
  2455. /*
  2456. DEBUG_INFO("defaultTxProfile after align.\n");
  2457. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2458. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2459. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2460. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2461. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2462. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2463. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2464. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2465. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2466. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2467. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2468. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2469. {
  2470. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2471. {
  2472. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2473. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2474. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2475. }
  2476. }
  2477. DEBUG_INFO("------------------------------------\n");*/
  2478. }
  2479. if(maxProfile.ChargingProfileId != -1)
  2480. {
  2481. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2482. {
  2483. if(maxProfile.ChargingSchedule.Duration != -1)
  2484. {
  2485. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2486. 0:
  2487. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2488. }
  2489. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2490. {
  2491. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2492. {
  2493. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2494. 0:
  2495. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2496. if(idxPeriod > 0)
  2497. {
  2498. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2499. {
  2500. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2501. }
  2502. }
  2503. }
  2504. }
  2505. }
  2506. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2507. {
  2508. if(maxProfile.ChargingSchedule.Duration != -1)
  2509. {
  2510. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2511. 0:
  2512. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2513. }
  2514. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2515. {
  2516. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2517. {
  2518. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2519. 0:
  2520. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2521. if(idxPeriod > 0)
  2522. {
  2523. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2524. {
  2525. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2526. }
  2527. }
  2528. }
  2529. }
  2530. }
  2531. else
  2532. {
  2533. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2534. {
  2535. if(maxProfile.ChargingSchedule.Duration != -1)
  2536. {
  2537. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2538. 0:
  2539. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2540. }
  2541. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2542. {
  2543. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2544. {
  2545. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2546. 0:
  2547. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2548. if(idxPeriod > 0)
  2549. {
  2550. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2551. {
  2552. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2553. }
  2554. }
  2555. }
  2556. }
  2557. }
  2558. else
  2559. {
  2560. if(maxProfile.ChargingSchedule.Duration != -1)
  2561. {
  2562. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2563. 0:
  2564. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2565. }
  2566. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2567. {
  2568. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2569. {
  2570. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2571. 0:
  2572. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2573. if(idxPeriod > 0)
  2574. {
  2575. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2576. {
  2577. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2578. }
  2579. }
  2580. }
  2581. }
  2582. }
  2583. }
  2584. /*
  2585. DEBUG_INFO("MaxProfile after align.\n");
  2586. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2587. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2588. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2589. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2590. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2591. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2592. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2593. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2594. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2595. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2596. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2597. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2598. {
  2599. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2600. {
  2601. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2602. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2603. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2604. }
  2605. }
  2606. DEBUG_INFO("------------------------------------\n");*/
  2607. }
  2608. /*
  2609. * Merge to conposite schedule
  2610. */
  2611. //DEBUG_INFO("====================================\n");
  2612. // Find each profile period quantity
  2613. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2614. {
  2615. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2616. limitMax = idx+1;
  2617. }
  2618. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2619. {
  2620. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2621. limitDef = idx+1;
  2622. }
  2623. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2624. {
  2625. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2626. limitTx = idx+1;
  2627. }
  2628. // TxProfile found, composite schedule based on it
  2629. if(txProfile.ChargingProfileId != -1)
  2630. {
  2631. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2632. {
  2633. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2634. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2635. (txProfile.ChargingSchedule.Duration > 0))
  2636. {
  2637. if(maxProfile.ChargingProfileId != -1)
  2638. {
  2639. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2640. {
  2641. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2642. {
  2643. if((maxProfile.ChargingSchedule.Duration > 0))
  2644. {
  2645. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2646. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2647. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2648. }
  2649. else
  2650. {
  2651. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2652. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2653. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2654. }
  2655. }
  2656. if(idxMaxPeriod == (limitMax-1))
  2657. {
  2658. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2659. {
  2660. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2661. {
  2662. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2663. compositePeriodIdx++;
  2664. }
  2665. else
  2666. {
  2667. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2668. }
  2669. }
  2670. }
  2671. }
  2672. }
  2673. else
  2674. {
  2675. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2676. {
  2677. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2678. compositePeriodIdx++;
  2679. }
  2680. else
  2681. {
  2682. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2683. }
  2684. }
  2685. }
  2686. if(idxTxPeriod == (limitTx-1))
  2687. {
  2688. if(defaultTxProfile.ChargingProfileId != -1)
  2689. {
  2690. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2691. {
  2692. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2693. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2694. (defaultTxProfile.ChargingSchedule.Duration>0))
  2695. {
  2696. if(maxProfile.ChargingProfileId != -1)
  2697. {
  2698. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2699. {
  2700. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2701. {
  2702. if((maxProfile.ChargingSchedule.Duration > 0))
  2703. {
  2704. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2705. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2706. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2707. }
  2708. else
  2709. {
  2710. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2711. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2712. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2713. }
  2714. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2715. {
  2716. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2717. {
  2718. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2719. compositePeriodIdx++;
  2720. }
  2721. else
  2722. {
  2723. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2724. }
  2725. }
  2726. // Delete duplicate period
  2727. if(compositePeriodIdx > 1)
  2728. {
  2729. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2730. {
  2731. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2732. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2733. compositePeriodIdx -= 1;
  2734. }
  2735. }
  2736. }
  2737. else
  2738. break;
  2739. }
  2740. }
  2741. else
  2742. {
  2743. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2744. {
  2745. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2746. compositePeriodIdx++;
  2747. }
  2748. else
  2749. {
  2750. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2751. }
  2752. }
  2753. }
  2754. }
  2755. }
  2756. }
  2757. }
  2758. }
  2759. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2760. else if(defaultTxProfile.ChargingProfileId != -1)
  2761. {
  2762. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2763. {
  2764. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2765. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2766. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2767. {
  2768. if(maxProfile.ChargingProfileId != -1)
  2769. {
  2770. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2771. {
  2772. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2773. {
  2774. if((maxProfile.ChargingSchedule.Duration > 0))
  2775. {
  2776. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2777. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2778. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2779. }
  2780. else
  2781. {
  2782. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2783. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2784. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2785. }
  2786. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2787. {
  2788. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2789. {
  2790. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2791. compositePeriodIdx++;
  2792. }
  2793. else
  2794. {
  2795. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2796. }
  2797. }
  2798. // Delete duplicate period
  2799. if(compositePeriodIdx > 1)
  2800. {
  2801. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2802. {
  2803. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2804. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2805. compositePeriodIdx -= 1;
  2806. }
  2807. }
  2808. }
  2809. else
  2810. break;
  2811. }
  2812. }
  2813. else
  2814. {
  2815. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2816. {
  2817. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2818. compositePeriodIdx++;
  2819. }
  2820. else
  2821. {
  2822. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2823. }
  2824. }
  2825. }
  2826. }
  2827. }
  2828. // Fill other period by MaxProfile
  2829. if(maxProfile.ChargingProfileId != -1)
  2830. {
  2831. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2832. {
  2833. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2834. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2835. (maxProfile.ChargingSchedule.Duration > 0))
  2836. {
  2837. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2838. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2839. {
  2840. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2841. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2842. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2843. }
  2844. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2845. {
  2846. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2847. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2848. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2849. }
  2850. if(tmpPeriod.Limit != -1)
  2851. {
  2852. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2853. {
  2854. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2855. {
  2856. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2857. compositePeriodIdx++;
  2858. }
  2859. else
  2860. {
  2861. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2862. }
  2863. }
  2864. // Delete duplicate period
  2865. if(compositePeriodIdx > 1)
  2866. {
  2867. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2868. {
  2869. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2870. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2871. compositePeriodIdx -= 1;
  2872. }
  2873. }
  2874. }
  2875. }
  2876. }
  2877. }
  2878. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2879. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2880. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2881. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2882. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2883. {
  2884. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2885. {
  2886. compositeProfile->ChargingProfileId = 1;
  2887. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2888. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2889. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2890. }
  2891. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2892. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2893. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2894. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2895. }
  2896. if(line)
  2897. free(line);
  2898. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  2899. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2900. }
  2901. //==========================================
  2902. // Init all share memory
  2903. //==========================================
  2904. int InitShareMemory()
  2905. {
  2906. int result = PASS;
  2907. int MeterSMId;
  2908. //creat ShmSysConfigAndInfo
  2909. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2910. {
  2911. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2912. result = FAIL;
  2913. }
  2914. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2915. {
  2916. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2917. result = FAIL;
  2918. }
  2919. else
  2920. {}
  2921. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2922. {
  2923. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2924. result = FAIL;
  2925. }
  2926. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2927. {
  2928. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2929. result = FAIL;
  2930. }
  2931. else
  2932. {}
  2933. //creat ShmPsuData
  2934. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2935. {
  2936. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2937. result = FAIL;
  2938. }
  2939. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2940. {
  2941. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2942. result = FAIL;
  2943. }
  2944. else
  2945. {}
  2946. //link ShmOCPP16Data
  2947. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2948. {
  2949. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2950. result = FAIL;
  2951. }
  2952. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2953. {
  2954. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2955. result = FAIL;
  2956. }
  2957. else
  2958. {}
  2959. //creat ShmOCPP16DataPH
  2960. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  2961. {
  2962. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  2963. result = FAIL;
  2964. }
  2965. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2966. {
  2967. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  2968. result = FAIL;
  2969. }
  2970. else
  2971. {}
  2972. /****************************** For Initial Settings************************************************/
  2973. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  2974. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  2975. // allocate Configuration memory address
  2976. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  2977. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2978. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2979. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2980. //offline MeterValue Interval
  2981. TempMeterValueInterval = 0;
  2982. return result;
  2983. }
  2984. int ProcessShareMemory()
  2985. {
  2986. if(InitShareMemory() == FAIL)
  2987. {
  2988. DEBUG_ERROR("InitShareMemory NG\n");
  2989. if(ShmStatusCodeData!=NULL)
  2990. {
  2991. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2992. }
  2993. sleep(5);
  2994. return FAIL;
  2995. }
  2996. return PASS;
  2997. }
  2998. void CheckSystemValue(void)
  2999. {
  3000. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3001. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3002. char filenmae[100]={0};
  3003. char str[100]={0};
  3004. int tempIndex = 0;
  3005. //===============================
  3006. // send Heartbeat
  3007. //===============================
  3008. //HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3009. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3010. {
  3011. clientTime.Heartbeat=time((time_t*)NULL);
  3012. if(server_sign == TRUE)
  3013. {
  3014. HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3015. }
  3016. else
  3017. {
  3018. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3019. }
  3020. }
  3021. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3022. {
  3023. //parameter for test
  3024. sendHeartbeatRequest(0);
  3025. //==============================================
  3026. // Reset Waiting Time
  3027. //==============================================
  3028. HeartBeatWithNOResponse += 2;
  3029. }
  3030. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3031. {
  3032. //==========================================
  3033. // csu trigger DataTransferReq
  3034. //==========================================
  3035. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3036. {
  3037. sendDataTransferRequest(gun_index);
  3038. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3039. }
  3040. //===============================
  3041. // CSU Trigger Authorize Request
  3042. //===============================
  3043. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3044. {
  3045. sendAuthorizeRequest(0);
  3046. authorizeRetryTimes = authorizeRetryTimes + 1;
  3047. if(authorizeRetryTimes < 3)
  3048. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3049. }
  3050. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3051. {
  3052. authorizeRetryTimes = 0;
  3053. SetOcppConnStatus(FALSE);
  3054. server_sign = FALSE;
  3055. }
  3056. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0)&& (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1))
  3057. {
  3058. sendAuthorizeRequest(0);
  3059. }
  3060. //==============================================
  3061. // Charger start transaction
  3062. //==============================================
  3063. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3064. {
  3065. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3066. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3067. sendStartTransactionRequest(gun_index);
  3068. clientTime.StartTransaction = time((time_t*)NULL);
  3069. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3070. storeTempStopTransaction(gun_index);
  3071. }
  3072. //==============================================
  3073. // Charger stop transaction
  3074. //==============================================
  3075. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3076. {
  3077. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3078. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3079. sendStopTransactionRequest(gun_index);
  3080. clientTime.StopTransaction = time((time_t*)NULL);
  3081. }
  3082. //==============================================
  3083. // Charger status report
  3084. //==============================================
  3085. //--- Check Mode Change ---//
  3086. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3087. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3088. {
  3089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3090. {
  3091. tempIndex = ((gun_index==2) ? 1: 0);
  3092. }
  3093. else
  3094. {
  3095. tempIndex = gun_index;
  3096. }
  3097. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3098. {
  3099. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3100. {
  3101. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3102. {
  3103. // Sent unplug message for California pricing logic
  3104. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3105. {
  3106. uint8_t ts[20];
  3107. getNowDatetime(ts);
  3108. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3109. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3110. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3111. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3112. }
  3113. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3114. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3115. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3116. }
  3117. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3118. {
  3119. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3120. if((access(filenmae,F_OK))!=-1)
  3121. {
  3122. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3123. sprintf(str,"rm -f %s",filenmae);
  3124. system(str);
  3125. }
  3126. }
  3127. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3128. #if 1 // for TempStopTransaction
  3129. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3130. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3131. {
  3132. checkTempStopTransaction(gun_index);
  3133. }
  3134. #endif
  3135. }
  3136. }
  3137. }
  3138. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3139. {
  3140. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3141. {
  3142. tempIndex = ((gun_index==2) ? 1: 0);
  3143. }
  3144. else
  3145. {
  3146. tempIndex = gun_index;
  3147. }
  3148. for (int index = 0; index < CCS_QUANTITY; index++)
  3149. {
  3150. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3151. {
  3152. 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]*/ )
  3153. {
  3154. // Sent unplug message for California pricing logic
  3155. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3156. {
  3157. uint8_t ts[20];
  3158. getNowDatetime(ts);
  3159. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3160. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3161. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3162. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3163. }
  3164. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3165. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3166. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3167. }
  3168. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3169. {
  3170. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3171. if((access(filenmae,F_OK))!=-1)
  3172. {
  3173. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3174. sprintf(str,"rm -f %s",filenmae);
  3175. system(str);
  3176. }
  3177. }
  3178. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3179. #if 1 // for TempStopTransaction
  3180. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3181. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3182. {
  3183. checkTempStopTransaction(gun_index);
  3184. }
  3185. #endif
  3186. }
  3187. }
  3188. }
  3189. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3190. {
  3191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3192. {
  3193. tempIndex = ((gun_index==2) ? 1: 0);
  3194. }
  3195. else
  3196. {
  3197. tempIndex = gun_index;
  3198. }
  3199. for (int index = 0; index < GB_QUANTITY; index++)
  3200. {
  3201. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3202. {
  3203. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3204. {
  3205. // Sent unplug message for California pricing logic
  3206. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3207. {
  3208. uint8_t ts[20];
  3209. getNowDatetime(ts);
  3210. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3211. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3212. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3213. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3214. }
  3215. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3216. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3217. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3218. }
  3219. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3220. {
  3221. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3222. if((access(filenmae,F_OK))!=-1)
  3223. {
  3224. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3225. sprintf(str,"rm -f %s",filenmae);
  3226. system(str);
  3227. }
  3228. }
  3229. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3230. #if 1 // for TempStopTransaction
  3231. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3232. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3233. {
  3234. checkTempStopTransaction(gun_index);
  3235. }
  3236. #endif
  3237. }
  3238. }
  3239. }
  3240. else if(gunType[gun_index] == GUN_TYPE_DO)
  3241. {
  3242. tempIndex = gun_index;
  3243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3244. {
  3245. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3246. {
  3247. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3248. {
  3249. // Sent unplug message for California pricing logic
  3250. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3251. {
  3252. uint8_t ts[20];
  3253. getNowDatetime(ts);
  3254. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3255. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3256. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3257. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3258. }
  3259. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3260. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3261. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3262. }
  3263. 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
  3264. {
  3265. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3266. if((access(filenmae,F_OK))!=-1)
  3267. {
  3268. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3269. sprintf(str,"rm -f %s",filenmae);
  3270. system(str);
  3271. }
  3272. }
  3273. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3274. #if 1 // for TempStopTransaction
  3275. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3276. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3277. {
  3278. checkTempStopTransaction(gun_index);
  3279. }
  3280. #endif
  3281. }
  3282. }
  3283. }
  3284. else
  3285. {
  3286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3287. {
  3288. tempIndex = 2;
  3289. }
  3290. else
  3291. {
  3292. tempIndex = gun_index;
  3293. }
  3294. for (int index = 0; index < AC_QUANTITY; index++)
  3295. {
  3296. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3297. {
  3298. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3299. {
  3300. // Sent unplug message for California pricing logic
  3301. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3302. {
  3303. uint8_t ts[20];
  3304. getNowDatetime(ts);
  3305. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3306. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3307. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3308. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3309. }
  3310. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3311. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3312. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3313. }
  3314. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3315. {
  3316. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3317. if((access(filenmae,F_OK))!=-1)
  3318. {
  3319. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3320. sprintf(str,"rm -f %s",filenmae);
  3321. system(str);
  3322. }
  3323. }
  3324. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3325. #if 1 // for TempStopTransaction
  3326. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3327. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3328. {
  3329. checkTempStopTransaction(gun_index);
  3330. }
  3331. #endif
  3332. }
  3333. }// END
  3334. }
  3335. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3336. (
  3337. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3338. )
  3339. )
  3340. {
  3341. if(SystemInitial > 0)
  3342. SystemInitial -= 1;
  3343. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3344. sendStatusNotificationRequest(gun_index);
  3345. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3346. }
  3347. //==============================================
  3348. // CSU Trigger Smart Charging Profilw
  3349. //==============================================
  3350. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3351. {
  3352. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3353. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3354. }
  3355. //==============================================
  3356. // Meter report
  3357. //==============================================
  3358. // Trigger MeterValue
  3359. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3360. {
  3361. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3362. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3363. }
  3364. // ClockAlign MeterValue
  3365. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3366. {
  3367. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3368. {
  3369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3370. {
  3371. tempIndex = ((gun_index==2) ? 1: 0);
  3372. }
  3373. else
  3374. {
  3375. tempIndex = gun_index;
  3376. }
  3377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3378. {
  3379. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3380. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3381. {
  3382. reqClockAlignMeter[gun_index] = 1;
  3383. }
  3384. }// End for CHAdeMO
  3385. }
  3386. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3387. {
  3388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3389. {
  3390. tempIndex = ((gun_index==2) ? 1: 0);
  3391. }
  3392. else
  3393. {
  3394. tempIndex = gun_index;
  3395. }
  3396. for (int index = 0; index < CCS_QUANTITY; index++)
  3397. {
  3398. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3399. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3400. {
  3401. reqClockAlignMeter[gun_index] = 1;
  3402. }
  3403. } // End for CCS
  3404. }
  3405. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3406. {
  3407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3408. {
  3409. tempIndex = ((gun_index==2) ? 1: 0);
  3410. }
  3411. else
  3412. {
  3413. tempIndex = gun_index;
  3414. }
  3415. for (int index = 0; index < GB_QUANTITY; index++)
  3416. {
  3417. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3418. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3419. {
  3420. reqClockAlignMeter[gun_index] = 1;
  3421. }
  3422. }// End for GB
  3423. }
  3424. else if(gunType[gun_index] == GUN_TYPE_DO)
  3425. {
  3426. tempIndex = gun_index;
  3427. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3428. {
  3429. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3430. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3431. {
  3432. reqClockAlignMeter[gun_index] = 1;
  3433. }
  3434. }
  3435. }
  3436. else
  3437. {
  3438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3439. {
  3440. tempIndex = 2;
  3441. }
  3442. else
  3443. {
  3444. tempIndex = gun_index;
  3445. }
  3446. for (int index = 0; index < AC_QUANTITY; index++)
  3447. {
  3448. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3449. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3450. {
  3451. reqClockAlignMeter[gun_index] = 1;
  3452. }
  3453. }//End for AC
  3454. }
  3455. if(reqClockAlignMeter[gun_index] == 1)
  3456. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3457. }
  3458. // Sample period MeterValue
  3459. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  3460. {
  3461. //check Transaction active
  3462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3463. {
  3464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3465. {
  3466. tempIndex = ((gun_index==2) ? 1: 0);
  3467. }
  3468. else
  3469. {
  3470. tempIndex = gun_index;
  3471. }
  3472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3473. {
  3474. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3475. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3476. {
  3477. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3478. {
  3479. reqSampleMeter[gun_index] = 1;
  3480. }
  3481. }
  3482. }// End for CHAdeMO
  3483. }
  3484. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3485. {
  3486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3487. {
  3488. tempIndex = ((gun_index==2) ? 1: 0);
  3489. }
  3490. else
  3491. {
  3492. tempIndex = gun_index;
  3493. }
  3494. for (int index = 0; index < CCS_QUANTITY; index++)
  3495. {
  3496. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3497. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3498. {
  3499. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3500. {
  3501. reqSampleMeter[gun_index] = 1;
  3502. }
  3503. }
  3504. } // End for CCS
  3505. }
  3506. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3507. {
  3508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3509. {
  3510. tempIndex = ((gun_index==2) ? 1: 0);
  3511. }
  3512. else
  3513. {
  3514. tempIndex = gun_index;
  3515. }
  3516. for (int index = 0; index < GB_QUANTITY; index++)
  3517. {
  3518. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3519. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3520. {
  3521. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3522. {
  3523. reqSampleMeter[gun_index] = 1;
  3524. }
  3525. }
  3526. }// End for GB
  3527. }
  3528. else if(gunType[gun_index] == GUN_TYPE_DO)
  3529. {
  3530. tempIndex = gun_index;
  3531. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3532. {
  3533. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3534. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3535. {
  3536. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3537. {
  3538. reqSampleMeter[gun_index] = 1;
  3539. }
  3540. }
  3541. }
  3542. }
  3543. else
  3544. {
  3545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3546. {
  3547. tempIndex = 2;
  3548. }
  3549. else
  3550. {
  3551. tempIndex = gun_index;
  3552. }
  3553. for (int index = 0; index < AC_QUANTITY; index++)
  3554. {
  3555. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3556. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3557. {
  3558. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3559. {
  3560. reqSampleMeter[gun_index] = 1;
  3561. }
  3562. }
  3563. }//End for AC
  3564. }
  3565. if(reqSampleMeter[gun_index] == 1)
  3566. {
  3567. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3568. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3569. storeTempStopTransaction(gun_index);
  3570. }
  3571. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3572. }
  3573. //==============================================
  3574. // Check Connector reserved
  3575. //==============================================
  3576. //===============================
  3577. // Check if Reserve is expired
  3578. //===============================
  3579. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3580. {
  3581. double diff_t;
  3582. struct tm tp;
  3583. // current time
  3584. time_t t = time(NULL);
  3585. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3586. tp.tm_isdst = -1;
  3587. time_t utc = mktime(&tp);
  3588. diff_t = difftime(utc, t);
  3589. if(diff_t <= 0)
  3590. {
  3591. DEBUG_INFO("reserve expired.\n");
  3592. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  3593. }
  3594. }//END OF Check if Reserve is expired
  3595. //==========================================
  3596. // csu trigger FirmwareStatusNotificationReq
  3597. //==========================================
  3598. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3599. {
  3600. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  3601. }
  3602. //==========================================
  3603. // csu trigger DiagnosticsStatusNotificationReq
  3604. //==========================================
  3605. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3606. {
  3607. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  3608. }
  3609. //==========================================
  3610. // csu trigger CancelReservationConf
  3611. //==========================================
  3612. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3613. {
  3614. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  3615. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3616. }
  3617. //==========================================
  3618. // csu trigger ChangeAvailabilityConf
  3619. //==========================================
  3620. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3621. {
  3622. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  3623. }
  3624. //==========================================
  3625. // csu trigger UnlockConnectorConf
  3626. //==========================================
  3627. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3628. {
  3629. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  3630. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3631. }
  3632. //==========================================
  3633. // csu trigger ReserveNowConf
  3634. //==========================================
  3635. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3636. {
  3637. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  3638. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3639. }
  3640. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  3641. {
  3642. sendSignCertificateRequest();
  3643. }
  3644. }
  3645. }
  3646. //==========================================
  3647. // send request routine
  3648. //==========================================
  3649. int sendAuthorizeRequest(int gun_index)
  3650. {
  3651. mtrace();
  3652. int result = FAIL;
  3653. char message[100]={0};
  3654. char guid[37];
  3655. char tempdata[65]={0};
  3656. DEBUG_INFO("sendAuthorizeRequest...\n");
  3657. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3658. //Local Authorize
  3659. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  3660. {
  3661. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3662. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3663. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3664. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3665. result = PASS;
  3666. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3667. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3668. authorizeRetryTimes = 0;
  3669. return result;
  3670. }
  3671. else if(((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0))||
  3672. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3673. {
  3674. // Query from cache
  3675. DEBUG_INFO("Authorize from cache.\n");
  3676. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3677. // Query from list
  3678. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3679. {
  3680. DEBUG_INFO("Authorize from list.\n");
  3681. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3682. }
  3683. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3684. {
  3685. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3686. {
  3687. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3688. }
  3689. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3690. {
  3691. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3692. }
  3693. if(!GetOcppConnStatus())
  3694. {
  3695. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3696. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3697. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3698. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3699. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3700. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3701. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3702. authorizeRetryTimes = 0;
  3703. return result;
  3704. }
  3705. }
  3706. else
  3707. {
  3708. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3709. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3710. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3711. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3712. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  3713. else
  3714. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3715. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3716. result = PASS;
  3717. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3718. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3719. authorizeRetryTimes = 0;
  3720. return result;
  3721. }
  3722. }
  3723. //initialize struct Authorize
  3724. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  3725. //get data from shared memory
  3726. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3727. random_uuid(guid);
  3728. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  3729. LWS_Send(message);
  3730. sprintf(tempdata, "Authorize,%d", gun_index);
  3731. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3732. {
  3733. result = PASS;
  3734. DEBUG_INFO("Authorize mapItem pass\n");
  3735. }
  3736. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3737. return result;
  3738. }
  3739. int sendBootNotificationRequest(void)
  3740. {
  3741. mtrace();
  3742. int result = FAIL;
  3743. char message[500]={0}, payload[700]={0};
  3744. char guid[37]={0};
  3745. char tempdata[65]={0};
  3746. // Fill BootNotification fields
  3747. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  3748. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3749. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3750. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3751. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3752. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3753. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3754. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3755. ShmOCPP16DataPH->ChargeBoxId
  3756. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3757. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3758. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3759. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  3760. ,ShmOCPP16DataPH->BootNotification.CpIccid
  3761. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  3762. random_uuid(guid);
  3763. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3764. LWS_Send(message);
  3765. sprintf(tempdata, "BootNotification,0");
  3766. 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*/)
  3767. {
  3768. result = PASS;
  3769. }
  3770. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3771. strcpy(queuedata,message);
  3772. return result;
  3773. }
  3774. int sendDataTransferRequest(int gun_index)
  3775. {
  3776. mtrace();
  3777. char message[1000]={0};
  3778. char guid[37]={0};
  3779. char tempdata[65]={0};
  3780. int result = FAIL;
  3781. random_uuid(guid);
  3782. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3783. MESSAGE_TYPE_CALL,
  3784. guid,
  3785. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  3786. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  3787. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  3788. LWS_Send(message);
  3789. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3790. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3791. {
  3792. result = PASS;
  3793. DEBUG_INFO("DataTransfer mapItem pass\n");
  3794. }
  3795. return result;
  3796. }
  3797. int sendDiagnosticsStatusNotificationRequest(char *status)
  3798. {
  3799. mtrace();
  3800. int result = FAIL;
  3801. char message[110]={0};
  3802. char guid[37]={0};
  3803. char tempdata[65]={0};
  3804. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3805. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3806. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3807. random_uuid(guid);
  3808. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3809. LWS_SendNow(message);
  3810. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3811. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3812. {
  3813. result = PASS;
  3814. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3815. }
  3816. //#ifdef SystemLogMessage
  3817. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3818. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3819. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3820. //#endif
  3821. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3822. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3823. //record status
  3824. if(strcmp(status,"Idle")==0)
  3825. {
  3826. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3827. }
  3828. else if(strcmp(status,"Uploaded")==0)
  3829. {
  3830. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3831. }
  3832. else if(strcmp(status,"UploadFailed")==0)
  3833. {
  3834. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3835. }
  3836. else if(strcmp(status,"Uploading")==0)
  3837. {
  3838. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3839. }
  3840. return result;
  3841. }
  3842. int sendFirmwareStatusNotificationRequest(char *status)
  3843. {
  3844. mtrace();
  3845. int result = FAIL;
  3846. char message[110]={0};
  3847. char guid[37]={0};
  3848. char tempdata[65]={0};
  3849. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3850. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3851. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3852. random_uuid(guid);
  3853. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3854. LWS_SendNow(message);
  3855. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3856. 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*/)
  3857. {
  3858. result = PASS;
  3859. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3860. }
  3861. //#ifdef SystemLogMessage
  3862. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3863. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3864. //#endif
  3865. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3866. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3867. //record status
  3868. if(strcmp(status,"Downloaded")==0)
  3869. {
  3870. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3871. }
  3872. else if(strcmp(status,"DownloadFailed")==0)
  3873. {
  3874. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3875. }
  3876. else if(strcmp(status,"Downloading")==0)
  3877. {
  3878. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3879. }
  3880. else if(strcmp(status,"Idle")==0)
  3881. {
  3882. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3883. }
  3884. else if(strcmp(status,"InstallationFailed")==0)
  3885. {
  3886. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3887. }
  3888. else if(strcmp(status,"Installing")==0)
  3889. {
  3890. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3891. }
  3892. else if(strcmp(status,"Installed")==0)
  3893. {
  3894. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3895. }
  3896. return result;
  3897. }
  3898. int sendHeartbeatRequest(int gun_index)
  3899. {
  3900. mtrace();
  3901. int result = FAIL;
  3902. char message[80]={0};
  3903. char guid[37]={0};
  3904. char tempdata[65]={0};
  3905. random_uuid(guid);
  3906. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3907. , MESSAGE_TYPE_CALL
  3908. , guid );
  3909. LWS_Send(message);
  3910. sprintf(tempdata, "Heartbeat,%d", 0);
  3911. 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*/)
  3912. {
  3913. result = PASS;
  3914. }
  3915. return result;
  3916. }
  3917. int sendStartTransactionRequest(int gun_index)
  3918. {
  3919. mtrace();
  3920. int result = FAIL;
  3921. char message[250]={0};
  3922. char guid[37]={0};
  3923. struct timeval tmnow;
  3924. struct tm *tm;
  3925. char buf[28];//, usec_buf[6];
  3926. char tempdata[65]={0};
  3927. int tempIndex = 0;
  3928. DEBUG_INFO("sendStartTransactionRequest...\n");
  3929. gettimeofday(&tmnow, NULL);
  3930. time_t t;
  3931. t = time(NULL);
  3932. /*UTC time and date*/
  3933. tm = gmtime(&t);
  3934. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3935. #if 0 // remove temporally
  3936. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3937. strcat(buf,".");
  3938. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3939. strcat(buf,usec_buf);
  3940. #endif
  3941. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3942. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  3943. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3944. // clear StartTransaction Response
  3945. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3946. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3947. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3948. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  3949. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3950. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3951. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3952. {
  3953. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3954. {
  3955. tempIndex = ((gun_index==2) ? 1: 0);
  3956. }
  3957. else
  3958. {
  3959. tempIndex = gun_index;
  3960. }
  3961. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3962. {
  3963. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3964. {
  3965. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3966. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3967. }
  3968. }
  3969. }
  3970. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3971. {
  3972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3973. {
  3974. tempIndex = ((gun_index==2) ? 1: 0);
  3975. }
  3976. else
  3977. {
  3978. tempIndex = gun_index;
  3979. }
  3980. for (int index = 0; index < CCS_QUANTITY; index++)
  3981. {
  3982. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3983. {
  3984. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3985. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3986. }
  3987. }
  3988. }
  3989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  4000. {
  4001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4002. {
  4003. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4004. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4005. }
  4006. }
  4007. }
  4008. else if(gunType[gun_index] == GUN_TYPE_DO)
  4009. {
  4010. tempIndex = gun_index;
  4011. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4012. {
  4013. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4014. {
  4015. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4016. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4017. }
  4018. }
  4019. }
  4020. else
  4021. {
  4022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4023. {
  4024. tempIndex = 2;
  4025. }
  4026. else
  4027. {
  4028. tempIndex = gun_index;
  4029. }
  4030. for (int index = 0; index < AC_QUANTITY; index++)
  4031. {
  4032. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4033. {
  4034. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4035. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4036. }
  4037. }
  4038. }
  4039. random_uuid(guid);
  4040. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4041. {
  4042. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4043. , gun_index +1
  4044. , MESSAGE_TYPE_CALL
  4045. , guid
  4046. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4047. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4048. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4049. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4050. }
  4051. else
  4052. {
  4053. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4054. , gun_index +1
  4055. , MESSAGE_TYPE_CALL
  4056. , guid
  4057. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4058. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4059. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4060. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4061. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4062. }
  4063. #if 1
  4064. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4065. 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*/)
  4066. {
  4067. result = PASS;
  4068. }
  4069. #endif
  4070. strcpy(queuedata, message);
  4071. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4072. OCPP_insert_transaction_msg(YES, queuedata);
  4073. return result;
  4074. }
  4075. int sendStatusNotificationRequest(int gun_index)
  4076. {
  4077. mtrace();
  4078. int result = FAIL;
  4079. char message[600]={0};
  4080. char guid[37];
  4081. int currentStatus = 0;
  4082. struct timeval tmnow;
  4083. struct tm *tm;
  4084. char buf[28];//, usec_buf[6];
  4085. char tempdata[65]={0};
  4086. int tempIndex = 0;
  4087. uint8_t isStateChanged = TRUE;
  4088. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4089. gettimeofday(&tmnow, NULL);
  4090. time_t t;
  4091. t = time(NULL);
  4092. /*UTC time and date*/
  4093. tm = gmtime(&t);
  4094. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4095. #if 0 // remove temporally
  4096. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4097. strcat(buf,".");
  4098. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4099. strcat(buf,usec_buf);
  4100. #endif
  4101. //printf("%s",buf);
  4102. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4103. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4104. // it's option
  4105. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4106. /*
  4107. enum _SYSTEM_STATUS
  4108. {
  4109. S_BOOTING = 0,
  4110. S_IDLE, = 1
  4111. S_AUTHORIZING, =2
  4112. S_REASSIGN_CHECK, =3
  4113. S_REASSIGN, =4
  4114. S_PRECHARGE, =5
  4115. S_PREPARING_FOR_EV, =6
  4116. S_PREPARING_FOR_EVSE, =7
  4117. S_CHARGING, =8
  4118. S_TERMINATING, =9
  4119. S_COMPLETE, =10
  4120. S_ALARM, =11
  4121. S_FAULT =12
  4122. }
  4123. */
  4124. //check Transaction active
  4125. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4126. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4127. {
  4128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4129. {
  4130. tempIndex = ((gun_index==2) ? 1: 0);
  4131. }
  4132. else
  4133. {
  4134. tempIndex = gun_index;
  4135. }
  4136. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4137. {
  4138. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4139. {
  4140. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4141. {
  4142. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4143. {
  4144. currentStatus = Preparing; //OCPP Status: Preparing
  4145. }
  4146. else
  4147. {
  4148. currentStatus = Available; //OCPP Status: Available
  4149. }
  4150. }
  4151. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4152. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4153. ) //S_PRECHARGE
  4154. {
  4155. currentStatus = Preparing; //OCPP Status: Preparing
  4156. }
  4157. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4158. {
  4159. currentStatus = Charging; //OCPP Status: Charging
  4160. }
  4161. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4162. {
  4163. currentStatus = Finishing; //OCPP Status: Finishing
  4164. }
  4165. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4166. {
  4167. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4168. }
  4169. 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
  4170. {
  4171. currentStatus = Unavailable; //OCPP Status: Unavailable
  4172. }
  4173. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4174. {
  4175. currentStatus = Faulted; //OCPP Status: Faulted
  4176. }
  4177. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4178. {
  4179. currentStatus = Reserved; //OCPP Status: Reserved
  4180. }
  4181. } //end of the same index
  4182. }//end of for CHAdeMO_QUANTITY
  4183. }
  4184. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4185. {
  4186. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4187. {
  4188. tempIndex = ((gun_index==2) ? 1: 0);
  4189. }
  4190. else
  4191. {
  4192. tempIndex = gun_index;
  4193. }
  4194. for (int index = 0; index < CCS_QUANTITY; index++)
  4195. {
  4196. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4197. {
  4198. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4199. {
  4200. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4201. {
  4202. currentStatus = Preparing; //OCPP Status: Preparing
  4203. }
  4204. else
  4205. {
  4206. currentStatus = Available; //OCPP Status: Available
  4207. }
  4208. }
  4209. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4210. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4211. ) //S_PRECHARGE
  4212. {
  4213. currentStatus = Preparing; //OCPP Status: Preparing
  4214. }
  4215. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4216. {
  4217. currentStatus = Charging; //OCPP Status: Charging
  4218. }
  4219. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4220. {
  4221. currentStatus = Finishing; //OCPP Status: Finishing
  4222. }
  4223. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4224. {
  4225. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4226. }
  4227. 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
  4228. {
  4229. currentStatus = Unavailable; //OCPP Status : Unavailable
  4230. }
  4231. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4232. {
  4233. currentStatus = Faulted; //OCPP Status: Faulted
  4234. }
  4235. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4236. {
  4237. currentStatus = Reserved; //OCPP Status: Reserved
  4238. }
  4239. } //end of the same index
  4240. } // end of for CCS_QUANTITY
  4241. }
  4242. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4243. {
  4244. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4245. {
  4246. tempIndex = ((gun_index==2) ? 1: 0);
  4247. }
  4248. else
  4249. {
  4250. tempIndex = gun_index;
  4251. }
  4252. for (int index = 0; index < GB_QUANTITY; index++)
  4253. {
  4254. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4255. {
  4256. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4257. {
  4258. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4259. {
  4260. currentStatus = Preparing; //OCPP Status: Preparing
  4261. }
  4262. else
  4263. {
  4264. currentStatus = Available; //OCPP Status: Available
  4265. }
  4266. }
  4267. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4268. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4269. ) //S_PRECHARGE
  4270. {
  4271. currentStatus = Preparing; //OCPP Status: Preparing
  4272. }
  4273. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4274. {
  4275. currentStatus = Charging; //OCPP Status: Charging
  4276. }
  4277. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4278. {
  4279. currentStatus = Finishing; //OCPP Status: Finishing
  4280. }
  4281. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4282. {
  4283. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4284. }
  4285. 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
  4286. {
  4287. currentStatus = Unavailable; //OCPP Status: Unavailable
  4288. }
  4289. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4290. {
  4291. currentStatus = Faulted; //OCPP Status: Faulted
  4292. }
  4293. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4294. {
  4295. currentStatus = Reserved; //OCPP Status: Reserved
  4296. }
  4297. } //end of the same index
  4298. } // end of for GB_QUANTITY
  4299. }
  4300. else if(gunType[gun_index] == GUN_TYPE_DO)
  4301. {
  4302. tempIndex = gun_index;
  4303. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4304. {
  4305. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4306. {
  4307. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4308. {
  4309. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4310. {
  4311. currentStatus = Preparing; //OCPP Status: Preparing
  4312. }
  4313. else
  4314. {
  4315. currentStatus = Available; //OCPP Status: Available
  4316. }
  4317. }
  4318. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4319. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4320. ) //S_PRECHARGE
  4321. {
  4322. currentStatus = Preparing; //OCPP Status: Preparing
  4323. }
  4324. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4325. {
  4326. currentStatus = Charging; //OCPP Status: Charging
  4327. }
  4328. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4329. {
  4330. currentStatus = Finishing; //OCPP Status: Finishing
  4331. }
  4332. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4333. {
  4334. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4335. }
  4336. 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
  4337. {
  4338. currentStatus = Unavailable; //OCPP Status: Unavailable
  4339. }
  4340. 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
  4341. {
  4342. currentStatus = Faulted; //OCPP Status: Faulted
  4343. }
  4344. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4345. {
  4346. currentStatus = Reserved; //OCPP Status: Reserved
  4347. }
  4348. } //end of the same index
  4349. }
  4350. }
  4351. else
  4352. {
  4353. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4354. {
  4355. tempIndex = 2;
  4356. }
  4357. else
  4358. {
  4359. tempIndex = gun_index;
  4360. }
  4361. for (int index = 0; index < AC_QUANTITY; index++)
  4362. {
  4363. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4364. {
  4365. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4366. {
  4367. 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))
  4368. {
  4369. currentStatus = Preparing; //OCPP Status: Preparing
  4370. }
  4371. else
  4372. {
  4373. currentStatus = Available; //OCPP Status: Available
  4374. }
  4375. }
  4376. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4377. {
  4378. currentStatus = Preparing; //OCPP Status: Preparing
  4379. }
  4380. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4381. {
  4382. currentStatus = Charging; //OCPP Status: Charging
  4383. }
  4384. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4385. {
  4386. currentStatus = Finishing; //OCPP Status: Finishing
  4387. }
  4388. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4389. {
  4390. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4391. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4392. else
  4393. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4394. }
  4395. 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
  4396. {
  4397. currentStatus = Unavailable; //OCPP Status: Unavailable
  4398. }
  4399. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4400. {
  4401. currentStatus = Faulted; //OCPP Status: Faulted
  4402. }
  4403. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4404. {
  4405. currentStatus = Reserved; //OCPP Status: Reserved
  4406. }
  4407. }//end of the same index
  4408. }//end of for AC_QUANTITY
  4409. }
  4410. //it's option
  4411. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4412. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4413. {
  4414. isStateChanged = FALSE;
  4415. }
  4416. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4417. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4418. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4419. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4420. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4421. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4422. random_uuid(guid);
  4423. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4424. , MESSAGE_TYPE_CALL
  4425. , guid
  4426. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4427. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4428. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4429. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4430. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4431. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4432. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4433. if((server_sign == TRUE) && isStateChanged)
  4434. {
  4435. LWS_Send(message);
  4436. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4437. 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*/)
  4438. {
  4439. //DEBUG_ERROR("statusNotification mapitem pass");
  4440. result = PASS;
  4441. }
  4442. }
  4443. else
  4444. {
  4445. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4446. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4447. result = PASS;
  4448. }
  4449. return result;
  4450. }
  4451. int sendStopTransactionRequest(int gun_index)
  4452. {
  4453. mtrace();
  4454. int result = FAIL;
  4455. //char message[1500]={0};
  4456. char guid[37]={0};
  4457. char tempdata[65]={0};
  4458. int tempIndex = 0;
  4459. char TempStopTransaction[256];
  4460. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4461. //int idx_sample=0;
  4462. DEBUG_INFO("sendStopTransactionRequest \n");
  4463. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4464. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4465. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4466. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4467. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4468. {
  4469. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4470. {
  4471. tempIndex = ((gun_index==2) ? 1: 0);
  4472. }
  4473. else
  4474. {
  4475. tempIndex = gun_index;
  4476. }
  4477. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4478. {
  4479. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4480. {
  4481. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4482. }
  4483. }// END OF CHAdeMO_QUANTITY
  4484. }
  4485. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4486. {
  4487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4488. {
  4489. tempIndex = ((gun_index==2) ? 1: 0);
  4490. }
  4491. else
  4492. {
  4493. tempIndex = gun_index;
  4494. }
  4495. for (int index = 0; index < CCS_QUANTITY; index++)
  4496. {
  4497. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4498. {
  4499. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4500. }
  4501. }// END OF CCS_QUANTITY
  4502. }
  4503. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4504. {
  4505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4506. {
  4507. tempIndex = ((gun_index==2) ? 1: 0);
  4508. }
  4509. else
  4510. {
  4511. tempIndex = gun_index;
  4512. }
  4513. for (int index = 0; index < GB_QUANTITY; index++)
  4514. {
  4515. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4516. {
  4517. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4518. }
  4519. }// END OF GB_QUANTITY
  4520. }
  4521. else if(gunType[gun_index] == GUN_TYPE_DO)
  4522. {
  4523. tempIndex = gun_index;
  4524. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4525. {
  4526. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4527. {
  4528. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4529. }
  4530. }// END OF GB_QUANTITY
  4531. }
  4532. else
  4533. {
  4534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4535. {
  4536. tempIndex = 2;
  4537. }
  4538. else
  4539. {
  4540. tempIndex = gun_index;
  4541. }
  4542. for (int index = 0; index < AC_QUANTITY; index++)
  4543. {
  4544. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4545. {
  4546. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4547. }
  4548. }// END OF AC_QUANTITY
  4549. }
  4550. //====================================== Stop Transaction Time =====================================================
  4551. struct timeval tmnow;
  4552. struct tm *tm;
  4553. char buf[28];//, usec_buf[6];
  4554. gettimeofday(&tmnow, NULL);
  4555. time_t t;
  4556. t = time(NULL);
  4557. /*UTC time and date*/
  4558. tm = gmtime(&t);
  4559. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4560. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  4561. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  4562. random_uuid(guid);
  4563. /***********************************transactionData******************************************************/
  4564. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4565. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4566. //=================================
  4567. // Transaction_Begin
  4568. //=================================
  4569. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4570. {
  4571. //============================================ Energy.Active.Import.Interval ================================
  4572. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4573. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4574. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4575. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  4576. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4577. 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))
  4578. {
  4579. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4580. }
  4581. else
  4582. {
  4583. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4584. }
  4585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4586. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4587. }
  4588. //=================================
  4589. // Transaction_End
  4590. //=================================
  4591. // ================================= Current.Import L1 ===============================================
  4592. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4593. {
  4594. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4595. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4596. {
  4597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4598. {
  4599. tempIndex = ((gun_index==2) ? 1: 0);
  4600. }
  4601. else
  4602. {
  4603. tempIndex = gun_index;
  4604. }
  4605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4606. {
  4607. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4608. {
  4609. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4610. }
  4611. }// End of for CHAdeMO_QUANTITY
  4612. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4613. }
  4614. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4615. {
  4616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4617. {
  4618. tempIndex = ((gun_index==2) ? 1: 0);
  4619. }
  4620. else
  4621. {
  4622. tempIndex = gun_index;
  4623. }
  4624. for (int index = 0; index < CCS_QUANTITY; index++)
  4625. {
  4626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4627. {
  4628. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4629. }
  4630. }// End of for CCS_QUANTITY
  4631. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4632. }
  4633. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4634. {
  4635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4636. {
  4637. tempIndex = ((gun_index==2) ? 1: 0);
  4638. }
  4639. else
  4640. {
  4641. tempIndex = gun_index;
  4642. }
  4643. for (int index = 0; index < GB_QUANTITY; index++)
  4644. {
  4645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4646. {
  4647. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4648. }
  4649. }// End of for GB_QUANTITY
  4650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4651. }
  4652. else if(gunType[gun_index] == GUN_TYPE_DO)
  4653. {
  4654. tempIndex = gun_index;
  4655. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4656. {
  4657. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4658. {
  4659. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4660. }
  4661. }
  4662. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4663. }
  4664. else
  4665. {
  4666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4667. {
  4668. tempIndex = 2;
  4669. }
  4670. else
  4671. {
  4672. tempIndex = gun_index;
  4673. }
  4674. for (int index = 0; index < AC_QUANTITY; index++)
  4675. {
  4676. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4677. {
  4678. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4679. }
  4680. }// End of for AC_QUANTITY
  4681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4682. }
  4683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4685. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4688. }
  4689. // ================================= Energy.Active.Import.Interval ==============================================
  4690. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4691. {
  4692. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4693. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4694. {
  4695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4696. {
  4697. tempIndex = ((gun_index==2) ? 1: 0);
  4698. }
  4699. else
  4700. {
  4701. tempIndex = gun_index;
  4702. }
  4703. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4704. {
  4705. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4706. {
  4707. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4708. }
  4709. }// END OF CHAdeMO_QUANTITY
  4710. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4711. }
  4712. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4713. {
  4714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4715. {
  4716. tempIndex = ((gun_index==2) ? 1: 0);
  4717. }
  4718. else
  4719. {
  4720. tempIndex = gun_index;
  4721. }
  4722. for (int index = 0; index < CCS_QUANTITY; index++)
  4723. {
  4724. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4725. {
  4726. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4727. }
  4728. }// END OF CCS_QUANTITY
  4729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4730. }
  4731. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4732. {
  4733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4734. {
  4735. tempIndex = ((gun_index==2) ? 1: 0);
  4736. }
  4737. else
  4738. {
  4739. tempIndex = gun_index;
  4740. }
  4741. for (int index = 0; index < GB_QUANTITY; index++)
  4742. {
  4743. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4744. {
  4745. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4746. }
  4747. }// END OF GB_QUANTITY
  4748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4749. }
  4750. else if(gunType[gun_index] == GUN_TYPE_DO)
  4751. {
  4752. tempIndex = gun_index;
  4753. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4754. {
  4755. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4756. {
  4757. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4758. }
  4759. }
  4760. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4761. }
  4762. else
  4763. {
  4764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4765. {
  4766. tempIndex = 2;
  4767. }
  4768. else
  4769. {
  4770. tempIndex = gun_index;
  4771. }
  4772. for (int index = 0; index < AC_QUANTITY; index++)
  4773. {
  4774. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4775. {
  4776. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4777. }
  4778. }// END OF AC_QUANTITY
  4779. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4780. }
  4781. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4784. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4786. }
  4787. //=================================== Power.Active.Import ==================================================
  4788. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4789. {
  4790. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4791. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4792. {
  4793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4794. {
  4795. tempIndex = ((gun_index==2) ? 1: 0);
  4796. }
  4797. else
  4798. {
  4799. tempIndex = gun_index;
  4800. }
  4801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4802. {
  4803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4804. {
  4805. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4806. }
  4807. } // End for CHAdeMO_QUANTITY
  4808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4809. }
  4810. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4811. {
  4812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4813. {
  4814. tempIndex = ((gun_index==2) ? 1: 0);
  4815. }
  4816. else
  4817. {
  4818. tempIndex = gun_index;
  4819. }
  4820. for (int index = 0; index < CCS_QUANTITY; index++)
  4821. {
  4822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4823. {
  4824. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4825. }
  4826. } // END for CCS_QUANTITY
  4827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4828. }
  4829. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4830. {
  4831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4832. {
  4833. tempIndex = ((gun_index==2) ? 1: 0);
  4834. }
  4835. else
  4836. {
  4837. tempIndex = gun_index;
  4838. }
  4839. for (int index = 0; index < GB_QUANTITY; index++)
  4840. {
  4841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4842. {
  4843. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4844. }
  4845. }// END for GB_QUANTITY
  4846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4847. }
  4848. else if(gunType[gun_index] == GUN_TYPE_DO)
  4849. {
  4850. tempIndex = gun_index;
  4851. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4852. {
  4853. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4854. {
  4855. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4856. }
  4857. }
  4858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4859. }
  4860. else
  4861. {
  4862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4863. {
  4864. tempIndex = 2;
  4865. }
  4866. else
  4867. {
  4868. tempIndex = gun_index;
  4869. }
  4870. for (int index = 0; index < AC_QUANTITY; index++)
  4871. {
  4872. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4873. {
  4874. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4875. }
  4876. } // END for AC_QUANTITY
  4877. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4878. }
  4879. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4880. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4881. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4882. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4883. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4884. }
  4885. //============================ Voltage L1 ====================================
  4886. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4887. {
  4888. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4889. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4890. {
  4891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4892. {
  4893. tempIndex = ((gun_index==2) ? 1: 0);
  4894. }
  4895. else
  4896. {
  4897. tempIndex = gun_index;
  4898. }
  4899. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4900. {
  4901. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4902. {
  4903. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4904. }
  4905. } // END OF FOR CHAdeMO_QUANTITY
  4906. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4907. }
  4908. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4909. {
  4910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4911. {
  4912. tempIndex = ((gun_index==2) ? 1: 0);
  4913. }
  4914. else
  4915. {
  4916. tempIndex = gun_index;
  4917. }
  4918. for (int index = 0; index < CCS_QUANTITY; index++)
  4919. {
  4920. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4921. {
  4922. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4923. }
  4924. } // END OF FOR CCS_QUANTITY
  4925. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4926. }
  4927. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4928. {
  4929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4930. {
  4931. tempIndex = ((gun_index==2) ? 1: 0);
  4932. }
  4933. else
  4934. {
  4935. tempIndex = gun_index;
  4936. }
  4937. for (int index = 0; index < GB_QUANTITY; index++)
  4938. {
  4939. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4940. {
  4941. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4942. }
  4943. } // END OF FOR GB_QUANTITY
  4944. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4945. }
  4946. else if(gunType[gun_index] == GUN_TYPE_DO)
  4947. {
  4948. tempIndex = gun_index;
  4949. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4950. {
  4951. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4952. {
  4953. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4954. }
  4955. }
  4956. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4957. }
  4958. else
  4959. {
  4960. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4961. {
  4962. tempIndex = 2;
  4963. }
  4964. else
  4965. {
  4966. tempIndex = gun_index;
  4967. }
  4968. for (int index = 0; index < AC_QUANTITY; index++)
  4969. {
  4970. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4971. {
  4972. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4973. }
  4974. } // END OF FOR AC_QUANTITY
  4975. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4976. }
  4977. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4978. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4979. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4980. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4981. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4982. }
  4983. //====================== End SoC ================================
  4984. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4985. {
  4986. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4987. 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))
  4988. {
  4989. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4990. {
  4991. tempIndex = ((gun_index==2) ? 1: 0);
  4992. }
  4993. else
  4994. {
  4995. tempIndex = gun_index;
  4996. }
  4997. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4998. {
  4999. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5000. {
  5001. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5002. {
  5003. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5004. }
  5005. }
  5006. }
  5007. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5008. {
  5009. for (int index = 0; index < CCS_QUANTITY; index++)
  5010. {
  5011. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5012. {
  5013. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5014. }
  5015. }
  5016. }
  5017. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5018. {
  5019. for (int index = 0; index < GB_QUANTITY; index++)
  5020. {
  5021. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5022. {
  5023. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5024. }
  5025. }
  5026. }
  5027. else if(gunType[gun_index] == GUN_TYPE_DO)
  5028. {
  5029. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5030. {
  5031. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5032. {
  5033. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5034. }
  5035. }
  5036. }
  5037. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5038. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5039. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5040. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5041. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5042. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5043. } // END FOR DC CASE
  5044. }
  5045. // ================================= Current.Import L2 ===============================================
  5046. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5047. {
  5048. // AC 3 phse L2 current
  5049. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5050. {
  5051. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5052. {
  5053. tempIndex = 2;
  5054. }
  5055. else
  5056. {
  5057. tempIndex = gun_index;
  5058. }
  5059. for (int index = 0; index < AC_QUANTITY; index++)
  5060. {
  5061. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5062. {
  5063. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5064. }
  5065. }// End of for AC_QUANTITY
  5066. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5067. }
  5068. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5069. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5070. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5071. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5072. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5073. }
  5074. // ================================= Current.Import L3 ===============================================
  5075. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5076. {
  5077. // AC 3 phse L3 current
  5078. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5079. {
  5080. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5081. {
  5082. tempIndex = 2;
  5083. }
  5084. else
  5085. {
  5086. tempIndex = gun_index;
  5087. }
  5088. for (int index = 0; index < AC_QUANTITY; index++)
  5089. {
  5090. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5091. {
  5092. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5093. }
  5094. }// End of for AC_QUANTITY
  5095. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5096. }
  5097. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5098. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5099. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5100. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5101. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5102. }
  5103. //============================ Voltage L2 ====================================
  5104. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5105. {
  5106. // AC 3 phse L2 voltage
  5107. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5108. {
  5109. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5110. {
  5111. tempIndex = 2;
  5112. }
  5113. else
  5114. {
  5115. tempIndex = gun_index;
  5116. }
  5117. for (int index = 0; index < AC_QUANTITY; index++)
  5118. {
  5119. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5120. {
  5121. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5122. }
  5123. } // END OF FOR AC_QUANTITY
  5124. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5125. }
  5126. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5127. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5128. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5129. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5130. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5131. }
  5132. //============================ Voltage L3 ====================================
  5133. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5134. {
  5135. // AC 3 phse L3 voltage
  5136. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5137. {
  5138. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5139. {
  5140. tempIndex = 2;
  5141. }
  5142. else
  5143. {
  5144. tempIndex = gun_index;
  5145. }
  5146. for (int index = 0; index < AC_QUANTITY; index++)
  5147. {
  5148. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5149. {
  5150. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5151. }
  5152. } // END OF FOR AC_QUANTITY
  5153. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5154. }
  5155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5156. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5158. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5160. }
  5161. //====================== Start SoC ================================
  5162. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5163. {
  5164. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5165. 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))
  5166. {
  5167. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5168. {
  5169. tempIndex = ((gun_index==2) ? 1: 0);
  5170. }
  5171. else
  5172. {
  5173. tempIndex = gun_index;
  5174. }
  5175. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5176. {
  5177. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5178. {
  5179. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5180. {
  5181. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5182. }
  5183. }
  5184. }
  5185. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5186. {
  5187. for (int index = 0; index < CCS_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5190. {
  5191. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5192. }
  5193. }
  5194. }
  5195. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5196. {
  5197. for (int index = 0; index < GB_QUANTITY; index++)
  5198. {
  5199. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5200. {
  5201. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5202. }
  5203. }
  5204. }
  5205. else if(gunType[gun_index] == GUN_TYPE_DO)
  5206. {
  5207. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5208. {
  5209. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5210. {
  5211. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5212. }
  5213. }
  5214. }
  5215. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5216. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5217. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5220. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5221. } // END FOR DC CASE
  5222. }
  5223. //================================================ Message create ====================================================
  5224. json_object *StopTransaction = json_object_new_object();
  5225. json_object *transactionDatas = json_object_new_array();
  5226. json_object *sampledValues = json_object_new_array();
  5227. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5228. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5229. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5230. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5231. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5232. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5233. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5234. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5235. {
  5236. json_object *transactionData = json_object_new_object();
  5237. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5238. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5239. {
  5240. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5241. {
  5242. json_object *sampledValue = json_object_new_object();
  5243. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5244. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5245. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5246. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5247. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5248. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5249. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5250. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5251. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5252. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5253. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5254. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5255. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5256. json_object_array_add(sampledValues, sampledValue);
  5257. }
  5258. }
  5259. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5260. json_object_array_add(transactionDatas, transactionData);
  5261. }
  5262. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5263. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5264. ,MESSAGE_TYPE_CALL
  5265. ,guid
  5266. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5267. json_object_put(StopTransaction);
  5268. #if 1 // for TempStopTransaction
  5269. //Delete TempStopTransaction
  5270. if((access(TempStopTransaction,F_OK))!=-1)
  5271. {
  5272. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5273. }
  5274. #endif
  5275. #if 1
  5276. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5277. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5278. {
  5279. result = PASS;
  5280. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5281. }
  5282. #endif
  5283. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5284. OCPP_insert_transaction_msg(NO, queuedata);
  5285. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5286. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5287. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5288. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5289. {
  5290. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5291. }
  5292. //for test
  5293. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5294. return result;
  5295. }
  5296. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5297. {
  5298. mtrace();
  5299. int result = FAIL;
  5300. char guid[37]={0};
  5301. char tempdata[65]={0};
  5302. int tempIndex = 0;
  5303. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5304. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5305. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5306. //set value
  5307. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5308. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  5309. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5310. -1);
  5311. random_uuid(guid);
  5312. //UTC Date time
  5313. struct timeval tmnow;
  5314. struct tm *tm;
  5315. char buf[28];//, usec_buf[6];
  5316. gettimeofday(&tmnow, NULL);
  5317. time_t t;
  5318. t = time(NULL);
  5319. /*UTC time and date*/
  5320. tm = gmtime(&t);
  5321. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5322. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5323. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5324. //********************************(1)Current.Import L1************************************************/
  5325. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5326. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5327. (dataType == ReadingContext_Trigger))
  5328. {
  5329. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5330. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5331. {
  5332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5333. {
  5334. tempIndex = ((gun_index==2) ? 1: 0);
  5335. }
  5336. else
  5337. {
  5338. tempIndex = gun_index;
  5339. }
  5340. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5341. {
  5342. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5343. {
  5344. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5345. }
  5346. }
  5347. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5348. }
  5349. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5350. {
  5351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5352. {
  5353. tempIndex = ((gun_index==2) ? 1: 0);
  5354. }
  5355. else
  5356. {
  5357. tempIndex = gun_index;
  5358. }
  5359. for (int index = 0; index < CCS_QUANTITY; index++)
  5360. {
  5361. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5362. {
  5363. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5364. }
  5365. }
  5366. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5367. }
  5368. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5369. {
  5370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5371. {
  5372. tempIndex = ((gun_index==2) ? 1: 0);
  5373. }
  5374. else
  5375. {
  5376. tempIndex = gun_index;
  5377. }
  5378. for (int index = 0; index < GB_QUANTITY; index++)
  5379. {
  5380. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5381. {
  5382. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5383. }
  5384. }
  5385. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5386. }
  5387. else if(gunType[gun_index] == GUN_TYPE_DO)
  5388. {
  5389. tempIndex = gun_index;
  5390. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5391. {
  5392. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5393. {
  5394. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5395. }
  5396. }
  5397. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5398. }
  5399. else
  5400. {
  5401. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5402. {
  5403. tempIndex = 2;
  5404. }
  5405. else
  5406. {
  5407. tempIndex = gun_index;
  5408. }
  5409. for (int index = 0; index < AC_QUANTITY; index++)
  5410. {
  5411. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5412. {
  5413. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5414. }
  5415. }
  5416. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5417. }
  5418. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5419. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5420. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5421. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5422. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5423. }
  5424. //********************************(2)Energy.Active.Import.Register ************************************************/
  5425. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5426. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5427. (dataType == ReadingContext_Trigger))
  5428. {
  5429. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5430. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5431. {
  5432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5433. {
  5434. tempIndex = ((gun_index==2) ? 1: 0);
  5435. }
  5436. else
  5437. {
  5438. tempIndex = gun_index;
  5439. }
  5440. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5441. {
  5442. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5443. {
  5444. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5445. }
  5446. }
  5447. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5448. }
  5449. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5450. {
  5451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5452. {
  5453. tempIndex = ((gun_index==2) ? 1: 0);
  5454. }
  5455. else
  5456. {
  5457. tempIndex = gun_index;
  5458. }
  5459. for (int index = 0; index < CCS_QUANTITY; index++)
  5460. {
  5461. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5462. {
  5463. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5464. }
  5465. }
  5466. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5467. }
  5468. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5469. {
  5470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5471. {
  5472. tempIndex = ((gun_index==2) ? 1: 0);
  5473. }
  5474. else
  5475. {
  5476. tempIndex = gun_index;
  5477. }
  5478. for (int index = 0; index < GB_QUANTITY; index++)
  5479. {
  5480. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5481. {
  5482. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5483. }
  5484. }
  5485. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5486. }
  5487. else if(gunType[gun_index] == GUN_TYPE_DO)
  5488. {
  5489. tempIndex = gun_index;
  5490. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5491. {
  5492. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5493. {
  5494. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5495. }
  5496. }
  5497. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5498. }
  5499. else
  5500. {
  5501. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5502. {
  5503. tempIndex = 2;
  5504. }
  5505. else
  5506. {
  5507. tempIndex = gun_index;
  5508. }
  5509. for (int index = 0; index < AC_QUANTITY; index++)
  5510. {
  5511. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5512. {
  5513. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5514. }
  5515. }
  5516. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5517. }
  5518. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5519. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5520. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5521. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5522. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5523. }
  5524. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5525. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5526. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5527. (dataType == ReadingContext_Trigger))
  5528. {
  5529. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5530. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5531. {
  5532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5533. {
  5534. tempIndex = ((gun_index==2) ? 1: 0);
  5535. }
  5536. else
  5537. {
  5538. tempIndex = gun_index;
  5539. }
  5540. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5541. {
  5542. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5543. {
  5544. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5545. }
  5546. } // END OF FOR CHAdeMO_QUANTITY
  5547. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5548. }
  5549. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5550. {
  5551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5552. {
  5553. tempIndex = ((gun_index==2) ? 1: 0);
  5554. }
  5555. else
  5556. {
  5557. tempIndex = gun_index;
  5558. }
  5559. for (int index = 0; index < CCS_QUANTITY; index++)
  5560. {
  5561. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5562. {
  5563. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5564. }
  5565. } // END OF CCS_QUANTITY
  5566. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5567. }
  5568. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5569. {
  5570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5571. {
  5572. tempIndex = ((gun_index==2) ? 1: 0);
  5573. }
  5574. else
  5575. {
  5576. tempIndex = gun_index;
  5577. }
  5578. for (int index = 0; index < GB_QUANTITY; index++)
  5579. {
  5580. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5581. {
  5582. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5583. }
  5584. } // END OF GB_QUANTITY
  5585. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5586. }
  5587. else if(gunType[gun_index] == GUN_TYPE_DO)
  5588. {
  5589. tempIndex = gun_index;
  5590. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5591. {
  5592. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5593. {
  5594. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5595. }
  5596. }
  5597. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5598. }
  5599. else
  5600. {
  5601. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5602. {
  5603. tempIndex = 2;
  5604. }
  5605. else
  5606. {
  5607. tempIndex = gun_index;
  5608. }
  5609. for (int index = 0; index < AC_QUANTITY; index++)
  5610. {
  5611. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5612. {
  5613. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5614. }
  5615. }
  5616. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5617. }
  5618. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5619. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5620. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5621. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5622. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5623. }
  5624. //********************************(4)Power.Active.Import************************************************/
  5625. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5626. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5627. (dataType == ReadingContext_Trigger))
  5628. {
  5629. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5630. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5631. {
  5632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5633. {
  5634. tempIndex = ((gun_index==2) ? 1: 0);
  5635. }
  5636. else
  5637. {
  5638. tempIndex = gun_index;
  5639. }
  5640. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5641. {
  5642. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5643. {
  5644. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5645. }
  5646. } // END OF FOR
  5647. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5648. }
  5649. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5650. {
  5651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5652. {
  5653. tempIndex = ((gun_index==2) ? 1: 0);
  5654. }
  5655. else
  5656. {
  5657. tempIndex = gun_index;
  5658. }
  5659. for (int index = 0; index < CCS_QUANTITY; index++)
  5660. {
  5661. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5662. {
  5663. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5664. }
  5665. }
  5666. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5667. }
  5668. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5669. {
  5670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5671. {
  5672. tempIndex = ((gun_index==2) ? 1: 0);
  5673. }
  5674. else
  5675. {
  5676. tempIndex = gun_index;
  5677. }
  5678. for (int index = 0; index < GB_QUANTITY; index++)
  5679. {
  5680. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5681. {
  5682. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5683. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5684. }
  5685. }
  5686. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5687. }
  5688. else if(gunType[gun_index] == GUN_TYPE_DO)
  5689. {
  5690. tempIndex = gun_index;
  5691. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5692. {
  5693. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5694. {
  5695. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5696. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5697. }
  5698. }
  5699. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5700. }
  5701. else
  5702. {
  5703. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5704. {
  5705. tempIndex = 2;
  5706. }
  5707. else
  5708. {
  5709. tempIndex = gun_index;
  5710. }
  5711. for (int index = 0; index < AC_QUANTITY; index++)
  5712. {
  5713. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5714. {
  5715. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5716. }
  5717. }
  5718. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5719. }
  5720. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5721. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5722. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5723. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5724. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5725. }
  5726. //***********************************************(5)VOLTAGE L1******************************************************/
  5727. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5728. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5729. (dataType == ReadingContext_Trigger))
  5730. {
  5731. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5732. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5733. {
  5734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5735. {
  5736. tempIndex = ((gun_index==2) ? 1: 0);
  5737. }
  5738. else
  5739. {
  5740. tempIndex = gun_index;
  5741. }
  5742. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5743. {
  5744. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5745. {
  5746. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5747. }
  5748. }
  5749. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5750. }
  5751. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5752. {
  5753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5754. {
  5755. tempIndex = ((gun_index==2) ? 1: 0);
  5756. }
  5757. else
  5758. {
  5759. tempIndex = gun_index;
  5760. }
  5761. for (int index = 0; index < CCS_QUANTITY; index++)
  5762. {
  5763. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5764. {
  5765. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5766. }
  5767. }
  5768. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5769. }
  5770. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5771. {
  5772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5773. {
  5774. tempIndex = ((gun_index==2) ? 1: 0);
  5775. }
  5776. else
  5777. {
  5778. tempIndex = gun_index;
  5779. }
  5780. for (int index = 0; index < GB_QUANTITY; index++)
  5781. {
  5782. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5783. {
  5784. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5785. }
  5786. }
  5787. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5788. }
  5789. else if(gunType[gun_index] == GUN_TYPE_DO)
  5790. {
  5791. tempIndex = gun_index;
  5792. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5793. {
  5794. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5795. {
  5796. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5797. }
  5798. }
  5799. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5800. }
  5801. else
  5802. {
  5803. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5804. {
  5805. tempIndex = 2;
  5806. }
  5807. else
  5808. {
  5809. tempIndex = gun_index;
  5810. }
  5811. for (int index = 0; index < AC_QUANTITY; index++)
  5812. {
  5813. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5814. {
  5815. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5816. }
  5817. }
  5818. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5819. }
  5820. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5821. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5822. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5823. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5824. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5825. }
  5826. //***********************************************(6)SOC******************************************************/
  5827. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5828. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5829. (dataType == ReadingContext_Trigger))
  5830. {
  5831. 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))
  5832. {
  5833. //idx_sample=5;
  5834. //sampledValue = NULL;
  5835. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5836. {
  5837. tempIndex = ((gun_index==2) ? 1: 0);
  5838. }
  5839. else
  5840. {
  5841. tempIndex = gun_index;
  5842. }
  5843. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5844. {
  5845. //tempIndex = ((gun_index==2) ? 1: 0);
  5846. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5847. {
  5848. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5849. {
  5850. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5851. }
  5852. }
  5853. }
  5854. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5855. {
  5856. //tempIndex = ((gun_index==2) ? 1: 0);
  5857. for (int index = 0; index < CCS_QUANTITY; index++)
  5858. {
  5859. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5860. {
  5861. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5862. }
  5863. }
  5864. }
  5865. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5866. {
  5867. //tempIndex = ((gun_index==2) ? 1: 0);
  5868. for (int index = 0; index < GB_QUANTITY; index++)
  5869. {
  5870. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5871. {
  5872. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5873. }
  5874. }
  5875. }
  5876. else if(gunType[gun_index] == GUN_TYPE_DO)
  5877. {
  5878. //tempIndex = ((gun_index==2) ? 1: 0);
  5879. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5880. {
  5881. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5882. {
  5883. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5884. }
  5885. }
  5886. }
  5887. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5888. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5889. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5890. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5891. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5892. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5893. }
  5894. }
  5895. //********************************(7)Current.Import L2************************************************/
  5896. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5897. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5898. (dataType == ReadingContext_Trigger))
  5899. {
  5900. // Only for AC 3 phase
  5901. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5902. {
  5903. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5904. {
  5905. tempIndex = 2;
  5906. }
  5907. else
  5908. {
  5909. tempIndex = gun_index;
  5910. }
  5911. for (int index = 0; index < AC_QUANTITY; index++)
  5912. {
  5913. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5914. {
  5915. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5916. }
  5917. }
  5918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5919. }
  5920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5921. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5922. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5923. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5924. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5925. }
  5926. //********************************(8)Current.Import L3************************************************/
  5927. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5928. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5929. (dataType == ReadingContext_Trigger))
  5930. {
  5931. // Only for AC 3 phase
  5932. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5933. {
  5934. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5935. {
  5936. tempIndex = 2;
  5937. }
  5938. else
  5939. {
  5940. tempIndex = gun_index;
  5941. }
  5942. for (int index = 0; index < AC_QUANTITY; index++)
  5943. {
  5944. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5945. {
  5946. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5947. }
  5948. }
  5949. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5950. }
  5951. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5952. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5953. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5954. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5955. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5956. }
  5957. //***********************************************(9)VOLTAGE L2******************************************************/
  5958. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5959. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5960. (dataType == ReadingContext_Trigger))
  5961. {
  5962. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5963. {
  5964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5965. {
  5966. tempIndex = 2;
  5967. }
  5968. else
  5969. {
  5970. tempIndex = gun_index;
  5971. }
  5972. for (int index = 0; index < AC_QUANTITY; index++)
  5973. {
  5974. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5975. {
  5976. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5977. }
  5978. }
  5979. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5980. }
  5981. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5982. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5983. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5984. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5985. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5986. }
  5987. //***********************************************(10)VOLTAGE L3******************************************************/
  5988. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5989. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5990. (dataType == ReadingContext_Trigger))
  5991. {
  5992. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5993. {
  5994. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5995. {
  5996. tempIndex = 2;
  5997. }
  5998. else
  5999. {
  6000. tempIndex = gun_index;
  6001. }
  6002. for (int index = 0; index < AC_QUANTITY; index++)
  6003. {
  6004. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6005. {
  6006. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6007. }
  6008. }
  6009. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6010. }
  6011. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6012. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6013. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6014. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6015. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6016. }
  6017. // Message create ====================================================================================================
  6018. if(TRUE)
  6019. {
  6020. json_object *MeterValueReq = json_object_new_object();
  6021. json_object *MeterValues = json_object_new_array();
  6022. json_object *sampledValues = json_object_new_array();
  6023. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6024. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6025. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6026. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6027. {
  6028. json_object *MeterValue = json_object_new_object();
  6029. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6030. {
  6031. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6032. {
  6033. json_object *sampledValue = json_object_new_object();
  6034. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6035. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6036. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6037. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6038. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6039. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6040. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6041. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6042. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6043. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6044. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6045. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6046. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6047. json_object_array_add(sampledValues, sampledValue);
  6048. }
  6049. }
  6050. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6051. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6052. json_object_array_add(MeterValues, MeterValue);
  6053. }
  6054. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6055. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6056. ,gun_index + 1
  6057. ,MESSAGE_TYPE_CALL
  6058. ,guid
  6059. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6060. json_object_put(MeterValueReq);
  6061. }
  6062. // Put request guid to hash map
  6063. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6064. 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*/)
  6065. {
  6066. result = PASS;
  6067. //DEBUG_INFO("MeterValues mapitem pass\n");
  6068. }
  6069. if((dataType != ReadingContext_Trigger) &&
  6070. (dataType != ReadingContext_Sample_Clock) &&
  6071. (ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1))
  6072. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6073. else
  6074. {
  6075. if(FirstHeartBeat)
  6076. LWS_Send(queuedata +2);
  6077. }
  6078. return result;
  6079. }
  6080. int sendLogStatusNotificationRequest(char *status)
  6081. {
  6082. mtrace();
  6083. int result = PASS;
  6084. char message[4096]={0};
  6085. char guid[37]={0};
  6086. char tempdata[128]={0};
  6087. json_object *LogStatusNotification = json_object_new_object();
  6088. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6089. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6090. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6091. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6092. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6093. random_uuid(guid);
  6094. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6095. json_object_put(LogStatusNotification);
  6096. LWS_Send(message);
  6097. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6098. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6099. {
  6100. result = PASS;
  6101. }
  6102. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6103. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6104. return result;
  6105. }
  6106. int sendSecurityEventNotificationRequest()
  6107. {
  6108. mtrace();
  6109. int result = PASS;
  6110. char message[4096]={0};
  6111. char guid[37]={0};
  6112. char tempdata[128]={0};
  6113. json_object *SecurityEventNotification = json_object_new_object();
  6114. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6115. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6116. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6117. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6118. random_uuid(guid);
  6119. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6120. json_object_put(SecurityEventNotification);
  6121. LWS_Send(message);
  6122. sprintf(tempdata, "SecurityEventNotification,0");
  6123. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6124. {
  6125. result = PASS;
  6126. }
  6127. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6128. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6129. return result;
  6130. }
  6131. int sendSignCertificateRequest()
  6132. {
  6133. mtrace();
  6134. int result = PASS;
  6135. char message[4096]={0};
  6136. char guid[37]={0};
  6137. char tempdata[128]={0};
  6138. json_object *SignCertificate = json_object_new_object();
  6139. DEBUG_INFO("sendSignCertificateRequest...\n");
  6140. // Read csr file content
  6141. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6142. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6143. char *line = NULL;
  6144. size_t len = 0;
  6145. while(getline(&line, &len, fp) != -1)
  6146. {
  6147. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6148. {
  6149. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6150. }
  6151. }
  6152. fclose(fp);
  6153. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6154. random_uuid(guid);
  6155. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6156. json_object_put(SignCertificate);
  6157. LWS_Send(message);
  6158. sprintf(tempdata, "SignCertificate,0");
  6159. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6160. {
  6161. result = PASS;
  6162. }
  6163. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6164. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6165. return result;
  6166. }
  6167. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6168. {
  6169. mtrace();
  6170. int result = PASS;
  6171. char message[110]={0};
  6172. char guid[37]={0};
  6173. char tempdata[65]={0};
  6174. json_object *FirmwareStatusNotification = json_object_new_object();
  6175. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6176. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6177. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6178. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6179. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6180. random_uuid(guid);
  6181. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6182. json_object_put(FirmwareStatusNotification);
  6183. LWS_Send(message);
  6184. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6185. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6186. {
  6187. result = PASS;
  6188. }
  6189. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6190. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6191. return result;
  6192. }
  6193. //==========================================
  6194. // send confirm routine
  6195. //==========================================
  6196. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6197. {
  6198. mtrace();
  6199. int result = FAIL;
  6200. char message[100]={0};
  6201. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6202. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6203. LWS_Send(message);
  6204. result = TRUE;
  6205. return result;
  6206. }
  6207. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6208. {
  6209. mtrace();
  6210. int result = FAIL;
  6211. char message[100]={0};
  6212. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6213. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6214. LWS_Send(message);
  6215. result = TRUE;
  6216. return result;
  6217. }
  6218. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6219. {
  6220. mtrace();
  6221. int result = FAIL;
  6222. char message[100]={0};
  6223. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6224. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6225. LWS_Send(message);
  6226. result = TRUE;
  6227. return result;
  6228. }
  6229. int sendClearCacheConfirmation(char *uuid,char *payload)
  6230. {
  6231. mtrace();
  6232. int result = FAIL;
  6233. char message[500]={0};
  6234. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6235. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6236. LWS_Send(message);
  6237. return result;
  6238. }
  6239. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6240. {
  6241. mtrace();
  6242. int result = FAIL;
  6243. char message[500]={0};
  6244. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6245. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6246. LWS_Send(message);
  6247. return result;
  6248. }
  6249. int sendDataTransferConfirmation(char *uuid,char *payload)
  6250. {
  6251. mtrace();
  6252. char statusStr[20]={0};
  6253. char dataStr[10]={0};
  6254. char sstr[20]={0};
  6255. int c = 0;
  6256. char *loc;
  6257. int result = FAIL;
  6258. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6259. /**********************status**************************/
  6260. loc = strstr(payload, "status");
  6261. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6262. c = 0;
  6263. while (loc[3+strlen("status")+c] != '\"')
  6264. {
  6265. sstr[c] = loc[3+strlen("status")+c];
  6266. c++;
  6267. }
  6268. sstr[c] = '\0';
  6269. strcpy(statusStr, sstr);
  6270. /**********************data**************************/
  6271. loc = strstr(payload, "data");
  6272. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6273. c = 0;
  6274. while (loc[3+strlen("data")+c] != '\"')
  6275. {
  6276. sstr[c] = loc[3+strlen("data")+c];
  6277. c++;
  6278. }
  6279. sstr[c] = '\0';
  6280. strcpy(dataStr, sstr);
  6281. return result;
  6282. }
  6283. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6284. {
  6285. mtrace();
  6286. int result = FAIL;
  6287. char message[1000]={0};
  6288. int CompositeScheduleIndex = 0;
  6289. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6290. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6291. if(nPeriod == 0)
  6292. {
  6293. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6294. {
  6295. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6296. ,MESSAGE_TYPE_CALLRESULT
  6297. ,uuid
  6298. ,payload
  6299. ,connectorIdInt);
  6300. }
  6301. else
  6302. {
  6303. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6304. ,MESSAGE_TYPE_CALLRESULT
  6305. ,uuid
  6306. ,payload
  6307. ,connectorIdInt
  6308. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6309. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6310. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6311. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6312. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6313. }
  6314. }
  6315. else
  6316. {
  6317. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6318. ,MESSAGE_TYPE_CALLRESULT
  6319. ,uuid
  6320. ,payload
  6321. ,connectorIdInt
  6322. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6323. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6324. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6325. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6326. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6327. {
  6328. if (idx_sample == 0)
  6329. {
  6330. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6331. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6332. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6333. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6334. }
  6335. else
  6336. {
  6337. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6338. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6339. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6340. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6341. }
  6342. }
  6343. sprintf(message + strlen(message), "]}}]");
  6344. }
  6345. LWS_Send(message);
  6346. result = TRUE;
  6347. return result;
  6348. }
  6349. int sendGetConfigurationConfirmation(char *uuid)
  6350. {
  6351. mtrace();
  6352. int result = FAIL;
  6353. int MaxKeySupported = 0;
  6354. int sentConfigurationNumber= 0;
  6355. int sentunConfigurationNumber= 0;
  6356. char message[4000]={0};
  6357. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6358. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6359. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6360. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6361. ,MESSAGE_TYPE_CALLRESULT
  6362. ,uuid );
  6363. //configuration key
  6364. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6365. {
  6366. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6367. {
  6368. if (sentConfigurationNumber == 0)
  6369. {
  6370. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6371. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6372. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6373. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6374. }
  6375. else
  6376. {
  6377. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6378. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6379. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6380. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6381. }
  6382. sentConfigurationNumber = sentConfigurationNumber + 1;
  6383. }
  6384. }
  6385. sprintf(message + strlen(message), "]");
  6386. if(UnknownKeynum != 0)
  6387. {
  6388. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6389. //unkown key
  6390. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6391. {
  6392. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6393. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6394. if(sentunConfigurationNumber == 0)
  6395. {
  6396. sprintf(message + strlen(message), "\"%s\""
  6397. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6398. }
  6399. else
  6400. {
  6401. sprintf(message + strlen(message), ",\"%s\""
  6402. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6403. }
  6404. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6405. }
  6406. sprintf(message + strlen(message), "]");
  6407. }
  6408. sprintf(message + strlen(message), "}]");
  6409. LWS_Send(message);
  6410. return result;
  6411. }
  6412. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6413. {
  6414. mtrace();
  6415. int result = FAIL;
  6416. char message[400]={0};
  6417. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6418. if(strcmp(payload,"")==0)
  6419. {
  6420. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6421. }
  6422. else
  6423. {
  6424. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6425. }
  6426. LWS_Send(message);
  6427. result = TRUE;
  6428. return result;
  6429. }
  6430. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6431. {
  6432. mtrace();
  6433. int result = FAIL;
  6434. char message[80]={0};
  6435. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6436. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  6437. LWS_Send(message);
  6438. result = TRUE;
  6439. return result;
  6440. }
  6441. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6442. {
  6443. mtrace();
  6444. int result = FAIL;
  6445. char message[80]={0};
  6446. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6447. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6448. LWS_Send(message);
  6449. result = TRUE;
  6450. return result;
  6451. }
  6452. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6453. {
  6454. mtrace();
  6455. int result = FAIL;
  6456. char message[80]={0};
  6457. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6458. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6459. LWS_Send(message);
  6460. result = TRUE;
  6461. return result;
  6462. }
  6463. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6464. {
  6465. mtrace();
  6466. int result = FAIL;
  6467. char message[80]={0};
  6468. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6469. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6470. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6471. LWS_Send(message);
  6472. result = TRUE;
  6473. return result;
  6474. }
  6475. int sendResetConfirmation(char *uuid,char *payload)
  6476. {
  6477. mtrace();
  6478. int result = FAIL;
  6479. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6480. char message[80]={0};
  6481. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  6482. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6483. LWS_Send(message);
  6484. result = TRUE;
  6485. return result;
  6486. }
  6487. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6488. {
  6489. mtrace();
  6490. int result = FAIL;
  6491. char message[500]={0};
  6492. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6493. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6494. LWS_Send(message);
  6495. result = TRUE;
  6496. return result;
  6497. }
  6498. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6499. {
  6500. mtrace();
  6501. int result = FAIL;
  6502. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6503. char message[80]={0};
  6504. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6505. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6506. LWS_Send(message);
  6507. result = TRUE;
  6508. return result;
  6509. }
  6510. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6511. {
  6512. mtrace();
  6513. int result = FAIL;
  6514. char message[80]={0};
  6515. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6516. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6517. LWS_Send(message);
  6518. result = TRUE;
  6519. return result;
  6520. }
  6521. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6522. {
  6523. mtrace();
  6524. int result = FAIL;
  6525. char message[80]={0};
  6526. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6527. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6528. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6529. LWS_Send(message);
  6530. result = TRUE;
  6531. return result;
  6532. }
  6533. int sendUpdateFirmwareConfirmation(char *uuid)
  6534. {
  6535. mtrace();
  6536. int result = FAIL;
  6537. char message[60]={0};
  6538. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6539. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6540. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6541. LWS_Send(message);
  6542. result = TRUE;
  6543. return result;
  6544. }
  6545. int sendCertificateSignedConfirmation(char *uuid)
  6546. {
  6547. mtrace();
  6548. int result = PASS;
  6549. char message[4096]={0};
  6550. json_object *CertificateSigned = json_object_new_object();
  6551. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6552. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  6553. sprintf(message,"[%d,\"%s\",%s]"
  6554. ,MESSAGE_TYPE_CALLRESULT
  6555. ,uuid
  6556. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6557. json_object_put(CertificateSigned);
  6558. LWS_Send(message);
  6559. return result;
  6560. }
  6561. int sendDeleteCertificateConfirmation(char *uuid)
  6562. {
  6563. mtrace();
  6564. int result = PASS;
  6565. char message[4096]={0};
  6566. json_object *DeleteCertificate = json_object_new_object();
  6567. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6568. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  6569. sprintf(message,"[%d,\"%s\",%s]"
  6570. ,MESSAGE_TYPE_CALLRESULT
  6571. ,uuid
  6572. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6573. json_object_put(DeleteCertificate);
  6574. LWS_Send(message);
  6575. return result;
  6576. }
  6577. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6578. {
  6579. mtrace();
  6580. int result = PASS;
  6581. char message[4096]={0};
  6582. json_object *ExtendedTriggerMessage = json_object_new_object();
  6583. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6584. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  6585. sprintf(message,"[%d,\"%s\",%s]"
  6586. ,MESSAGE_TYPE_CALLRESULT
  6587. ,uuid
  6588. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6589. json_object_put(ExtendedTriggerMessage);
  6590. LWS_Send(message);
  6591. return result;
  6592. }
  6593. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6594. {
  6595. mtrace();
  6596. int result = PASS;
  6597. char message[4096]={0};
  6598. json_object *GetInstalledCertificateIds = json_object_new_object();
  6599. json_object *certificateHashDataDatas = json_object_new_array();
  6600. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6601. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  6602. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6603. {
  6604. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6605. {
  6606. json_object *certificateHashData = json_object_new_object();
  6607. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6608. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6609. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6610. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6611. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6612. }
  6613. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6614. }
  6615. else
  6616. {
  6617. json_object_put(certificateHashDataDatas);
  6618. }
  6619. sprintf(message,"[%d,\"%s\",%s]"
  6620. ,MESSAGE_TYPE_CALLRESULT
  6621. ,uuid
  6622. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6623. json_object_put(GetInstalledCertificateIds);
  6624. LWS_Send(message);
  6625. return result;
  6626. }
  6627. int sendGetLogConfirmation(char *uuid)
  6628. {
  6629. mtrace();
  6630. int result = PASS;
  6631. char message[4096]={0};
  6632. json_object *GetLog = json_object_new_object();
  6633. DEBUG_INFO("sendGetLogConfirmation...\n");
  6634. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  6635. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  6636. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  6637. sprintf(message,"[%d,\"%s\",%s]"
  6638. ,MESSAGE_TYPE_CALLRESULT
  6639. ,uuid
  6640. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6641. json_object_put(GetLog);
  6642. LWS_Send(message);
  6643. return result;
  6644. }
  6645. int sendInstallCertificateConfirmation(char *uuid)
  6646. {
  6647. mtrace();
  6648. int result = PASS;
  6649. char message[4096]={0};
  6650. json_object *InstallCertificate = json_object_new_object();
  6651. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6652. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  6653. sprintf(message,"[%d,\"%s\",%s]"
  6654. ,MESSAGE_TYPE_CALLRESULT
  6655. ,uuid
  6656. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6657. json_object_put(InstallCertificate);
  6658. LWS_Send(message);
  6659. return result;
  6660. }
  6661. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6662. {
  6663. mtrace();
  6664. int result = PASS;
  6665. char message[4096]={0};
  6666. json_object *SignedUpdateFirmware = json_object_new_object();
  6667. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6668. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  6669. sprintf(message,"[%d,\"%s\",%s]"
  6670. ,MESSAGE_TYPE_CALLRESULT
  6671. ,uuid
  6672. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6673. json_object_put(SignedUpdateFirmware);
  6674. LWS_Send(message);
  6675. return result;
  6676. }
  6677. int sendUnknownConfirmation(char *uuid)
  6678. {
  6679. mtrace();
  6680. int result = PASS;
  6681. char message[256]={0};
  6682. DEBUG_INFO("sendUnknownConfirmation...\n");
  6683. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6684. LWS_Send(message);
  6685. return result;
  6686. }
  6687. //==========================================
  6688. // Handle server request routine Start
  6689. //==========================================
  6690. int handleCancelReservationRequest(char *uuid, char *payload)
  6691. {
  6692. mtrace();
  6693. int result = FAIL;
  6694. int gunNO = 0;
  6695. int reservationIdInt = -1;
  6696. char comfirmstr[20];
  6697. DEBUG_INFO("handleCancelReservationRequest...\n");
  6698. json_object *CancelReservation;
  6699. CancelReservation = json_tokener_parse(payload);
  6700. if(!is_error(CancelReservation))
  6701. {
  6702. // Required data
  6703. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6704. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6705. }
  6706. json_object_put(CancelReservation);
  6707. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6708. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6709. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6710. if(reservationIdInt != -1)
  6711. {
  6712. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6713. //check Transaction active
  6714. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6715. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6716. {
  6717. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6718. {
  6719. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6720. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6721. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6722. {
  6723. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6724. }
  6725. else
  6726. {
  6727. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6728. }
  6729. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6730. goto end;
  6731. }
  6732. }
  6733. for (int index = 0; index < CCS_QUANTITY; index++)
  6734. {
  6735. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6736. {
  6737. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6738. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6739. if(gunType[2] == GUN_TYPE_CCS)
  6740. {
  6741. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6742. }
  6743. else
  6744. {
  6745. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6746. }
  6747. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6748. goto end;
  6749. }
  6750. }
  6751. for (int index = 0; index < GB_QUANTITY; index++)
  6752. {
  6753. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6754. {
  6755. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6756. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6757. if(gunType[2] == GUN_TYPE_GBT)
  6758. {
  6759. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6760. }
  6761. else
  6762. {
  6763. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6764. }
  6765. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6766. goto end;
  6767. }
  6768. }
  6769. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6770. {
  6771. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6772. {
  6773. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6774. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6775. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6776. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6777. goto end;
  6778. }
  6779. }
  6780. for (int index = 0; index < AC_QUANTITY; index++)
  6781. {
  6782. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6783. {
  6784. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6785. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6786. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6787. {
  6788. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6789. }
  6790. else
  6791. {
  6792. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6793. }
  6794. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6795. goto end;
  6796. }
  6797. }
  6798. }
  6799. //The reservationId does NOT match the reservationId
  6800. sendCancelReservationConfirmation(uuid, comfirmstr);
  6801. end:
  6802. // Fill in ocpp packet uuid
  6803. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  6804. return result;
  6805. }
  6806. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6807. {
  6808. mtrace();
  6809. int result = FAIL;
  6810. int gunIndex = 0;
  6811. char typeStr[16]={0};
  6812. char comfirmstr[20];
  6813. int specificId = FALSE;
  6814. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6815. json_object *ChangeAvailability;
  6816. ChangeAvailability = json_tokener_parse(payload);
  6817. if(!is_error(ChangeAvailability))
  6818. {
  6819. // Required data
  6820. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6821. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6822. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6823. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6824. }
  6825. json_object_put(ChangeAvailability);
  6826. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6827. {
  6828. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6829. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6830. }
  6831. else if(gunIndex == 0)
  6832. {
  6833. for(int i=0; i < gunTotalNumber; i++)
  6834. {
  6835. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  6836. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  6837. }
  6838. }
  6839. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6840. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6841. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6842. {
  6843. specificId = TRUE;
  6844. }
  6845. if(specificId == FALSE)
  6846. goto end;
  6847. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6848. {
  6849. //----------------------gunIndex is 0 ------------------------------------------------//
  6850. if(gunIndex == 0)
  6851. {
  6852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6853. {
  6854. for(int i=0; i < gunTotalNumber; i++)
  6855. {
  6856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6857. {
  6858. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6859. {
  6860. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6861. {
  6862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6863. goto end;
  6864. }
  6865. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6866. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6867. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6868. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6869. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6870. {
  6871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6872. goto end;
  6873. }
  6874. }
  6875. }//END FOR CHAdeMO_QUANTITY
  6876. for (int index = 0; index < CCS_QUANTITY; index++)
  6877. {
  6878. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6879. {
  6880. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6881. {
  6882. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6883. goto end;
  6884. }
  6885. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6886. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6887. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6888. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6889. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6890. {
  6891. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6892. goto end;
  6893. }
  6894. }
  6895. }//END FOR CCS_QUANTITY
  6896. for (int index = 0; index < GB_QUANTITY; index++)
  6897. {
  6898. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6899. {
  6900. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6901. {
  6902. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6903. goto end;
  6904. }
  6905. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6906. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6907. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6908. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6909. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6910. {
  6911. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6912. goto end;
  6913. }
  6914. }
  6915. }// END FOR GB_QUANTITY
  6916. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6917. {
  6918. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6919. {
  6920. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6921. {
  6922. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6923. goto end;
  6924. }
  6925. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6926. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6927. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6928. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6929. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6930. {
  6931. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6932. goto end;
  6933. }
  6934. }
  6935. }// END FOR GENERAL_GUN_QUANTITY
  6936. for (int index = 0; index < AC_QUANTITY; index++)
  6937. {
  6938. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6939. {
  6940. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6941. {
  6942. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6943. goto end;
  6944. }
  6945. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6946. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6947. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6948. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6949. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6950. {
  6951. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6952. goto end;
  6953. }
  6954. }
  6955. }//END FOR AC_QUANTITY
  6956. }// END FOR gunTotalNumber
  6957. }
  6958. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6959. {
  6960. for(int i=0; i < gunTotalNumber; i++)
  6961. {
  6962. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6963. {
  6964. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6965. goto end;
  6966. }
  6967. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6968. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6969. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6970. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6971. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6972. {
  6973. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6974. goto end;
  6975. }
  6976. }
  6977. }
  6978. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6979. goto end;
  6980. }
  6981. //----------------------gunIndex is not 0 ------------------------------------------------//
  6982. //check Transaction active
  6983. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6984. {
  6985. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6986. {
  6987. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6988. {
  6989. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6990. goto end;
  6991. }
  6992. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6993. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6994. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6995. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6996. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6997. {
  6998. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6999. goto end;
  7000. }
  7001. else
  7002. {
  7003. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7004. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7005. goto end;
  7006. }
  7007. }
  7008. }//END FOR CHAdeMO_QUANTITY
  7009. for (int index = 0; index < CCS_QUANTITY; index++)
  7010. {
  7011. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7012. {
  7013. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7014. {
  7015. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7016. goto end;
  7017. }
  7018. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7019. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7020. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7021. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7022. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7023. {
  7024. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7025. goto end;
  7026. }
  7027. else
  7028. {
  7029. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7030. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7031. goto end;
  7032. }
  7033. }
  7034. }//END FOR CCS_QUANTITY
  7035. for (int index = 0; index < GB_QUANTITY; index++)
  7036. {
  7037. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7038. {
  7039. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7040. {
  7041. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7042. goto end;
  7043. }
  7044. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7045. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7046. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7047. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7048. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7049. {
  7050. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7051. goto end;
  7052. }
  7053. else
  7054. {
  7055. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7056. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7057. goto end;
  7058. }
  7059. }
  7060. }// END FOR GB_QUANTITY
  7061. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7062. {
  7063. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7064. {
  7065. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7066. {
  7067. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7068. goto end;
  7069. }
  7070. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7071. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7072. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7073. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7074. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7075. {
  7076. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7077. goto end;
  7078. }
  7079. else
  7080. {
  7081. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7082. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7083. goto end;
  7084. }
  7085. }
  7086. }// END FOR GENERAL_GUN_QUANTITY
  7087. for (int index = 0; index < AC_QUANTITY; index++)
  7088. {
  7089. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7090. {
  7091. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7092. {
  7093. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7094. goto end;
  7095. }
  7096. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7097. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7098. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7099. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7100. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7101. {
  7102. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7103. goto end;
  7104. }
  7105. else
  7106. {
  7107. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7108. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7109. goto end;
  7110. }
  7111. }
  7112. }//END FOR AC_QUANTITY
  7113. }//END FOR AvailabilityTypeStr[Inoperative]
  7114. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7115. {
  7116. //----------------------gunIndex is 0 ------------------------------------------------//
  7117. if(gunIndex == 0)
  7118. {
  7119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7120. {
  7121. for(int i=0; i < gunTotalNumber; i++)
  7122. {
  7123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7124. {
  7125. 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
  7126. {
  7127. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7128. goto end;
  7129. }
  7130. }//END FOR CHAdeMO_QUANTITY
  7131. for (int index = 0; index < CCS_QUANTITY; index++)
  7132. {
  7133. 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
  7134. {
  7135. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7136. goto end;
  7137. }
  7138. }//END FOR CCS_QUANTITY
  7139. for (int index = 0; index < GB_QUANTITY; index++)
  7140. {
  7141. 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
  7142. {
  7143. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7144. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7145. goto end;
  7146. }
  7147. }// END FOR GB_QUANTITY
  7148. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7149. {
  7150. 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
  7151. {
  7152. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7153. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7154. goto end;
  7155. }
  7156. }// END FOR GENERAL_GUN_QUANTITY
  7157. for (int index = 0; index < AC_QUANTITY; index++)
  7158. {
  7159. 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
  7160. {
  7161. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7162. goto end;
  7163. }
  7164. }//END FOR CHAdeMO_QUANTITY
  7165. }// END FOR gunTotalNumber
  7166. }
  7167. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7168. {
  7169. for(int i=0; i < gunTotalNumber; i++)
  7170. {
  7171. for (int index = 0; index < AC_QUANTITY; index++)
  7172. {
  7173. 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
  7174. {
  7175. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7176. goto end;
  7177. }
  7178. }//END FOR CHAdeMO_QUANTITY
  7179. } // END FOR gunTotalNumber
  7180. }
  7181. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7182. goto end;
  7183. }
  7184. //----------------------gunIndex is not 0 ------------------------------------------------//
  7185. //check Transaction active
  7186. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7187. {
  7188. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7189. {
  7190. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7191. goto end;
  7192. }
  7193. }//END FOR CHAdeMO_QUANTITY
  7194. for (int index = 0; index < CCS_QUANTITY; index++)
  7195. {
  7196. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7197. {
  7198. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7199. goto end;
  7200. }
  7201. }//END FOR CCS_QUANTITY
  7202. for (int index = 0; index < GB_QUANTITY; index++)
  7203. {
  7204. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7205. {
  7206. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7207. goto end;
  7208. }
  7209. }// END FOR GB_QUANTITY
  7210. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7211. {
  7212. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7213. {
  7214. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7215. goto end;
  7216. }
  7217. }// END FOR GENERAL_GUN_QUANTITY
  7218. for (int index = 0; index < AC_QUANTITY; index++)
  7219. {
  7220. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7221. {
  7222. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7223. goto end;
  7224. }
  7225. }//END FOR AC_QUANTITY
  7226. }//END FOR AvailabilityTypeStr[Operative]
  7227. end:
  7228. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7229. {
  7230. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7231. }
  7232. else
  7233. {
  7234. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7235. }
  7236. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7237. {
  7238. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7239. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7240. }
  7241. else if(gunIndex == 0)
  7242. {
  7243. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7244. {
  7245. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7246. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7247. }
  7248. }
  7249. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7250. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7251. return result;
  7252. }
  7253. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7254. {
  7255. mtrace();
  7256. int result = FAIL;
  7257. char keystr[40]={0};
  7258. char valuestr[256]={0};
  7259. char comfirmstr[20]={0};
  7260. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7261. json_object *ChangeConfiguration;
  7262. ChangeConfiguration = json_tokener_parse(payload);
  7263. if(!is_error(ChangeConfiguration))
  7264. {
  7265. // Required data
  7266. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7267. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7268. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7269. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7270. }
  7271. json_object_put(ChangeConfiguration);
  7272. if((uuid==NULL) || (payload ==NULL) )
  7273. {
  7274. DEBUG_ERROR("Payload is null\n");
  7275. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7276. }
  7277. else
  7278. {
  7279. int status = setKeyValue(keystr, valuestr);
  7280. switch(status)
  7281. {
  7282. case ConfigurationStatus_Accepted:
  7283. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7284. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7285. StoreConfigurationTable();
  7286. break;
  7287. case RebootRequired:
  7288. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7289. StoreConfigurationTable();
  7290. break;
  7291. case NotSupported:
  7292. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7293. break;
  7294. case ConfigurationStatus_Rejected:
  7295. default:
  7296. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7297. break;
  7298. }
  7299. }
  7300. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7301. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7302. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7303. {
  7304. ChageWebSocketPingInterval(atoi(valuestr));
  7305. }
  7306. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7307. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7308. {
  7309. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7310. SetOcppConnStatus(FALSE);
  7311. }
  7312. return result;
  7313. }
  7314. int handleClearCacheRequest(char *uuid, char *payload)
  7315. {
  7316. mtrace();
  7317. int result = FAIL;
  7318. char comfirmstr[20];
  7319. char rmFileCmd[100]={0};
  7320. struct stat stats;
  7321. DEBUG_INFO("handleClearCacheRequest...\n");
  7322. stat("/Storage/OCPP_PH", &stats);
  7323. // Check for directory existence
  7324. if (S_ISDIR(stats.st_mode) == 1)
  7325. {}
  7326. else
  7327. {
  7328. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7329. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  7330. system(rmFileCmd);
  7331. }
  7332. if(OCPP_cleanLocalCache())
  7333. {
  7334. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7335. }
  7336. else
  7337. {
  7338. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7339. }
  7340. sendClearCacheConfirmation(uuid, comfirmstr);
  7341. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7342. return result;
  7343. }
  7344. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7345. {
  7346. mtrace();
  7347. int result = FAIL;
  7348. int resultRename;
  7349. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7350. char chargingProfilePurposeStr[26]={0};
  7351. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7352. char tempchargingProfilePurposeStr[26]={0};
  7353. char str[100]={0};
  7354. char fname[200]={0};
  7355. char comfirmstr[20]={0};
  7356. char word[1600]={0};
  7357. int clearflag = FALSE;
  7358. int chargingProfileIdIsNULL = FALSE;
  7359. int connectorIsNULL = FALSE;
  7360. int chargingProfilePurposeIsNULL = FALSE;
  7361. int stackLevelIsNULL = FALSE;
  7362. //int GotoEnd = FALSE;
  7363. FILE *fptr1, *fptr2;
  7364. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  7365. int n_chargingProfile=0;
  7366. int isEmptyFile = FALSE;
  7367. char sLineWord[1600]={0};
  7368. char chargingProfiles[10][100]={0};
  7369. int ChargeProfileCount = 0;
  7370. int ch;
  7371. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7372. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7373. json_object *ClearChargingProfile;
  7374. ClearChargingProfile = json_tokener_parse(payload);
  7375. if(!is_error(ClearChargingProfile))
  7376. {
  7377. // Optional data
  7378. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7379. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7380. else
  7381. chargingProfileIdIsNULL = TRUE;
  7382. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7383. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7384. else
  7385. connectorIsNULL = TRUE;
  7386. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7387. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7388. else
  7389. chargingProfilePurposeIsNULL = TRUE;
  7390. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7391. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7392. else
  7393. stackLevelIsNULL = TRUE;
  7394. }
  7395. json_object_put(ClearChargingProfile);
  7396. if(connectorIsNULL == FALSE)
  7397. {
  7398. switch(connectorIdInt)
  7399. {
  7400. case 0:
  7401. if(chargingProfilePurposeIsNULL == TRUE)
  7402. {
  7403. int l = 0;
  7404. strcpy(fname, ChargePointMaxProfile_JSON);
  7405. if((access(fname,F_OK))!=-1)
  7406. {
  7407. strcpy(chargingProfiles[l], fname);
  7408. l = l + 1;
  7409. }
  7410. strcpy(fname, TxDefaultProfile_0_JSON);
  7411. if((access(fname,F_OK))!=-1)
  7412. {
  7413. strcpy(chargingProfiles[l], fname);
  7414. l = l + 1;
  7415. }
  7416. ChargeProfileCount = l;
  7417. }
  7418. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7419. {
  7420. strcpy(fname, ChargePointMaxProfile_JSON);
  7421. if((access(fname,F_OK))!=-1)
  7422. {
  7423. strcpy(chargingProfiles[0], fname);
  7424. ChargeProfileCount = 1;
  7425. }
  7426. }
  7427. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7428. {
  7429. strcpy(fname, TxDefaultProfile_0_JSON);
  7430. if((access(fname,F_OK))!=-1)
  7431. {
  7432. strcpy(chargingProfiles[0], fname);
  7433. ChargeProfileCount = 1;
  7434. }
  7435. }
  7436. break;
  7437. default:
  7438. if(chargingProfilePurposeIsNULL == TRUE)
  7439. {
  7440. int m = 0;
  7441. memset(fname, 0, ARRAY_SIZE(fname));
  7442. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7443. if((access(fname,F_OK))!=-1)
  7444. {
  7445. strcpy(chargingProfiles[m], fname);
  7446. m = m + 1;
  7447. }
  7448. memset(fname, 0, ARRAY_SIZE(fname));
  7449. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7450. if((access(fname,F_OK))!=-1)
  7451. {
  7452. strcpy(chargingProfiles[m], fname);
  7453. m = m + 1;
  7454. }
  7455. ChargeProfileCount = m;
  7456. }
  7457. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7458. {
  7459. //strcpy(fname, TxDefaultProfile_1_JSON);
  7460. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7461. if((access(fname,F_OK))!=-1)
  7462. {
  7463. strcpy(chargingProfiles[0], fname);
  7464. ChargeProfileCount = 1;
  7465. }
  7466. }
  7467. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7468. {
  7469. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7470. if((access(fname,F_OK))!=-1)
  7471. {
  7472. strcpy(chargingProfiles[0], fname);
  7473. ChargeProfileCount = 1;
  7474. }
  7475. //strcpy(fname, TxProfile_1_JSON);
  7476. }
  7477. //strcpy(fname, ChargePointMaxProfile_JSON );
  7478. break;
  7479. }
  7480. }
  7481. else // Check all Charging Profiles
  7482. {
  7483. int i = 0;
  7484. char fnametemp[200]={0};
  7485. ChargeProfileCount = 0;
  7486. //Check ChargePointMaxProfile.json exit
  7487. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  7488. {
  7489. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  7490. i = i + 1;
  7491. }
  7492. //Check TxDefaultProfile_0.json exit
  7493. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  7494. {
  7495. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  7496. i = i + 1;
  7497. }
  7498. //Check TxDefaultProfile_%d.json
  7499. for(int j=1; j <= gunTotalNumber; j++)
  7500. {
  7501. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7502. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  7503. if((access(fnametemp,F_OK))!=-1)
  7504. {
  7505. strcpy(chargingProfiles[i], fnametemp);
  7506. i = i + 1;
  7507. }
  7508. }
  7509. //Check TxProfile_%d.json
  7510. for(int j=1; j <= gunTotalNumber; j++)
  7511. {
  7512. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7513. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  7514. if((access(fnametemp,F_OK))!=-1)
  7515. {
  7516. strcpy(chargingProfiles[i], fnametemp);
  7517. i = i + 1;
  7518. }
  7519. }
  7520. ChargeProfileCount = i;
  7521. }// End connectorIsNULL is TRUE
  7522. if(ChargeProfileCount == 0)
  7523. {
  7524. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7525. goto end;
  7526. }
  7527. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7528. {
  7529. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7530. goto end;
  7531. }
  7532. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7533. {
  7534. memset(str, 0, ARRAY_SIZE(str));
  7535. // clear temp file
  7536. sprintf(str,"rm -f %s",temp);
  7537. system(str);
  7538. for(int k=0; k < ChargeProfileCount; k++)
  7539. {
  7540. memset(str, 0, ARRAY_SIZE(str));
  7541. //clear file in C
  7542. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7543. system(str);
  7544. }
  7545. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7546. goto end;
  7547. }
  7548. else if(connectorIsNULL == TRUE)
  7549. {
  7550. for(int k=0; k < ChargeProfileCount; k++)
  7551. {
  7552. fptr1 = fopen(chargingProfiles[k], "r");
  7553. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  7554. //Check Charging Profile Count
  7555. while(fscanf(fptr1, "%s", word) != EOF)
  7556. {
  7557. //DEBUG_INFO("word=%s\n",word);
  7558. if(strstr(word, "chargingProfileId")!= NULL)
  7559. {
  7560. //DEBUG_INFO("test chargingProfileId \n");
  7561. n_chargingProfile = n_chargingProfile + 1;
  7562. //DEBUG_INFO("chargingProfileId Found\n");
  7563. }
  7564. }
  7565. rewind(fptr1);
  7566. //search Charging Profile Element
  7567. //int i= 0;
  7568. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7569. {
  7570. json_object *tmpProfilee;
  7571. tmpProfilee = json_tokener_parse(sLineWord);
  7572. if(!is_error(tmpProfilee))
  7573. {
  7574. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7575. {
  7576. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7577. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7578. }
  7579. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7580. {
  7581. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7582. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7583. }
  7584. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7585. {
  7586. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7587. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7588. }
  7589. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7590. {
  7591. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7592. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7593. }
  7594. }
  7595. json_object_put(tmpProfilee);
  7596. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7597. {
  7598. //------- not write to fptr2-------//
  7599. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7600. //clearflag = TRUE;
  7601. }
  7602. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7603. {
  7604. //------- not write to fptr2-------//
  7605. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7606. }
  7607. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7608. {
  7609. //------- not write to fptr2-------//
  7610. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7611. }
  7612. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7613. {
  7614. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7615. }
  7616. else
  7617. {
  7618. fprintf(fptr2, sLineWord);//writing data into file
  7619. }
  7620. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7621. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7622. if(clearflag == TRUE)
  7623. {
  7624. fclose(fptr1);
  7625. fclose(fptr2);
  7626. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7627. system(str);
  7628. // clear temp file
  7629. sprintf(str,"rm -f %s",temp);
  7630. system(str);
  7631. }
  7632. else
  7633. {
  7634. fclose(fptr1);
  7635. fclose(fptr2);
  7636. memset(str, 0, ARRAY_SIZE(str));
  7637. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7638. system(str);
  7639. resultRename = rename(temp, chargingProfiles[k]);
  7640. if(resultRename == 0)
  7641. {
  7642. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7643. }
  7644. else
  7645. {
  7646. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7647. }
  7648. if(comfirmstr[0]== 0)
  7649. {
  7650. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7651. }
  7652. //Check chargingProfile is empty file
  7653. /*------ Read the file ----------------*/
  7654. fptr1=fopen(chargingProfiles[k],"r");
  7655. ch=fgetc(fptr1);
  7656. rewind(fptr1);
  7657. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7658. if(ch!=EOF)
  7659. {
  7660. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7661. {
  7662. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7663. if(sLineWord[0]=='\0')
  7664. {
  7665. isEmptyFile = TRUE;
  7666. break;
  7667. }
  7668. else
  7669. {
  7670. isEmptyFile = FALSE;
  7671. break;
  7672. }
  7673. }
  7674. }
  7675. else
  7676. isEmptyFile = TRUE;
  7677. fclose(fptr1);
  7678. if(isEmptyFile == TRUE)
  7679. {
  7680. memset(str, 0, ARRAY_SIZE(str));
  7681. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7682. system(str);
  7683. }
  7684. }
  7685. }// End of while(int k=0; k < ChargePointCount; k++)
  7686. }
  7687. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7688. {
  7689. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7690. for(int k=0; k < ChargeProfileCount; k++)
  7691. {
  7692. fptr1 = fopen(chargingProfiles[k], "r");
  7693. fptr2 = fopen(temp, "w+");
  7694. //Check Charging Profile Count
  7695. while(fscanf(fptr1, "%s", word) != EOF)
  7696. {
  7697. //DEBUG_INFO("word=%s\n",word);
  7698. if(strstr(word, "chargingProfileId")!= NULL)
  7699. {
  7700. n_chargingProfile = n_chargingProfile + 1;
  7701. }
  7702. }
  7703. rewind(fptr1);
  7704. //search Charging Profile Element
  7705. //int i= 0;
  7706. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7707. {
  7708. json_object *tmpProfilee;
  7709. tmpProfilee = json_tokener_parse(sLineWord);
  7710. if(!is_error(tmpProfilee))
  7711. {
  7712. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7713. {
  7714. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7715. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7716. }
  7717. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7718. {
  7719. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7720. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7721. }
  7722. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7723. {
  7724. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7725. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7726. }
  7727. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7728. {
  7729. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7730. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7731. }
  7732. }
  7733. json_object_put(tmpProfilee);
  7734. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7735. {
  7736. //------- not write to fptr2-------//
  7737. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7738. //clearflag = TRUE;
  7739. }
  7740. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7741. {
  7742. //------- not write to fptr2-------//
  7743. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7744. }
  7745. else if(stackLevelIsNULL == TRUE)
  7746. {
  7747. //Clear Whole File
  7748. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7749. clearflag = TRUE;
  7750. break;
  7751. }
  7752. else
  7753. {
  7754. fprintf(fptr2, sLineWord);//writing data into file
  7755. }
  7756. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7757. }
  7758. if(clearflag == TRUE)
  7759. {
  7760. fclose(fptr1);
  7761. fclose(fptr2);
  7762. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7763. system(str);
  7764. // clear temp file
  7765. sprintf(str,"rm -f %s",temp);
  7766. system(str);
  7767. }
  7768. else
  7769. {
  7770. fclose(fptr1);
  7771. fclose(fptr2);
  7772. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7773. system(str);
  7774. resultRename = rename(temp, chargingProfiles[k]);
  7775. if(resultRename == 0)
  7776. {
  7777. DEBUG_INFO("File ChargingProfile renamed successfully");
  7778. }
  7779. else
  7780. {
  7781. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7782. }
  7783. if(comfirmstr[0]== 0)
  7784. {
  7785. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7786. }
  7787. //Check chargingProfile is empty file
  7788. /*------ Read the file ----------------*/
  7789. fptr1=fopen(chargingProfiles[k],"r");
  7790. ch=fgetc(fptr1);
  7791. rewind(fptr1);
  7792. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7793. if(ch!=EOF)
  7794. {
  7795. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7796. {
  7797. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7798. if(sLineWord[0]=='\0')
  7799. {
  7800. isEmptyFile = TRUE;
  7801. break;
  7802. }
  7803. else
  7804. {
  7805. isEmptyFile = FALSE;
  7806. break;
  7807. }
  7808. }
  7809. }
  7810. else
  7811. isEmptyFile = TRUE;
  7812. fclose(fptr1);
  7813. if(isEmptyFile == TRUE)
  7814. {
  7815. memset(str, 0, ARRAY_SIZE(str));
  7816. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7817. system(str);
  7818. }
  7819. /*------- End of reading ---------------*/
  7820. }
  7821. } // while(int k=0; k < ChargeProfileCount; k++)
  7822. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7823. end:
  7824. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7825. {
  7826. if(connectorIdInt == 0)
  7827. {
  7828. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7829. {
  7830. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  7831. }
  7832. }
  7833. else
  7834. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  7835. }
  7836. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7837. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7838. return result;
  7839. }
  7840. void createFirmwareVersionByDataTransfer(void)
  7841. {
  7842. json_object *FirmwareDataTransfer = json_object_new_object();
  7843. // AC & DC model
  7844. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7845. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7846. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7847. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7848. // DC model
  7849. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7850. {
  7851. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  7852. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  7853. (gunType[3] != GUN_TYPE_UNKNOWN))
  7854. {
  7855. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7856. }
  7857. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  7858. {
  7859. // DS DM DW
  7860. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7861. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7862. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7863. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7864. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7865. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7866. }
  7867. else
  7868. {
  7869. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7870. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7871. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7872. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7873. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7874. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7875. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7876. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7877. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7878. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7879. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7880. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7881. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7882. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7883. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7884. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7885. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7886. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7887. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7888. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7889. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7890. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7891. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7892. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7893. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7894. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7895. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7896. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7897. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7898. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7899. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7900. }
  7901. }
  7902. // 4G model
  7903. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7904. {
  7905. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7906. }
  7907. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7908. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7909. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7910. json_object_put(FirmwareDataTransfer);
  7911. }
  7912. int handleDataTransferRequest(char *uuid, char *payload)
  7913. {
  7914. mtrace();
  7915. json_object *response = json_object_new_object();
  7916. int result = FAIL;
  7917. char tempvendorId[255]={0};
  7918. char tempmessageId[50]={0};
  7919. char tempdata[512]={0};
  7920. char message[2048]={0};
  7921. DEBUG_INFO("handleDataTransferRequest...\n");
  7922. if((uuid != NULL) && (payload != NULL))
  7923. {
  7924. json_object *DataTransfer;
  7925. DataTransfer = json_tokener_parse(payload);
  7926. if(!is_error(DataTransfer))
  7927. {
  7928. // Required data
  7929. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7930. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7931. // Optional data
  7932. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7933. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7934. if(json_object_object_get(DataTransfer, "data") != NULL)
  7935. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7936. result = PASS;
  7937. }
  7938. json_object_put(DataTransfer);
  7939. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7940. {
  7941. // Send all moudle firmware version on EVSE
  7942. createFirmwareVersionByDataTransfer();
  7943. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7944. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  7945. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7946. json_object_put(response);
  7947. }
  7948. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7949. {
  7950. system("/usr/bin/run_tmate_restart.sh &");
  7951. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7952. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7953. json_object_put(response);
  7954. }
  7955. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7956. {
  7957. json_object *data;
  7958. data = json_tokener_parse(tempdata);
  7959. if(!is_error(data))
  7960. {
  7961. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7962. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7963. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7964. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7965. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7966. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7967. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7968. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7969. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7970. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7971. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7972. }
  7973. else
  7974. {
  7975. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7976. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7977. }
  7978. json_object_put(data);
  7979. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7980. json_object_put(response);
  7981. }
  7982. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7983. {
  7984. json_object *data;
  7985. data = json_tokener_parse(tempdata);
  7986. if(!is_error(data))
  7987. {
  7988. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7989. if(json_object_object_get(data, "idToken") != NULL)
  7990. {
  7991. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7992. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7993. }
  7994. if(json_object_object_get(data, "price") != NULL)
  7995. {
  7996. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7997. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7998. }
  7999. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8000. }
  8001. else
  8002. {
  8003. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8004. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8005. }
  8006. json_object_put(data);
  8007. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8008. json_object_put(response);
  8009. }
  8010. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8011. {
  8012. json_object *data;
  8013. data = json_tokener_parse(tempdata);
  8014. if(!is_error(data))
  8015. {
  8016. if(json_object_object_get(data, "txId") != NULL)
  8017. {
  8018. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8019. for(int idx = 0;idx<gunTotalNumber;idx++)
  8020. {
  8021. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8022. {
  8023. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8024. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8025. if(json_object_object_get(data, "description") != NULL)
  8026. {
  8027. // California pricing V1.0
  8028. DEBUG_INFO("California pricing V1.0\n");
  8029. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8030. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8031. }
  8032. else
  8033. {
  8034. // California pricing V1.1
  8035. DEBUG_INFO("California pricing V1.1\n");
  8036. if(json_object_object_get(data, "timestamp") != NULL)
  8037. {
  8038. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8039. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8040. }
  8041. if(json_object_object_get(data, "meterValue") != NULL)
  8042. {
  8043. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8044. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8045. }
  8046. if(json_object_object_get(data, "cost") != NULL)
  8047. {
  8048. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8049. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8050. }
  8051. if(json_object_object_get(data, "state") != NULL)
  8052. {
  8053. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8054. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8055. }
  8056. if(json_object_object_get(data, "chargingPrice") != NULL)
  8057. {
  8058. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8059. {
  8060. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8061. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8062. }
  8063. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8064. {
  8065. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8066. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8067. }
  8068. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8069. {
  8070. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8071. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8072. }
  8073. }
  8074. if(json_object_object_get(data, "idlePrice") != NULL)
  8075. {
  8076. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8077. {
  8078. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8079. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8080. }
  8081. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8082. {
  8083. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8084. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8085. }
  8086. }
  8087. if(json_object_object_get(data, "nextPeriod") != NULL)
  8088. {
  8089. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8090. {
  8091. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8092. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8093. }
  8094. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8095. {
  8096. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8097. {
  8098. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  8099. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  8100. }
  8101. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8102. {
  8103. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  8104. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  8105. }
  8106. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8107. {
  8108. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  8109. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  8110. }
  8111. }
  8112. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8113. {
  8114. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8115. {
  8116. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  8117. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  8118. }
  8119. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8120. {
  8121. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  8122. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  8123. }
  8124. }
  8125. }
  8126. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8127. {
  8128. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8129. {
  8130. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8131. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8132. }
  8133. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8134. {
  8135. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8136. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8137. }
  8138. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8139. {
  8140. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8141. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8142. }
  8143. }
  8144. }
  8145. }
  8146. }
  8147. }
  8148. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8149. }
  8150. else
  8151. {
  8152. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8153. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8154. }
  8155. json_object_put(data);
  8156. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8157. json_object_put(response);
  8158. }
  8159. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8160. {
  8161. json_object *data;
  8162. data = json_tokener_parse(tempdata);
  8163. if(!is_error(data))
  8164. {
  8165. if(json_object_object_get(data, "txId") != NULL)
  8166. {
  8167. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8168. for(int idx = 0;idx<gunTotalNumber;idx++)
  8169. {
  8170. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8171. {
  8172. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8173. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8174. if(json_object_object_get(data, "description") != NULL)
  8175. {
  8176. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8177. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8178. }
  8179. }
  8180. }
  8181. }
  8182. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8183. }
  8184. else
  8185. {
  8186. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8187. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8188. }
  8189. json_object_put(data);
  8190. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8191. json_object_put(response);
  8192. }
  8193. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8194. {
  8195. json_object *data;
  8196. data = json_tokener_parse(tempdata);
  8197. if(!is_error(data))
  8198. {
  8199. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8200. if(json_object_object_get(data, "Content_Type") != NULL)
  8201. {
  8202. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  8203. {
  8204. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8205. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8206. {
  8207. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8208. }
  8209. }
  8210. else
  8211. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8212. }
  8213. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8214. }
  8215. else
  8216. {
  8217. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8218. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8219. }
  8220. json_object_put(data);
  8221. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8222. json_object_put(response);
  8223. }
  8224. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8225. {
  8226. json_object *data;
  8227. data = json_tokener_parse(tempdata);
  8228. if(!is_error(data))
  8229. {
  8230. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8231. if(json_object_object_get(data, "Page_Index") != NULL)
  8232. {
  8233. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8234. }
  8235. if(json_object_object_get(data, "Duration") != NULL)
  8236. {
  8237. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8238. }
  8239. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8240. }
  8241. else
  8242. {
  8243. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8244. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8245. }
  8246. json_object_put(data);
  8247. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8248. json_object_put(response);
  8249. }
  8250. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8251. {
  8252. json_object *data;
  8253. data = json_tokener_parse(tempdata);
  8254. if(!is_error(data))
  8255. {
  8256. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8257. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8258. {
  8259. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8260. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8261. else
  8262. {
  8263. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8264. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8265. }
  8266. }
  8267. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8268. {
  8269. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8270. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8271. else
  8272. {
  8273. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8274. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8275. }
  8276. }
  8277. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8278. {
  8279. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8280. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8281. else
  8282. {
  8283. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8284. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8285. }
  8286. }
  8287. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8288. {
  8289. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8290. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8291. else
  8292. {
  8293. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8294. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8295. }
  8296. }
  8297. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8298. {
  8299. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8300. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8301. else
  8302. {
  8303. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8304. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8305. }
  8306. }
  8307. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8308. {
  8309. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8310. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8311. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8312. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8313. else
  8314. {
  8315. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8316. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8317. }
  8318. }
  8319. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8320. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8321. }
  8322. else
  8323. {
  8324. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8325. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8326. }
  8327. json_object_put(data);
  8328. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8329. json_object_put(response);
  8330. }
  8331. else
  8332. {
  8333. // Can not find valid message id
  8334. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8335. }
  8336. }
  8337. else
  8338. {
  8339. // Payload is null
  8340. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8341. }
  8342. LWS_Send(message);
  8343. return result;
  8344. }
  8345. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8346. {
  8347. mtrace();
  8348. int result = FAIL;
  8349. int connectorIdInt, durationInt;
  8350. char chargingRateUnitStr[4]={0};
  8351. char comfirmstr[20];
  8352. int confirmPeriods = 0;
  8353. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8354. json_object *GetCompositeSchedule;
  8355. GetCompositeSchedule = json_tokener_parse(payload);
  8356. if(!is_error(GetCompositeSchedule))
  8357. {
  8358. // Required data
  8359. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8360. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8361. else
  8362. connectorIdInt = -1;
  8363. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8364. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8365. else
  8366. durationInt = 86400;
  8367. // Optional data
  8368. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8369. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8370. }
  8371. json_object_put(GetCompositeSchedule);
  8372. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8373. if((connectorIdInt == 0) ||
  8374. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8375. {
  8376. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8377. struct StructChargingProfile tmpProfile[1];
  8378. if(strstr(chargingRateUnitStr, "W") != NULL)
  8379. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8380. else
  8381. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8382. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8383. {
  8384. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8385. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8386. }
  8387. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8388. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8389. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8390. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8391. {
  8392. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8393. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8394. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8395. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8396. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8397. {
  8398. confirmPeriods = idx;
  8399. break;
  8400. }
  8401. }
  8402. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8403. {
  8404. confirmPeriods += 1;
  8405. }
  8406. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8407. }
  8408. else
  8409. {
  8410. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8411. }
  8412. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8413. return result;
  8414. }
  8415. int handleGetConfigurationRequest(char *uuid, char *payload)
  8416. {
  8417. mtrace();
  8418. int result = FAIL;
  8419. int MaxKeySupported = 0;
  8420. int n_keys = 0;
  8421. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8422. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8423. json_object *GetConfiguration;
  8424. GetConfiguration = json_tokener_parse(payload);
  8425. if(!is_error(GetConfiguration))
  8426. {
  8427. // Optional data
  8428. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8429. {
  8430. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8431. {
  8432. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8433. n_keys = idx + 1;
  8434. }
  8435. }
  8436. }
  8437. json_object_put(GetConfiguration);
  8438. UnknownKeynum = 0;
  8439. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8440. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8441. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8442. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8443. if(n_keys != 0)
  8444. {
  8445. for(int i=0;i<n_keys;i++)
  8446. {
  8447. getKeyValue(requestKey[i]);
  8448. }
  8449. }
  8450. else
  8451. {
  8452. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8453. getKeyValue("");
  8454. }
  8455. processUnkownKey();
  8456. sendGetConfigurationConfirmation(uuid);
  8457. return result;
  8458. }
  8459. static char fnamePlusPath[100]={0};
  8460. static char fnamePWithNoPath[60]={0};
  8461. void checkUploadLog(void)
  8462. {
  8463. FILE *fp;
  8464. /* Open the command for reading. */
  8465. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8466. if (fp == NULL) {
  8467. DEBUG_WARN("Failed to run command\n" );
  8468. exit(1);
  8469. }
  8470. int ftppathlen = 0;
  8471. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8472. int i = 0;
  8473. /* Read the output a line at a time - output it. */
  8474. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8475. if(i==0)
  8476. {
  8477. ftppathlen = strlen(fnamePlusPath);
  8478. DEBUG_INFO("%s\n", fnamePlusPath);
  8479. fnamePlusPath[ftppathlen]='\0';
  8480. break;
  8481. }
  8482. i= i+1;
  8483. }
  8484. /* close */
  8485. pclose(fp);
  8486. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8487. {
  8488. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8489. {
  8490. fnamePlusPath[k]='\0';
  8491. }
  8492. }
  8493. i=1;
  8494. //char fname[60]={0};
  8495. while(i < ftppathlen)
  8496. {
  8497. int len=ftppathlen-i;
  8498. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8499. {
  8500. DEBUG_INFO("compare '/' all right\n");
  8501. break;
  8502. }
  8503. i=i+1;
  8504. }
  8505. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8506. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8507. fnamePWithNoPath[i+1] = '\0';
  8508. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8509. {
  8510. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8511. {
  8512. fnamePWithNoPath[j]='\0';
  8513. }
  8514. }
  8515. FILE* fp1 = fopen(fnamePlusPath, "r");
  8516. if (fp1)
  8517. {
  8518. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8519. // file exists
  8520. fclose(fp1);
  8521. }
  8522. else
  8523. {
  8524. // file doesn't exist
  8525. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8526. }
  8527. }
  8528. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8529. {
  8530. mtrace();
  8531. int result = FAIL;
  8532. time_t CurrentTime;
  8533. struct tm *tm;
  8534. pthread_t th_Status;
  8535. CurrentTime = time(NULL);
  8536. tm = localtime(&CurrentTime);
  8537. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  8538. sprintf((char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  8539. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8540. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8541. return result;
  8542. }
  8543. void* GetDiagnosticsProcess(void* data)
  8544. {
  8545. pthread_detach(pthread_self());
  8546. mtrace();
  8547. int retriesInt=0, retryIntervalInt=0;
  8548. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8549. char protocol[10]={0}, user[64]={0},password[128]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  8550. int port=0;
  8551. int isSuccess = FALSE;
  8552. char ftpbuf[200]={0};
  8553. char cmdBuf[2048];
  8554. struct tm *tmNow;
  8555. time_t CurrentTime;
  8556. struct tm tmStart;
  8557. struct tm tmStop;
  8558. CurrentTime = time(NULL);
  8559. tmNow=localtime(&CurrentTime);
  8560. uint16_t targetYear, targetMonth;
  8561. json_object *GetDiagnostics;
  8562. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8563. GetDiagnostics = json_tokener_parse(data);
  8564. if(!is_error(GetDiagnostics))
  8565. {
  8566. // Required data
  8567. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8568. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8569. // Optional data
  8570. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8571. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8572. else
  8573. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8574. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8575. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8576. else
  8577. retryIntervalInt = 30;
  8578. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8579. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8580. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8581. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8582. }
  8583. json_object_put(GetDiagnostics);
  8584. // Pack log to compress file
  8585. 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) &&
  8586. (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))
  8587. {
  8588. // Pack system log
  8589. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8590. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8591. targetYear = tmStart.tm_year;
  8592. targetMonth = tmStart.tm_mon;
  8593. do
  8594. {
  8595. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8596. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8597. if(targetMonth+1>=13)
  8598. {
  8599. targetYear += 1;
  8600. targetMonth = 1;
  8601. }
  8602. else
  8603. {
  8604. targetMonth += 1;
  8605. }
  8606. }while((targetYear < (tmNow->tm_year+1900)) ||
  8607. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8608. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8609. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8610. system(cmdBuf);
  8611. // Pack charging & event log
  8612. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8613. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8614. targetYear = tmStart.tm_year;
  8615. targetMonth = tmStart.tm_mon;
  8616. do
  8617. {
  8618. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8619. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8620. if(targetMonth+1>=13)
  8621. {
  8622. targetYear += 1;
  8623. targetMonth = 1;
  8624. }
  8625. else
  8626. {
  8627. targetMonth += 1;
  8628. }
  8629. }while((targetYear < (tmNow->tm_year+1900)) ||
  8630. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8631. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8632. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8633. system(cmdBuf);
  8634. // Combine log file
  8635. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8636. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8637. }
  8638. else
  8639. {
  8640. system("exec /root/logPackTools 'log' 6");
  8641. }
  8642. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8643. system(cmdBuf);
  8644. checkUploadLog();
  8645. //****************location*******************/
  8646. if(strcmp(locationstr,"")==0)
  8647. {
  8648. DEBUG_INFO("location is <Empty>!\n");
  8649. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8650. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8651. goto end;
  8652. }
  8653. memset(protocol, 0, ARRAY_SIZE(protocol));
  8654. memset(user, 0, ARRAY_SIZE(user) );
  8655. memset(password, 0, ARRAY_SIZE(password));
  8656. memset(host, 0, ARRAY_SIZE(host));
  8657. memset(path, 0, ARRAY_SIZE(path));
  8658. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8659. memset(host1, 0, ARRAY_SIZE(host1));
  8660. memset(path1, 0, ARRAY_SIZE(path1));
  8661. /*location: ftp://user:password@host:port/path*/
  8662. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8663. if((access(fnamePlusPath,F_OK))!=-1)
  8664. {
  8665. DEBUG_INFO("fnamePlusPath exist.\n");
  8666. }
  8667. else
  8668. {
  8669. DEBUG_INFO("fnamePlusPath not exist!\n");
  8670. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8671. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8672. goto end;
  8673. }
  8674. if(strchr(locationstr,'@')==NULL)
  8675. {
  8676. sscanf(locationstr,
  8677. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8678. protocol, host, &port, path);
  8679. strcpy(user,"anonymous");
  8680. strcpy(password,"");
  8681. }
  8682. else
  8683. {
  8684. //DEBUG_INFO("pch=%s\n", pch);
  8685. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8686. protocol, user, password, host, &port, path);
  8687. }
  8688. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8689. {
  8690. DEBUG_INFO("protocol is not ftp/http ! \n");
  8691. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8692. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8693. goto end;
  8694. }
  8695. if(strncmp(locationstr,"http", 4) == 0)
  8696. {
  8697. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8698. sprintf(ftppath,"/%s", path);
  8699. do
  8700. {
  8701. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8702. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8703. sleep(3);
  8704. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8705. if(!isSuccess)
  8706. {
  8707. DEBUG_INFO("Diagnostics fail.\n");
  8708. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8709. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8710. sleep(retryIntervalInt);
  8711. }
  8712. else
  8713. {
  8714. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8715. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8716. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8717. }
  8718. retriesInt--;
  8719. }while((isSuccess == 0)&&(retriesInt >= 0));
  8720. }
  8721. else
  8722. {
  8723. sscanf(host,"%[^/]%s",host1, path1);
  8724. if(strlen(path) > 0)
  8725. sprintf(ftppath,"/%s", path);
  8726. else
  8727. sprintf(ftppath,"/%s", path1);
  8728. int ftppathlen=strlen(ftppath);
  8729. int i=1;
  8730. char filenametemp[50];
  8731. while(i < ftppathlen)
  8732. {
  8733. int len=ftppathlen-i;
  8734. if(ftppath[len]== 47) // '/' ascll code: 47
  8735. {
  8736. DEBUG_INFO("find '/' all right\n");
  8737. break;
  8738. }
  8739. i=i+1;
  8740. }
  8741. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8742. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8743. filenametemp[i+1] = 0;
  8744. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  8745. if(port == 0)
  8746. port = 21;
  8747. do
  8748. {
  8749. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8750. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8751. sleep(3);
  8752. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8753. if(!isSuccess)
  8754. {
  8755. DEBUG_INFO("Diagnostics fail.\n");
  8756. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8757. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8758. sleep(retryIntervalInt);
  8759. }
  8760. else
  8761. {
  8762. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8763. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8764. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8765. }
  8766. retriesInt--;
  8767. }while((!isSuccess)&&(retriesInt >= 0));
  8768. }
  8769. end:
  8770. system("rm -f /mnt/*");
  8771. sleep(5);
  8772. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8773. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8774. pthread_exit(NULL);
  8775. }
  8776. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8777. {
  8778. mtrace();
  8779. int result = FAIL;
  8780. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8781. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8782. {
  8783. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8784. locallistVersion = -1;
  8785. }
  8786. else
  8787. {
  8788. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8789. OCPP_getListVerion();
  8790. }
  8791. //from db.OCPP_getListVerion
  8792. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  8793. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  8794. sendGetLocalListVersionConfirmation(uuid,"");
  8795. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  8796. return result;
  8797. }
  8798. int handleRemoteStartRequest(char *uuid, char *payload)
  8799. {
  8800. mtrace();
  8801. int result = FAIL;
  8802. int connectorIdInt=0;
  8803. int tempIndex = 0;
  8804. int connectorIdIsNULL, chargingProfileIsNULL;
  8805. char comfirmstr[20]={0};
  8806. char cmdBuf[512];
  8807. json_object *RemoteStartTransaction;
  8808. FILE *fp;
  8809. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8810. if(server_pending == TRUE)
  8811. {
  8812. return 0;
  8813. }
  8814. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8815. RemoteStartTransaction = json_tokener_parse(payload);
  8816. if(!is_error(RemoteStartTransaction))
  8817. {
  8818. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8819. {
  8820. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8821. if(connectorIdInt <= gunTotalNumber)
  8822. {
  8823. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8824. // Required data
  8825. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8826. // Optional data
  8827. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8828. {
  8829. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8830. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8831. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8832. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8833. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8834. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8835. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8836. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8837. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8838. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8839. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8840. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8841. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8842. {
  8843. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  8844. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8845. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  8846. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8847. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  8848. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8849. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  8850. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8851. {
  8852. 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++)
  8853. {
  8854. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  8855. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  8856. 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)
  8857. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  8858. }
  8859. }
  8860. }
  8861. }
  8862. else
  8863. chargingProfileIsNULL = TRUE;
  8864. }
  8865. }
  8866. else
  8867. connectorIdIsNULL = TRUE;
  8868. }
  8869. else
  8870. connectorIdIsNULL = TRUE;
  8871. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8872. {
  8873. DEBUG_WARN("Connector id is NULL\n.");
  8874. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8875. goto end;
  8876. }
  8877. /*
  8878. enum _SYSTEM_STATUS
  8879. {
  8880. S_BOOTING = 0,
  8881. S_IDLE, = 1
  8882. S_AUTHORIZING, = 2
  8883. S_REASSIGN_CHECK, = 3
  8884. S_REASSIGN, = 4
  8885. S_PRECHARGE, = 5
  8886. S_PREPARING_FOR_EV, = 6
  8887. S_PREPARING_FOR_EVSE, = 7
  8888. S_CHARGING, = 8
  8889. S_TERMINATING, = 9
  8890. S_COMPLETE, = 10
  8891. S_ALARM, = 11
  8892. S_FAULT = 12
  8893. }
  8894. */
  8895. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8896. {
  8897. //check Transaction active
  8898. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8899. {
  8900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8901. {
  8902. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8903. }
  8904. else
  8905. {
  8906. tempIndex = connectorIdInt -1;
  8907. }
  8908. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8909. {
  8910. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8911. {
  8912. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8913. {
  8914. //Reserved
  8915. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8916. }
  8917. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8918. {
  8919. //Reserved
  8920. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8921. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8922. goto end;
  8923. }
  8924. else
  8925. {
  8926. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8927. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8928. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8929. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8930. {
  8931. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8932. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8933. goto end;
  8934. }
  8935. }//END FOR ELSE
  8936. }
  8937. }// END FOR CHAdeMO_QUANTITY
  8938. }
  8939. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8940. {
  8941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8942. {
  8943. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8944. }
  8945. else
  8946. {
  8947. tempIndex = connectorIdInt -1;
  8948. }
  8949. for (int index = 0; index < CCS_QUANTITY; index++)
  8950. {
  8951. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8952. {
  8953. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8954. {
  8955. //Reserved
  8956. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8957. }
  8958. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8959. {
  8960. //Reserved
  8961. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8962. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8963. goto end;
  8964. }
  8965. else
  8966. {
  8967. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8968. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8969. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8970. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8971. {
  8972. DEBUG_WARN("CCS connector not allow start\n.");
  8973. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8974. goto end;
  8975. }
  8976. }// END FOR ELSE
  8977. }
  8978. }// END FOR CCS_QUANTITY
  8979. }
  8980. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8981. {
  8982. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8983. {
  8984. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8985. }
  8986. else
  8987. {
  8988. tempIndex = connectorIdInt -1;
  8989. }
  8990. for (int index = 0; index < GB_QUANTITY; index++)
  8991. {
  8992. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8993. {
  8994. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8995. {
  8996. //Reserved
  8997. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8998. }
  8999. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9000. {
  9001. //Reserved
  9002. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9003. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9004. goto end;
  9005. }
  9006. else
  9007. {
  9008. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9009. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9010. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9011. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9012. {
  9013. DEBUG_WARN("GB connector not allow start\n.");
  9014. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9015. goto end;
  9016. }
  9017. }// END FOR ELSE
  9018. }
  9019. } // END FOR GB_QUANTITY
  9020. }
  9021. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9022. {
  9023. tempIndex = connectorIdInt -1;
  9024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9025. {
  9026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9027. {
  9028. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9029. {
  9030. //Reserved
  9031. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9032. }
  9033. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9034. {
  9035. //Reserved
  9036. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9037. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9038. goto end;
  9039. }
  9040. else
  9041. {
  9042. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9043. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9044. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9045. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9046. {
  9047. DEBUG_WARN("GB connector not allow start\n.");
  9048. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9049. goto end;
  9050. }
  9051. }// END FOR ELSE
  9052. }
  9053. } // END FOR GB_QUANTITY
  9054. }
  9055. else
  9056. {
  9057. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9058. {
  9059. tempIndex = 2;
  9060. }
  9061. else
  9062. {
  9063. tempIndex = connectorIdInt -1;
  9064. }
  9065. for (int index = 0; index < AC_QUANTITY; index++)
  9066. {
  9067. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9068. {
  9069. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9070. {
  9071. //Reserved
  9072. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9073. }
  9074. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9075. {
  9076. //Reserved
  9077. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9078. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9079. goto end;
  9080. }
  9081. else
  9082. {
  9083. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9084. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9085. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9086. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9087. {
  9088. DEBUG_WARN("AC connector not allow start\n.");
  9089. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9090. goto end;
  9091. }
  9092. }//END FOR ELSE
  9093. }
  9094. }// END FOR AC_QUANTITY
  9095. }
  9096. if(chargingProfileIsNULL == FALSE)
  9097. {
  9098. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9099. {
  9100. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9101. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9102. //memset idTag
  9103. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9104. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9105. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9106. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9107. // Save profile to file
  9108. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9109. system(cmdBuf);
  9110. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9111. fp = fopen(cmdBuf, "w");
  9112. 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));
  9113. fclose(fp);
  9114. }
  9115. else
  9116. {
  9117. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9118. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9119. }
  9120. }
  9121. else
  9122. {
  9123. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9124. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9125. //memset idTag
  9126. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9127. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9128. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9129. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9130. }
  9131. }
  9132. else
  9133. {
  9134. DEBUG_WARN("Connector id over\n.");
  9135. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9136. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9137. }
  9138. end:
  9139. json_object_put(RemoteStartTransaction);
  9140. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9141. {
  9142. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9143. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9144. }
  9145. //OCPP send RemoteStartConfirmation by first.
  9146. sendRemoteStartConfirmation(uuid, comfirmstr);
  9147. return result;
  9148. }
  9149. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9150. {
  9151. mtrace();
  9152. int result = FAIL;
  9153. int match = FALSE;
  9154. int GunNO = 0;
  9155. int tempIndex = 0;
  9156. int transactionIdInt=0;
  9157. int transactionIdIsNULL= TRUE;
  9158. char comfirmstr[20];
  9159. json_object *RemoteStopTransaction;
  9160. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9161. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9162. if(server_pending == TRUE)
  9163. {
  9164. return 0;
  9165. }
  9166. RemoteStopTransaction = json_tokener_parse(payload);
  9167. if(!is_error(RemoteStopTransaction))
  9168. {
  9169. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9170. {
  9171. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9172. transactionIdIsNULL = FALSE;
  9173. }
  9174. }
  9175. json_object_put(RemoteStopTransaction);
  9176. if(transactionIdIsNULL == FALSE)
  9177. {
  9178. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9179. {
  9180. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9181. {
  9182. //check Transaction active
  9183. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9184. {
  9185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9186. {
  9187. tempIndex = ((gun_index==2) ? 1: 0);
  9188. }
  9189. else
  9190. {
  9191. tempIndex = gun_index;
  9192. }
  9193. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9194. {
  9195. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9196. {
  9197. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9198. {
  9199. match = TRUE;
  9200. GunNO = gun_index;
  9201. }
  9202. }
  9203. }// END FOR CHAdeMO_QUANTITY
  9204. }
  9205. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9206. {
  9207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9208. {
  9209. tempIndex = ((gun_index==2) ? 1: 0);
  9210. }
  9211. else
  9212. {
  9213. tempIndex = gun_index;
  9214. }
  9215. for (int index = 0; index < CCS_QUANTITY; index++)
  9216. {
  9217. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9218. {
  9219. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9220. {
  9221. match = TRUE;
  9222. GunNO = gun_index;
  9223. }
  9224. }
  9225. }// END FOR CCS_QUANTITY
  9226. }
  9227. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9228. {
  9229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9230. {
  9231. tempIndex = ((gun_index==2) ? 1: 0);
  9232. }
  9233. else
  9234. {
  9235. tempIndex = gun_index;
  9236. }
  9237. for (int index = 0; index < GB_QUANTITY; index++)
  9238. {
  9239. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9240. {
  9241. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9242. {
  9243. match = TRUE;
  9244. GunNO = gun_index;
  9245. }
  9246. }
  9247. }// END FOR GB_QUANTITY
  9248. }
  9249. else if(gunType[gun_index] == GUN_TYPE_DO)
  9250. {
  9251. tempIndex = gun_index;
  9252. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9253. {
  9254. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9255. {
  9256. 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
  9257. {
  9258. match = TRUE;
  9259. GunNO = gun_index;
  9260. }
  9261. }
  9262. }// END FOR GB_QUANTITY
  9263. }
  9264. else
  9265. {
  9266. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9267. {
  9268. tempIndex = 2;
  9269. }
  9270. else
  9271. {
  9272. tempIndex = gun_index;
  9273. }
  9274. for (int index = 0; index < AC_QUANTITY; index++)
  9275. {
  9276. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9277. {
  9278. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9279. {
  9280. match = TRUE;
  9281. GunNO = gun_index;
  9282. }
  9283. }
  9284. }// END FOR CHAdeMO_QUANTITY
  9285. } // END FOR AC ELSE
  9286. }// CHECK IF ResponseTransactionId == transactionIdInt
  9287. }//END FOR
  9288. if( match == TRUE)
  9289. {
  9290. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9291. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9292. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9293. }
  9294. else
  9295. {
  9296. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9297. }
  9298. }
  9299. else
  9300. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9301. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9302. return result;
  9303. }
  9304. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9305. {
  9306. mtrace();
  9307. int result = FAIL;
  9308. int connectorIdInt=0, reservationIdInt=0;
  9309. int tempIndex = 0;
  9310. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9311. char comfirmstr[20]={0};
  9312. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9313. int c = 0;
  9314. char *loc;
  9315. //char *ptr;
  9316. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9317. strcpy(sstrtemp, stringtrimspace(payload));
  9318. //***(1)connectorId ****/
  9319. c=0;
  9320. loc = strstr(sstrtemp, "connectorId");
  9321. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9322. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9323. {
  9324. sstr[c] = loc[strlen("connectorId")+2+c];
  9325. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9326. c++;
  9327. }
  9328. sstr[c] = '\0';
  9329. connectorIdInt = atoi(sstr);
  9330. //***(2)expiryDate ****/
  9331. loc = strstr(sstrtemp, "expiryDate");
  9332. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9333. c = 0;
  9334. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9335. {
  9336. sstr[c] = loc[3+strlen("expiryDate")+c];
  9337. c++;
  9338. }
  9339. sstr[c] = '\0';
  9340. strcpy(expiryDatestr, sstr);
  9341. //***(3)idTag ****/
  9342. loc = strstr(sstrtemp, "idTag");
  9343. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9344. c = 0;
  9345. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9346. {
  9347. sstr[c] = loc[3+strlen("idTag")+c];
  9348. c++;
  9349. }
  9350. sstr[c] = '\0';
  9351. strcpy(idTagstr, sstr);
  9352. //***(4)parentIdTag ****/
  9353. loc = strstr(sstrtemp, "parentIdTag");
  9354. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9355. c = 0;
  9356. if(loc == NULL)
  9357. {
  9358. strcpy(parentIdTagstr, "");
  9359. }
  9360. else
  9361. {
  9362. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9363. {
  9364. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9365. c++;
  9366. }
  9367. sstr[c] = '\0';
  9368. strcpy(parentIdTagstr, sstr);
  9369. }
  9370. //***(5)reservationId ****/
  9371. c=0;
  9372. loc = strstr(sstrtemp, "reservationId");
  9373. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9374. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9375. {
  9376. sstr[c] = loc[strlen("reservationId")+2+c];
  9377. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9378. c++;
  9379. }
  9380. sstr[c] = '\0';
  9381. reservationIdInt = atoi(sstr);
  9382. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9383. /*
  9384. enum SYSTEM_STATUS
  9385. {
  9386. SYS_MODE_BOOTING = 0,
  9387. SYS_MODE_IDLE = 1,
  9388. SYS_MODE_AUTHORIZING = 2,
  9389. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9390. SYS_MODE_REASSIGN = 4,
  9391. SYS_MODE_PREPARING = 5,
  9392. SYS_MODE_PREPARE_FOR_EV = 6,
  9393. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9394. SYS_MODE_CHARGING = 8,
  9395. SYS_MODE_TERMINATING = 9,
  9396. SYS_MODE_COMPLETE = 10,
  9397. SYS_MODE_ALARM = 11,
  9398. SYS_MODE_FAULT = 12,
  9399. SYS_MODE_RESERVATION = 13,
  9400. SYS_MODE_BOOKING = 14,
  9401. SYS_MODE_MAINTAIN = 15,
  9402. SYS_MODE_DEBUG = 16,
  9403. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9404. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9405. SYS_MODE_UPDATE = 19
  9406. };
  9407. */
  9408. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9409. {
  9410. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9411. goto end;
  9412. }
  9413. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9414. {
  9415. //check Transaction active
  9416. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9417. {
  9418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9419. {
  9420. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9421. }
  9422. else
  9423. {
  9424. tempIndex = connectorIdInt -1;
  9425. }
  9426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9427. {
  9428. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9429. {
  9430. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9431. {
  9432. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9433. {
  9434. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9435. {
  9436. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9438. }
  9439. 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'))
  9440. {
  9441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9442. }
  9443. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9444. {
  9445. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9446. }
  9447. else
  9448. {
  9449. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9450. }
  9451. }
  9452. 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
  9453. {
  9454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9455. }
  9456. }
  9457. else
  9458. {
  9459. //replace reservation
  9460. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9461. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9462. }
  9463. }
  9464. } // END FOR CHAdeMO_QUANTITY
  9465. }
  9466. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9467. {
  9468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9469. {
  9470. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9471. }
  9472. else
  9473. {
  9474. tempIndex = connectorIdInt -1;
  9475. }
  9476. for (int index = 0; index < CCS_QUANTITY; index++)
  9477. {
  9478. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9479. {
  9480. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9481. {
  9482. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9483. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9484. {
  9485. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9486. {
  9487. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9488. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9489. }
  9490. 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'))
  9491. {
  9492. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9493. }
  9494. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9495. {
  9496. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9497. }
  9498. else
  9499. {
  9500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9501. }
  9502. }
  9503. 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
  9504. {
  9505. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9506. }
  9507. }
  9508. else
  9509. {
  9510. //replace reservation
  9511. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9512. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9513. }
  9514. }
  9515. } // END FOR CCS_QUANTITY
  9516. }
  9517. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9518. {
  9519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9520. {
  9521. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9522. }
  9523. else
  9524. {
  9525. tempIndex = connectorIdInt -1;
  9526. }
  9527. for (int index = 0; index < GB_QUANTITY; index++)
  9528. {
  9529. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9530. {
  9531. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9532. {
  9533. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9534. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9535. {
  9536. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9537. {
  9538. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9539. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9540. }
  9541. 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'))
  9542. {
  9543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9544. }
  9545. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9546. {
  9547. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9548. }
  9549. else
  9550. {
  9551. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9552. }
  9553. }
  9554. 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
  9555. {
  9556. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9557. }
  9558. }
  9559. else
  9560. {
  9561. //replace reservation
  9562. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9563. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9564. }
  9565. }
  9566. }// END FOR GB_QUANTITY
  9567. }
  9568. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9569. {
  9570. tempIndex = connectorIdInt -1;
  9571. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9572. {
  9573. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9574. {
  9575. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9576. {
  9577. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9578. 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
  9579. {
  9580. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9581. {
  9582. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9583. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9584. }
  9585. 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'))
  9586. {
  9587. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9588. }
  9589. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9590. {
  9591. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9592. }
  9593. else
  9594. {
  9595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9596. }
  9597. }
  9598. 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
  9599. {
  9600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9601. }
  9602. }
  9603. else
  9604. {
  9605. //replace reservation
  9606. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9608. }
  9609. }
  9610. }// END FOR GB_QUANTITY
  9611. }
  9612. else
  9613. {
  9614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9615. {
  9616. tempIndex = 2;
  9617. }
  9618. else
  9619. {
  9620. tempIndex = (connectorIdInt -1);
  9621. }
  9622. for (int index = 0; index < AC_QUANTITY; index++)
  9623. {
  9624. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9625. {
  9626. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9627. {
  9628. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9629. {
  9630. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9631. {
  9632. 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))
  9633. {
  9634. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9635. }
  9636. else
  9637. {
  9638. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9640. }
  9641. }
  9642. 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'))
  9643. {
  9644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9645. }
  9646. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9647. {
  9648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9649. }
  9650. else
  9651. {
  9652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9653. }
  9654. }
  9655. 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
  9656. {
  9657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9658. }
  9659. }
  9660. else
  9661. {
  9662. //replace reservation
  9663. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9665. }
  9666. }
  9667. } // END FOR AC_QUANTITY
  9668. }
  9669. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9670. }
  9671. else if(connectorIdInt == 0)
  9672. {
  9673. //check Transaction active
  9674. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9675. {
  9676. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9677. {
  9678. 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'))
  9679. {
  9680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9681. goto end;
  9682. }
  9683. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9684. {
  9685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9686. goto end;
  9687. }
  9688. 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
  9689. {
  9690. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9691. goto end;
  9692. }
  9693. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9694. {
  9695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9696. goto end;
  9697. }
  9698. }
  9699. }// END FOR CHAdeMO_QUANTITY
  9700. for (int index = 0; index < CCS_QUANTITY; index++)
  9701. {
  9702. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9703. {
  9704. 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'))
  9705. {
  9706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9707. goto end;
  9708. }
  9709. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9710. {
  9711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9712. goto end;
  9713. }
  9714. 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
  9715. {
  9716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9717. goto end;
  9718. }
  9719. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9720. {
  9721. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9722. goto end;
  9723. }
  9724. }
  9725. } // END FOR CCS_QUANTITY
  9726. for (int index = 0; index < GB_QUANTITY; index++)
  9727. {
  9728. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9729. {
  9730. 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'))
  9731. {
  9732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9733. goto end;
  9734. }
  9735. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9736. {
  9737. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9738. goto end;
  9739. }
  9740. 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
  9741. {
  9742. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9743. goto end;
  9744. }
  9745. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9746. {
  9747. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9748. goto end;
  9749. }
  9750. }
  9751. } // END FOR GB_QUANTITY
  9752. for (int index = 0; index < AC_QUANTITY; index++)
  9753. {
  9754. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9755. {
  9756. 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'))
  9757. {
  9758. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9759. goto end;
  9760. }
  9761. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9762. {
  9763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9764. goto end;
  9765. }
  9766. 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
  9767. {
  9768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9769. goto end;
  9770. }
  9771. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9772. {
  9773. 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))
  9774. {
  9775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9776. goto end;
  9777. }
  9778. }
  9779. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9780. {
  9781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9782. goto end;
  9783. }
  9784. }
  9785. }// END FOR AC_QUANTITY
  9786. //The connectorId is 0
  9787. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  9788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9789. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9790. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  9791. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9792. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  9793. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9794. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  9795. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  9796. result = TRUE;
  9797. return result;
  9798. }
  9799. else
  9800. {
  9801. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9802. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9803. }
  9804. if(strcmp(comfirmstr,"Accepted") == 0)
  9805. {
  9806. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9807. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9808. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9809. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9810. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9811. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  9812. result = TRUE;
  9813. return result;
  9814. }
  9815. end:
  9816. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9817. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9818. return result;
  9819. }
  9820. int handleResetRequest(char *uuid, char *payload)
  9821. {
  9822. mtrace();
  9823. int result = FAIL;
  9824. char sstr[10]={0},sstrtemp[30]={ 0 };
  9825. char typestr[10]={0};
  9826. char comfirmstr[20]={0};
  9827. int c = 0;
  9828. char *loc;
  9829. DEBUG_INFO("handleResetRequest...\n");
  9830. strcpy(sstrtemp, stringtrimspace(payload));
  9831. loc = strstr(sstrtemp, "type");
  9832. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9833. c = 0;
  9834. while (loc[3+strlen("type")+c] != '\"')
  9835. {
  9836. sstr[c] = loc[3+strlen("type")+c];
  9837. c++;
  9838. }
  9839. sstr[c] = '\0';
  9840. strcpy(typestr,sstr);
  9841. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  9842. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9843. {
  9844. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  9845. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  9846. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9847. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9848. }
  9849. else
  9850. {
  9851. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9852. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9853. result = PASS;
  9854. }
  9855. sendResetConfirmation(uuid, comfirmstr);
  9856. return result;
  9857. }
  9858. int handleSendLocalListRequest(char *uuid, char *payload)
  9859. {
  9860. mtrace();
  9861. int result = FAIL;
  9862. char comfirmstr[20];
  9863. int checkState_Faulted = FALSE;
  9864. json_object *SendLocalList;
  9865. DEBUG_INFO("handleSendLocalListRequest...\n");
  9866. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9867. {
  9868. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9869. goto end;
  9870. }
  9871. //check Charge Point state
  9872. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9873. {
  9874. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9875. {
  9876. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9877. }
  9878. }
  9879. for (int index = 0; index < CCS_QUANTITY; index++)
  9880. {
  9881. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9882. {
  9883. checkState_Faulted = TRUE; //OCPP Status
  9884. }
  9885. }
  9886. for (int index = 0; index < GB_QUANTITY; index++)
  9887. {
  9888. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9889. {
  9890. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9891. }
  9892. }
  9893. //check Charge Point state
  9894. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9895. {
  9896. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9897. {
  9898. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9899. }
  9900. }
  9901. //check Charge Point state
  9902. for (int index = 0; index < AC_QUANTITY; index++)
  9903. {
  9904. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9905. {
  9906. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9907. }
  9908. }
  9909. if(checkState_Faulted == TRUE)
  9910. {
  9911. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9912. goto end;
  9913. }
  9914. // Parsing payload
  9915. SendLocalList = json_tokener_parse(payload);
  9916. if(!is_error(SendLocalList))
  9917. {
  9918. // Required data
  9919. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  9920. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  9921. // Optional data
  9922. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  9923. {
  9924. //Check UpdateType
  9925. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9926. {
  9927. //Local list full update
  9928. DEBUG_INFO("Local list full update.\n");
  9929. OCPP_getListVerion();
  9930. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  9931. {
  9932. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9933. goto end;
  9934. }
  9935. OCPP_cleanLocalList();
  9936. }
  9937. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9938. {
  9939. //Local list different update
  9940. DEBUG_INFO("Local list different update.\n");
  9941. OCPP_getListVerion();
  9942. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  9943. {
  9944. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9945. goto end;
  9946. }
  9947. }
  9948. else
  9949. {
  9950. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9951. goto end;
  9952. }
  9953. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9954. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  9955. {
  9956. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  9957. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  9958. {
  9959. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  9960. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  9961. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  9962. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  9963. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  9964. }
  9965. // Add to db
  9966. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9967. {
  9968. //Local list full update
  9969. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  9970. idx,
  9971. ShmOCPP16DataPH->SendLocalList.ListVersion,
  9972. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9973. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9974. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9975. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9976. // update list
  9977. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  9978. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9979. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9980. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9981. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9982. }
  9983. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9984. {
  9985. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  9986. idx,
  9987. ShmOCPP16DataPH->SendLocalList.ListVersion,
  9988. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9989. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9990. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9991. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9992. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  9993. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9994. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9995. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9996. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9997. }
  9998. }
  9999. }
  10000. else
  10001. {
  10002. //Check UpdateType
  10003. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10004. {
  10005. //Local list full update
  10006. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10007. OCPP_cleanLocalList();
  10008. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10009. goto end;
  10010. }
  10011. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10012. {
  10013. //Local list different update
  10014. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10015. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10016. goto end;
  10017. }
  10018. }
  10019. result = PASS;
  10020. }
  10021. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10022. end:
  10023. json_object_put(SendLocalList);
  10024. sendSendLocalListConfirmation(uuid, comfirmstr);
  10025. return result;
  10026. }
  10027. #define MAX 200
  10028. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10029. {
  10030. mtrace();
  10031. int result = FAIL;
  10032. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10033. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10034. char chargingProfilePurposeStr[30]={0};
  10035. char chargingProfileKindStr[16]={0};
  10036. char recurrencyKindStr[10]={0};
  10037. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10038. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10039. int chargingSchedulePeriodCount = 0;
  10040. char comfirmstr[20]={0};
  10041. int meet= FALSE;
  10042. FILE *fptr1;
  10043. char filename[MAX]={0};
  10044. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  10045. char rmFileCmd[50]={0};
  10046. char tempchargingProfilePurposeStr[30]={0};
  10047. char word[1600]={0};
  10048. int n_chargingProfile = 0;
  10049. json_object *SetChargingProfile;
  10050. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10051. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10052. SetChargingProfile = json_tokener_parse(payload);
  10053. if(!is_error(SetChargingProfile))
  10054. {
  10055. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10056. {
  10057. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10058. if(connectorIdInt == 0)
  10059. {
  10060. memset(&ShmOCPP16DataPH->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10061. ShmOCPP16DataPH->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10062. }
  10063. else
  10064. {
  10065. memset(&ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10066. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10067. }
  10068. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10069. }
  10070. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10071. {
  10072. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10073. {
  10074. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10075. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10076. {
  10077. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10078. }
  10079. else
  10080. {
  10081. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10082. }
  10083. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10084. }
  10085. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10086. {
  10087. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10088. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10089. {
  10090. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10091. }
  10092. else
  10093. {
  10094. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10095. }
  10096. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10097. }
  10098. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10099. {
  10100. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10101. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10102. {
  10103. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10104. }
  10105. else
  10106. {
  10107. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10108. }
  10109. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10110. }
  10111. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10112. {
  10113. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10114. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10115. {
  10116. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10117. }
  10118. else
  10119. {
  10120. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10121. }
  10122. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10123. }
  10124. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10125. {
  10126. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10127. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10128. {
  10129. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10130. }
  10131. else
  10132. {
  10133. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10134. }
  10135. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10136. }
  10137. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10138. {
  10139. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10140. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10141. {
  10142. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10143. }
  10144. else
  10145. {
  10146. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10147. }
  10148. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10149. }
  10150. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10151. {
  10152. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10153. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10154. {
  10155. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10156. }
  10157. else
  10158. {
  10159. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10160. }
  10161. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10162. }
  10163. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10164. {
  10165. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10166. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10167. {
  10168. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10169. }
  10170. else
  10171. {
  10172. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10173. }
  10174. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10175. }
  10176. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10177. {
  10178. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10179. {
  10180. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10181. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10182. {
  10183. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10184. }
  10185. else
  10186. {
  10187. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10188. }
  10189. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10190. }
  10191. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10192. {
  10193. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10194. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10195. {
  10196. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10197. }
  10198. else
  10199. {
  10200. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10201. }
  10202. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10203. }
  10204. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10205. {
  10206. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10207. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10208. {
  10209. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10210. }
  10211. else
  10212. {
  10213. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10214. }
  10215. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10216. }
  10217. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10218. {
  10219. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10220. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10221. {
  10222. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10223. }
  10224. else
  10225. {
  10226. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10227. }
  10228. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10229. }
  10230. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10231. {
  10232. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10233. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10234. if(chargingSchedulePeriodCount <= 10)
  10235. {
  10236. 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++)
  10237. {
  10238. 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)
  10239. {
  10240. 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"));
  10241. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10242. {
  10243. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10244. }
  10245. else
  10246. {
  10247. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10248. }
  10249. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10250. }
  10251. 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)
  10252. {
  10253. 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"));
  10254. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10255. {
  10256. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10257. }
  10258. else
  10259. {
  10260. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10261. }
  10262. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10263. }
  10264. 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)
  10265. {
  10266. 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"));
  10267. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10268. {
  10269. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10270. }
  10271. else
  10272. {
  10273. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10274. }
  10275. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10276. }
  10277. }
  10278. }
  10279. }
  10280. }
  10281. }
  10282. }
  10283. json_object_put(SetChargingProfile);
  10284. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10285. {
  10286. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10287. goto end;
  10288. }
  10289. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10290. {
  10291. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10292. if(connectorIdInt != 0)
  10293. {
  10294. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10295. goto end;
  10296. }
  10297. strcpy(filename, ChargePointMaxProfile_JSON );
  10298. fptr1 = fopen(filename, "r");
  10299. if (!fptr1)
  10300. {
  10301. //file not exist
  10302. DEBUG_INFO("Unable to open the input file!!\n");
  10303. fptr1 = fopen(filename, "w+");
  10304. }
  10305. else
  10306. {
  10307. //Check Charging Profile Count
  10308. while(fscanf(fptr1, "%s", word) != EOF)
  10309. {
  10310. //DEBUG_INFO("word=%s\n",word);
  10311. if(strstr(word, "chargingProfileId")!= NULL)
  10312. {
  10313. //DEBUG_INFO("test chargingProfileId \n");
  10314. n_chargingProfile = n_chargingProfile + 1;
  10315. //DEBUG_INFO("chargingProfileId Found\n");
  10316. }
  10317. }
  10318. }
  10319. fclose(fptr1);
  10320. }
  10321. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10322. {
  10323. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10324. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10325. {
  10326. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10327. goto end;
  10328. }
  10329. memset(filename, 0, ARRAY_SIZE(filename));
  10330. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  10331. fptr1 = fopen(filename, "r");
  10332. if (!fptr1)
  10333. {
  10334. //file not exist
  10335. //DEBUG_INFO("Unable to open the input file!!\n");
  10336. fptr1 = fopen(filename, "w+");
  10337. }
  10338. else
  10339. {
  10340. //Check Charging Profile Count
  10341. while(fscanf(fptr1, "%s", word) != EOF)
  10342. {
  10343. //DEBUG_INFO("word=%s\n",word);
  10344. if(strstr(word, "chargingProfileId")!= NULL)
  10345. {
  10346. //DEBUG_INFO("test chargingProfileId \n");
  10347. n_chargingProfile = n_chargingProfile + 1;
  10348. //DEBUG_INFO("chargingProfileId Found\n");
  10349. }
  10350. }
  10351. }
  10352. fclose(fptr1);
  10353. }
  10354. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10355. {
  10356. //printf("set chargingProfile 1-4\n");
  10357. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10358. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10359. if(connectorIdInt == 0)
  10360. {
  10361. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10362. goto end;
  10363. }
  10364. int tempIndex = 0;
  10365. //check Transaction active
  10366. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10367. {
  10368. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10369. {
  10370. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10371. }
  10372. else
  10373. {
  10374. tempIndex = connectorIdInt -1;
  10375. }
  10376. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10377. {
  10378. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10379. {
  10380. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10381. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10382. {
  10383. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10384. {
  10385. meet = TRUE;
  10386. break;
  10387. }
  10388. }
  10389. }
  10390. }
  10391. }
  10392. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10393. {
  10394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10395. {
  10396. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10397. }
  10398. else
  10399. {
  10400. tempIndex = connectorIdInt -1;
  10401. }
  10402. for (int index = 0; index < CCS_QUANTITY; index++)
  10403. {
  10404. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10405. {
  10406. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10407. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10408. {
  10409. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10410. {
  10411. meet = TRUE;
  10412. break;
  10413. }
  10414. }
  10415. }
  10416. }
  10417. }
  10418. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10419. {
  10420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10421. {
  10422. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10423. }
  10424. else
  10425. {
  10426. tempIndex = connectorIdInt -1;
  10427. }
  10428. for (int index = 0; index < GB_QUANTITY; index++)
  10429. {
  10430. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10431. {
  10432. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10433. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10434. {
  10435. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10436. {
  10437. meet = TRUE;
  10438. break;
  10439. }
  10440. }
  10441. }
  10442. }
  10443. }
  10444. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10445. {
  10446. tempIndex = connectorIdInt -1;
  10447. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10448. {
  10449. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10450. {
  10451. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10452. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10453. {
  10454. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10455. {
  10456. meet = TRUE;
  10457. break;
  10458. }
  10459. }
  10460. }
  10461. }
  10462. }
  10463. else
  10464. {
  10465. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10466. {
  10467. tempIndex = 2;
  10468. }
  10469. else
  10470. {
  10471. tempIndex = (connectorIdInt -1);
  10472. }
  10473. for (int index = 0; index < AC_QUANTITY; index++)
  10474. {
  10475. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10476. {
  10477. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10478. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10479. {
  10480. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10481. {
  10482. meet = TRUE;
  10483. break;
  10484. }
  10485. }
  10486. }
  10487. }
  10488. }
  10489. //check Transaction active
  10490. if(meet == FALSE)
  10491. {
  10492. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10493. goto end;
  10494. }
  10495. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10496. {
  10497. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10498. goto end;
  10499. }
  10500. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10501. fptr1 = fopen(filename, "r");
  10502. if (!fptr1)
  10503. {
  10504. //file not exist
  10505. DEBUG_INFO("Unable to open the input file!!\n");
  10506. fptr1 = fopen(filename, "w+");
  10507. }
  10508. else
  10509. {
  10510. //Check Charging Profile Count
  10511. while(fscanf(fptr1, "%s", word) != EOF)
  10512. {
  10513. //DEBUG_INFO("word=%s\n",word);
  10514. if(strstr(word, "chargingProfileId")!= NULL)
  10515. {
  10516. //DEBUG_INFO("test chargingProfileId \n");
  10517. n_chargingProfile = n_chargingProfile + 1;
  10518. //DEBUG_INFO("chargingProfileId Found\n");
  10519. }
  10520. }
  10521. }
  10522. fclose(fptr1);
  10523. }
  10524. // Check ChargeProfileMaxStackLevel
  10525. if(n_chargingProfile >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10526. {
  10527. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10528. goto end;
  10529. }
  10530. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10531. {
  10532. int i = 0;
  10533. char fnametemp[200]={0};
  10534. n_chargingProfile = 0;
  10535. //Check ChargePointMaxProfile.json exit
  10536. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  10537. {
  10538. fptr1 = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  10539. //Check Charging Profile Count
  10540. while(fscanf(fptr1, "%s", word) != EOF)
  10541. {
  10542. //DEBUG_INFO("word=%s\n",word);
  10543. if(strstr(word, "chargingProfileId")!= NULL)
  10544. {
  10545. //DEBUG_INFO("test chargingProfileId \n");
  10546. n_chargingProfile = n_chargingProfile + 1;
  10547. i = i + 1;
  10548. //DEBUG_INFO("chargingProfileId Found\n");
  10549. }
  10550. memset(word, 0, ARRAY_SIZE(word));
  10551. }
  10552. fclose(fptr1);
  10553. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10554. }
  10555. //Check TxDefaultProfile_0.json exit
  10556. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  10557. {
  10558. i = 0;
  10559. fptr1 = fopen("/Storage/OCPP_PH/TxDefaultProfile_0.json", "r");
  10560. //Check Charging Profile Count
  10561. while(fscanf(fptr1, "%s", word) != EOF)
  10562. {
  10563. //DEBUG_INFO("word=%s\n",word);
  10564. if(strstr(word, "chargingProfileId")!= NULL)
  10565. {
  10566. //DEBUG_INFO("test chargingProfileId \n");
  10567. n_chargingProfile = n_chargingProfile + 1;
  10568. i = i + 1;
  10569. //DEBUG_INFO("chargingProfileId Found\n");
  10570. }
  10571. memset(word, 0, ARRAY_SIZE(word));
  10572. }
  10573. fclose(fptr1);
  10574. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10575. }
  10576. //Check TxDefaultProfile_%d.json
  10577. for(int j=1; j <= gunTotalNumber; j++)
  10578. {
  10579. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10580. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  10581. if((access(fnametemp,F_OK))!=-1)
  10582. {
  10583. i = 0;
  10584. fptr1 = fopen(fnametemp, "r");
  10585. //Check Charging Profile Count
  10586. while(fscanf(fptr1, "%s", word) != EOF)
  10587. {
  10588. //DEBUG_INFO("word=%s\n",word);
  10589. if(strstr(word, "chargingProfileId")!= NULL)
  10590. {
  10591. //DEBUG_INFO("test chargingProfileId \n");
  10592. n_chargingProfile = n_chargingProfile + 1;
  10593. i = i + 1;
  10594. //DEBUG_INFO("chargingProfileId Found\n");
  10595. }
  10596. memset(word, 0, ARRAY_SIZE(word));
  10597. }
  10598. fclose(fptr1);
  10599. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10600. }
  10601. }
  10602. //Check TxProfile_%d.json
  10603. for(int j=1; j <= gunTotalNumber; j++)
  10604. {
  10605. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10606. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  10607. if((access(fnametemp,F_OK))!=-1)
  10608. {
  10609. i = 0;
  10610. fptr1 = fopen(fnametemp, "r");
  10611. //Check Charging Profile Count
  10612. while(fscanf(fptr1, "%s", word) != EOF)
  10613. {
  10614. //DEBUG_INFO("word=%s\n",word);
  10615. if(strstr(word, "chargingProfileId")!= NULL)
  10616. {
  10617. //DEBUG_INFO("test chargingProfileId \n");
  10618. n_chargingProfile = n_chargingProfile + 1;
  10619. i = i + 1;
  10620. //DEBUG_INFO("chargingProfileId Found\n");
  10621. }
  10622. memset(word, 0, ARRAY_SIZE(word));
  10623. }
  10624. fclose(fptr1);
  10625. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10626. }
  10627. }
  10628. if( n_chargingProfile > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10629. {
  10630. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10631. goto end;
  10632. }
  10633. }
  10634. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10635. //**********************************Write to File********************************************************/
  10636. FILE *infile;
  10637. FILE *outfile;
  10638. infile = fopen (filename, "r");
  10639. outfile = fopen (tempfile, "w");
  10640. int d =0;
  10641. d = fgetc(infile);
  10642. rewind(infile);
  10643. if(d == EOF)
  10644. {
  10645. // Profile is empty
  10646. fprintf(outfile,"%s\n",payload);
  10647. fclose(infile);
  10648. fclose(outfile);
  10649. sprintf(rmFileCmd,"rm -f %s",filename);
  10650. system(rmFileCmd);
  10651. rename(tempfile, filename);
  10652. }
  10653. else
  10654. {
  10655. // Profile is not empty
  10656. char buf[2048]={0};
  10657. int ChargingProfileAdded = FALSE;
  10658. while (fgets(buf, sizeof(buf), infile) != NULL)
  10659. {
  10660. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10661. json_object *tmpChargingProfile;
  10662. tmpChargingProfile = json_tokener_parse(buf);
  10663. if(!is_error(SetChargingProfile))
  10664. {
  10665. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10666. {
  10667. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10668. }
  10669. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10670. {
  10671. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10672. {
  10673. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10674. }
  10675. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10676. {
  10677. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10678. }
  10679. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10680. {
  10681. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10682. }
  10683. }
  10684. }
  10685. json_object_put(tmpChargingProfile);
  10686. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10687. {
  10688. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10689. {
  10690. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10691. if(ChargingProfileAdded == FALSE)
  10692. {
  10693. fprintf(outfile,"%s\n",payload);
  10694. ChargingProfileAdded = TRUE;
  10695. }
  10696. }
  10697. else
  10698. {
  10699. if(tempstackLevelInt < stackLevelInt)
  10700. {
  10701. if(ChargingProfileAdded == FALSE)
  10702. {
  10703. fprintf(outfile,"%s\n",buf);
  10704. fprintf(outfile,"%s\n",payload);
  10705. ChargingProfileAdded = TRUE;
  10706. }
  10707. else
  10708. {
  10709. fprintf(outfile,"%s\n",buf);
  10710. }
  10711. }
  10712. else
  10713. {
  10714. if(ChargingProfileAdded == FALSE)
  10715. {
  10716. fprintf(outfile,"%s\n",buf);
  10717. fprintf(outfile,"%s\n",payload);
  10718. ChargingProfileAdded = TRUE;
  10719. }
  10720. else
  10721. {
  10722. fprintf(outfile,"%s\n",buf);
  10723. }
  10724. }
  10725. }
  10726. }
  10727. else
  10728. {
  10729. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10730. {
  10731. if(ChargingProfileAdded == FALSE)
  10732. {
  10733. fprintf(outfile,"%s\n",buf);
  10734. fprintf(outfile,"%s\n",payload);
  10735. ChargingProfileAdded = TRUE;
  10736. }
  10737. else
  10738. {
  10739. fprintf(outfile,"%s\n",buf);
  10740. }
  10741. }
  10742. else if(tempstackLevelInt < stackLevelInt)
  10743. {
  10744. if(ChargingProfileAdded == FALSE)
  10745. {
  10746. fprintf(outfile,"%s\n",buf);
  10747. fprintf(outfile,"%s\n",payload);
  10748. ChargingProfileAdded = TRUE;
  10749. }
  10750. else
  10751. {
  10752. fprintf(outfile,"%s\n",buf);
  10753. }
  10754. }
  10755. else
  10756. {
  10757. if(ChargingProfileAdded == FALSE)
  10758. {
  10759. fprintf(outfile,"%s\n",buf);
  10760. fprintf(outfile,"%s\n",payload);
  10761. ChargingProfileAdded = TRUE;
  10762. }
  10763. else
  10764. {
  10765. fprintf(outfile,"%s\n",buf);
  10766. }
  10767. }
  10768. }
  10769. } // end of while loop
  10770. fclose(infile);
  10771. fclose(outfile);
  10772. sprintf(rmFileCmd,"rm -f %s",filename);
  10773. system(rmFileCmd);
  10774. rename(tempfile, filename);
  10775. }
  10776. sleep(1);
  10777. result = TRUE;
  10778. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10779. end:
  10780. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10781. {
  10782. if(connectorIdInt == 0)
  10783. {
  10784. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10785. {
  10786. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  10787. }
  10788. }
  10789. else
  10790. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  10791. }
  10792. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10793. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10794. return result;
  10795. }
  10796. int handleTriggerMessageRequest(char *uuid, char *payload)
  10797. {
  10798. mtrace();
  10799. int result = FAIL;
  10800. int connectorIdIsNULL = FALSE;
  10801. int connectorIdInt =0;
  10802. char sstr[40]={0},sstrtemp[100]={ 0 };
  10803. char requestedMessagestr[40]={0};
  10804. char comfirmstr[20]={0};
  10805. int c = 0;
  10806. char *loc;
  10807. DEBUG_INFO("handleTriggerMessageRequest\n");
  10808. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10809. strcpy(sstrtemp, stringtrimspace(payload));
  10810. c = 0;
  10811. loc = strstr(sstrtemp, "requestedMessage");
  10812. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10813. {
  10814. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10815. c++;
  10816. }
  10817. sstr[c] = '\0';
  10818. strcpy(requestedMessagestr, sstr);
  10819. c = 0;
  10820. loc = strstr(sstrtemp, "connectorId");
  10821. if(loc == NULL)
  10822. {
  10823. connectorIdIsNULL = TRUE;
  10824. }
  10825. else
  10826. {
  10827. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10828. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10829. {
  10830. sstr[c] = loc[strlen("connectorId")+2+c];
  10831. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10832. c++;
  10833. }
  10834. sstr[c] = '\0';
  10835. connectorIdInt = atoi(sstr);
  10836. }
  10837. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10838. {
  10839. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10840. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10841. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10842. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10843. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10844. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10845. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10846. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10847. {
  10848. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10849. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10850. return TRUE;
  10851. }
  10852. else
  10853. {
  10854. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10855. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10856. }
  10857. }
  10858. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10859. {
  10860. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10861. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10862. return TRUE;
  10863. }
  10864. //==========================
  10865. // Trigger message
  10866. //==========================
  10867. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10868. {
  10869. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10870. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10871. {
  10872. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10873. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10874. }
  10875. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10876. }
  10877. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10878. {
  10879. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  10880. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10881. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10882. }
  10883. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10884. {
  10885. //sendBootNotificationRequest();
  10886. server_sign = FALSE;
  10887. }
  10888. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10889. {
  10890. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10891. }
  10892. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10893. {
  10894. if(connectorIdIsNULL == FALSE)
  10895. {
  10896. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10897. {
  10898. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10899. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10900. }
  10901. }
  10902. else
  10903. {
  10904. for(int idx=0;idx< gunTotalNumber;idx++)
  10905. {
  10906. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10907. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10908. }
  10909. }
  10910. }
  10911. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10912. {
  10913. if(connectorIdIsNULL == FALSE)
  10914. {
  10915. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10916. {
  10917. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10918. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  10919. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  10920. }
  10921. }
  10922. else
  10923. {
  10924. for(int idx=0;idx< gunTotalNumber;idx++)
  10925. {
  10926. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  10927. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  10928. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  10929. }
  10930. }
  10931. }
  10932. return result;
  10933. }
  10934. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10935. {
  10936. mtrace();
  10937. int result = FAIL;
  10938. int connectorIdInt =0;
  10939. char comfirmstr[20]={0};
  10940. int tempIndex = 0;
  10941. json_object *UnlockConnector;
  10942. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10943. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10944. UnlockConnector = json_tokener_parse(payload);
  10945. if(!is_error(UnlockConnector))
  10946. {
  10947. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10948. {
  10949. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10950. }
  10951. }
  10952. json_object_put(UnlockConnector);
  10953. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10954. if(gunTotalNumber == 0)
  10955. {
  10956. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10957. goto end;
  10958. }
  10959. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10960. {
  10961. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10962. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10963. goto end;
  10964. }
  10965. else
  10966. {
  10967. //check Transaction active
  10968. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10969. {
  10970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10971. {
  10972. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10973. }
  10974. else
  10975. {
  10976. tempIndex = connectorIdInt -1;
  10977. }
  10978. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10979. {
  10980. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10981. {
  10982. //stop Transaction
  10983. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10984. }
  10985. }
  10986. }
  10987. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10988. {
  10989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10990. {
  10991. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10992. }
  10993. else
  10994. {
  10995. tempIndex = connectorIdInt -1;
  10996. }
  10997. for (int index = 0; index < CCS_QUANTITY; index++)
  10998. {
  10999. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11000. {
  11001. //stop Transaction
  11002. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11003. }
  11004. }
  11005. }
  11006. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11007. {
  11008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11009. {
  11010. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11011. }
  11012. else
  11013. {
  11014. tempIndex = connectorIdInt -1;
  11015. }
  11016. for (int index = 0; index < GB_QUANTITY; index++)
  11017. {
  11018. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11019. {
  11020. //stop Transaction
  11021. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11022. }
  11023. }
  11024. }
  11025. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11026. {
  11027. tempIndex = connectorIdInt -1;
  11028. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11029. {
  11030. 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)))
  11031. {
  11032. //stop Transaction
  11033. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11034. }
  11035. }
  11036. }
  11037. else
  11038. {
  11039. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11040. {
  11041. tempIndex = 2;
  11042. }
  11043. else
  11044. {
  11045. tempIndex = connectorIdInt-1;
  11046. }
  11047. for (int index = 0; index < AC_QUANTITY; index++)
  11048. {
  11049. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11050. {
  11051. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11052. }
  11053. }
  11054. }
  11055. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11056. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  11057. result = TRUE;
  11058. return result;
  11059. }
  11060. end:
  11061. //json_object_put(obj); --- remove temporally
  11062. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11063. return result;
  11064. }
  11065. static char UpdateFirmwarepayloadData[300]={0};
  11066. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11067. {
  11068. mtrace();
  11069. int result = FAIL;
  11070. pthread_t t;
  11071. sendUpdateFirmwareConfirmation(uuid);
  11072. memset(UpdateFirmwarepayloadData, 0, 300);
  11073. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11074. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11075. ////pthread_join(t, NULL); //
  11076. //pthread_detach(t);
  11077. //sendUpdateFirmwareConfirmation(uuid);
  11078. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  11079. return result;
  11080. }
  11081. void *UpdateFirmwareProcess(void *data)
  11082. {
  11083. pthread_detach(pthread_self());
  11084. mtrace();
  11085. int retriesInt =0, retryIntervalInt=0;
  11086. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  11087. int port=0;
  11088. char locationstr[512]={0}, retrieveDatestr[36]={0};
  11089. int isSuccess = 0;
  11090. char ftpbuf[512];
  11091. char temp[100];
  11092. char * pch;
  11093. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11094. json_object *UpdateFirmware;
  11095. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11096. if(!is_error(UpdateFirmware))
  11097. {
  11098. // Required data
  11099. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11100. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11101. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11102. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11103. // Optional data
  11104. if(json_object_object_get(UpdateFirmware, "retries"))
  11105. {
  11106. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11107. }
  11108. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11109. {
  11110. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11111. }
  11112. }
  11113. json_object_put(UpdateFirmware);
  11114. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11115. memset(path, 0, ARRAY_SIZE(path));
  11116. // Wait retrieveData
  11117. if(strlen(retrieveDatestr) > 10)
  11118. {
  11119. do
  11120. {
  11121. sleep(1);
  11122. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11123. }
  11124. // Ready to download
  11125. system("rm -f /mnt/*");
  11126. if(strncmp(locationstr,"http", 4) == 0)
  11127. {
  11128. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11129. sprintf(ftppath,"/%s", path);
  11130. DEBUG_INFO("locationstr: %s\n", locationstr);
  11131. DEBUG_INFO("protocol: %s\n",protocol);
  11132. DEBUG_INFO("host: %s\n",host);
  11133. DEBUG_INFO("path: %s\n",path);
  11134. DEBUG_INFO("ftppath: %s\n",ftppath);
  11135. int ftppathlen=strlen(ftppath);
  11136. int i=1;
  11137. char filenametemp[50];
  11138. while(i < ftppathlen)
  11139. {
  11140. int len=ftppathlen-i;
  11141. if(ftppath[len]== 47) // '/' ascll code: 47
  11142. {
  11143. DEBUG_INFO("compare '/' all right\n");
  11144. break;
  11145. }
  11146. i=i+1;
  11147. }
  11148. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11149. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11150. filenametemp[i+1] = 0;
  11151. do
  11152. {
  11153. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11154. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11155. sleep(1);
  11156. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11157. if(!isSuccess)
  11158. {
  11159. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11160. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11161. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11162. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11163. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11164. }
  11165. else
  11166. {
  11167. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11168. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11169. }
  11170. retriesInt--;
  11171. }while((isSuccess == 0)&&(retriesInt >= 0));
  11172. }
  11173. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11174. {
  11175. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11176. memset(temp, 0, ARRAY_SIZE(temp));
  11177. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11178. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11179. int ftppathlen=strlen(ftpbuf);
  11180. int i=1;
  11181. char filenametemp[50];
  11182. while(i < ftppathlen)
  11183. {
  11184. int len=ftppathlen-i;
  11185. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11186. {
  11187. DEBUG_INFO(" compare '/' all right\n");
  11188. break;
  11189. }
  11190. i=i+1;
  11191. }
  11192. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11193. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11194. filenametemp[i+1] = 0;
  11195. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11196. pch=strchr(temp,'@');
  11197. if(pch==NULL)
  11198. {
  11199. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11200. protocol, host, &port, path);
  11201. strcpy(user,"anonymous");
  11202. strcpy(password,"");
  11203. }
  11204. else
  11205. {
  11206. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11207. protocol, user, password, host, &port, path);
  11208. }
  11209. sscanf(host,"%[^/]%s",host1, path1);
  11210. sprintf(ftppath,"%s", path1);
  11211. //DEBUG_INFO("protocol =%s\n",protocol);
  11212. //DEBUG_INFO("user =%s\n",user);
  11213. //DEBUG_INFO("password =%s\n",password);
  11214. //DEBUG_INFO("host1 =%s\n",host1);
  11215. //DEBUG_INFO("port =%d\n",port);
  11216. //DEBUG_INFO("path1 =%s\n",path1);
  11217. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11218. //ftpFile(host, user, password, port, ftppath, fname);
  11219. //download firmware pthred
  11220. if(port == 0)
  11221. {
  11222. port = 21;
  11223. }
  11224. do
  11225. {
  11226. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11227. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11228. sleep(1);
  11229. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11230. if(!isSuccess)
  11231. {
  11232. //BulldogUtil.sleepMs(interval*1000);
  11233. DEBUG_INFO("Update firmware request and download file fail.\n");
  11234. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11235. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11236. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11237. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11238. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11239. }
  11240. else
  11241. {
  11242. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11243. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11244. }
  11245. retriesInt--;
  11246. }while((!isSuccess)&&(retriesInt >= 0));
  11247. }
  11248. else
  11249. {
  11250. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11251. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11252. sleep(1);
  11253. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11254. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11255. }
  11256. // OCPPPH only, must announce CSU upgrade firmware
  11257. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  11258. pthread_exit(NULL);
  11259. }
  11260. int handleCertificateSignedRequest(char *uuid, char *payload)
  11261. {
  11262. mtrace();
  11263. int result = PASS;
  11264. json_object *CertificateSigned;
  11265. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11266. CertificateSigned = json_tokener_parse(payload);
  11267. if(!is_error(CertificateSigned))
  11268. {
  11269. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11270. }
  11271. json_object_put(CertificateSigned);
  11272. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  11273. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  11274. fclose(fp);
  11275. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11276. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  11277. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  11278. sendCertificateSignedConfirmation(uuid);
  11279. return result;
  11280. }
  11281. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11282. {
  11283. mtrace();
  11284. int result = PASS;
  11285. json_object *DeleteCertificate;
  11286. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11287. DeleteCertificate = json_tokener_parse(payload);
  11288. if(!is_error(DeleteCertificate))
  11289. {
  11290. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11291. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11292. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11293. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11294. }
  11295. json_object_put(DeleteCertificate);
  11296. /*
  11297. * TODO: Delete certificateSigned process
  11298. */
  11299. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  11300. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  11301. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  11302. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  11303. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  11304. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  11305. sendDeleteCertificateConfirmation(uuid);
  11306. return result;
  11307. }
  11308. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11309. {
  11310. mtrace();
  11311. int result = PASS;
  11312. json_object *ExtendedTriggerMessage;
  11313. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11314. ExtendedTriggerMessage = json_tokener_parse(payload);
  11315. if(!is_error(ExtendedTriggerMessage))
  11316. {
  11317. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11318. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11319. {
  11320. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11321. }
  11322. else
  11323. {
  11324. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  11325. }
  11326. }
  11327. json_object_put(ExtendedTriggerMessage);
  11328. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  11329. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  11330. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11331. {
  11332. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11333. }
  11334. else
  11335. {
  11336. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11337. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11338. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11339. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11340. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11341. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11342. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11343. {
  11344. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11345. }
  11346. else
  11347. {
  11348. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11349. }
  11350. }
  11351. sendExtendedTriggerMessageConfirmation(uuid);
  11352. //==========================
  11353. // Trigger message
  11354. //==========================
  11355. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11356. {
  11357. //sendBootNotificationRequest();
  11358. server_sign = FALSE;
  11359. }
  11360. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11361. {
  11362. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  11363. }
  11364. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11365. {
  11366. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11367. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11368. {
  11369. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11370. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11371. }
  11372. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11373. }
  11374. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11375. {
  11376. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11377. }
  11378. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11379. {
  11380. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11381. {
  11382. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11383. }
  11384. else
  11385. {
  11386. for(int idx=0;idx< gunTotalNumber;idx++)
  11387. {
  11388. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11389. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11390. }
  11391. }
  11392. }
  11393. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11394. {
  11395. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  11396. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  11397. {
  11398. system("openssl req -newkey rsa:2048 -out /Storage/OCPP_PH/certCP.csr -nodes -keyout /Storage/OCPP_PH/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  11399. }
  11400. }
  11401. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11402. {
  11403. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11404. {
  11405. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11406. }
  11407. else
  11408. {
  11409. for(int idx=0;idx< gunTotalNumber;idx++)
  11410. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11411. }
  11412. }
  11413. return result;
  11414. }
  11415. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11416. {
  11417. mtrace();
  11418. int result = PASS;
  11419. json_object *GetInstalledCertificateIds;
  11420. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11421. GetInstalledCertificateIds = json_tokener_parse(payload);
  11422. if(!is_error(GetInstalledCertificateIds))
  11423. {
  11424. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11425. }
  11426. json_object_put(GetInstalledCertificateIds);
  11427. /*
  11428. * TODO: Return installed certificate process
  11429. */
  11430. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11431. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  11432. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11433. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  11434. sendGetInstalledCertificateIdsConfirmation(uuid);
  11435. return result;
  11436. }
  11437. int handleGetLogRequest(char *uuid, char *payload)
  11438. {
  11439. mtrace();
  11440. int result = PASS;
  11441. json_object *GetLog;
  11442. DEBUG_INFO("handleGetLogRequest...\n");
  11443. GetLog = json_tokener_parse(payload);
  11444. if(!is_error(GetLog))
  11445. {
  11446. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11447. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11448. if(json_object_object_get(GetLog, "retries") != NULL)
  11449. {
  11450. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11451. }
  11452. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11453. {
  11454. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11455. }
  11456. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11457. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11458. {
  11459. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11460. }
  11461. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11462. {
  11463. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11464. }
  11465. }
  11466. json_object_put(GetLog);
  11467. /*
  11468. * TODO: Upload log process
  11469. */
  11470. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  11471. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  11472. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  11473. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  11474. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  11475. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  11476. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  11477. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  11478. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  11479. sendGetLogConfirmation(uuid);
  11480. return result;
  11481. }
  11482. int handleInstallCertificateRequest(char *uuid, char *payload)
  11483. {
  11484. mtrace();
  11485. int result = PASS;
  11486. json_object *InstallCertificate;
  11487. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11488. InstallCertificate = json_tokener_parse(payload);
  11489. if(!is_error(InstallCertificate))
  11490. {
  11491. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11492. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11493. /*
  11494. * TODO: Install certificate process
  11495. */
  11496. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  11497. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  11498. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  11499. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  11500. sendInstallCertificateConfirmation(uuid);
  11501. }
  11502. json_object_put(InstallCertificate);
  11503. return result;
  11504. }
  11505. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11506. {
  11507. mtrace();
  11508. int result = PASS;
  11509. json_object *SignedUpdateFirmware;
  11510. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11511. SignedUpdateFirmware = json_tokener_parse(payload);
  11512. if(!is_error(SignedUpdateFirmware))
  11513. {
  11514. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11515. {
  11516. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11517. }
  11518. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11519. {
  11520. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11521. }
  11522. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11523. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11524. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11525. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11526. {
  11527. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11528. }
  11529. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11530. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11531. }
  11532. json_object_put(SignedUpdateFirmware);
  11533. /*
  11534. * TODO: Upgrade firmware process
  11535. */
  11536. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11537. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  11538. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  11539. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  11540. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  11541. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  11542. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  11543. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  11544. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  11545. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  11546. sendInstallCertificateConfirmation(uuid);
  11547. return result;
  11548. }
  11549. int handleUnknownRequest(char *uuid, char *payload)
  11550. {
  11551. mtrace();
  11552. int result = PASS;
  11553. DEBUG_INFO("handleUnknownRequest...\n");
  11554. sendUnknownConfirmation(uuid);
  11555. result = PASS;
  11556. return result;
  11557. }
  11558. //==========================================
  11559. // Handle server response routine
  11560. //==========================================
  11561. void handleAuthorizeResponse(char *payload, int gun_index)
  11562. {
  11563. mtrace();
  11564. char expiryDatestr[30]={0};
  11565. char parentIdTagstr[20]={0};
  11566. char statusstr[20]={0};
  11567. int expiryDateISNULL=FALSE;
  11568. int parentIdTagISNULL=FALSE;
  11569. DEBUG_INFO("handleAuthorizeResponse...\n");
  11570. json_object *Authorize;
  11571. Authorize = json_tokener_parse(payload);
  11572. if(!is_error(Authorize))
  11573. {
  11574. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11575. {
  11576. // Required data
  11577. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11578. // Optional data
  11579. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11580. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11581. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11582. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11583. }
  11584. }
  11585. json_object_put(Authorize);
  11586. if(expiryDateISNULL == FALSE)
  11587. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11588. if(parentIdTagISNULL == FALSE)
  11589. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11590. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11591. //Update idTag information to authorization cache if supproted
  11592. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11593. {
  11594. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11595. }
  11596. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11597. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11598. authorizeRetryTimes = 0;
  11599. }
  11600. void handleBootNotificationResponse(char *payload, int gun_index)
  11601. {
  11602. mtrace();
  11603. char statusStr[12]={0};
  11604. char currentTimeStr[30]={0};
  11605. int intervalInt = 0;
  11606. DEBUG_INFO("handleBootNotificationResponse...\n");
  11607. json_object *BootNotification;
  11608. BootNotification = json_tokener_parse(payload);
  11609. if(!is_error(BootNotification))
  11610. {
  11611. // Required data
  11612. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11613. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11614. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11615. }
  11616. json_object_put(BootNotification);
  11617. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11618. BootNotificationInterval = intervalInt;
  11619. HeartBeatWaitTime = intervalInt;
  11620. //write back to ShmOCPP16DataPH->BootNotification
  11621. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11622. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11623. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11624. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11625. {
  11626. server_sign = TRUE;
  11627. server_pending =FALSE;
  11628. }
  11629. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11630. {
  11631. server_pending = TRUE;
  11632. }
  11633. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11634. srand(time(NULL));
  11635. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11636. SetOcppConnStatus(TRUE);
  11637. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11638. }
  11639. void handleDataTransferResponse(char *payload, int gun_index)
  11640. {
  11641. char sstr[160]={0};//sstr[200]={ 0 };
  11642. int c = 0;
  11643. char *loc;
  11644. DEBUG_INFO("handleDataTransferResponse ...\n");
  11645. loc = strstr(payload, "status");
  11646. c = 0;
  11647. while (loc[3+strlen("status")+c] != '\"')
  11648. {
  11649. sstr[c] = loc[3+strlen("status")+c];
  11650. c++;
  11651. }
  11652. sstr[c] = '\0';
  11653. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11654. }
  11655. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11656. {
  11657. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11658. //struct json_object *obj;
  11659. // obj = json_tokener_parse(payload);
  11660. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11661. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11662. //No fields are defined.
  11663. }
  11664. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11665. {
  11666. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11667. //struct json_object *obj;
  11668. // obj = json_tokener_parse(payload);
  11669. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11670. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11671. //No fields are defined.
  11672. }
  11673. void handleHeartbeatResponse(char *payload, int gun_index)
  11674. {
  11675. mtrace();
  11676. DEBUG_INFO("handleHeartbeatResponse...\n");
  11677. json_object *Heartbeat;
  11678. Heartbeat = json_tokener_parse(payload);
  11679. if(!is_error(Heartbeat))
  11680. {
  11681. // Required data
  11682. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11683. }
  11684. json_object_put(Heartbeat);
  11685. if(FirstHeartBeat == 0)
  11686. {
  11687. FirstHeartBeat = 1;
  11688. DEBUG_INFO("FirstHeartBeat \n");
  11689. }
  11690. HeartBeatWithNOResponse = 0;
  11691. clientTime.Heartbeat=time((time_t*)NULL);
  11692. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11693. }
  11694. void handleMeterValuesResponse(char *payload, int gun_index)
  11695. {
  11696. mtrace();
  11697. DEBUG_INFO("handleMeterValuesResponse...\n");
  11698. }
  11699. void handleStartTransactionResponse(char *payload, int gun_index)
  11700. {
  11701. mtrace();
  11702. //int transactionIdInt = 0;
  11703. FILE *outfile;
  11704. char data[100]={0};
  11705. DEBUG_INFO("handleStartTransactionResponse...\n");
  11706. json_object *StartTransaction;
  11707. StartTransaction = json_tokener_parse(payload);
  11708. if(!is_error(StartTransaction))
  11709. {
  11710. // Required data
  11711. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11712. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11713. // Optional data
  11714. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11715. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11716. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11717. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11718. }
  11719. json_object_put(StartTransaction);
  11720. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11721. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11722. //-----------Start : write to the Queue TransactionId file -----------------//
  11723. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11724. {}
  11725. else
  11726. {
  11727. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  11728. if(log == NULL)
  11729. {
  11730. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11731. return ;
  11732. }
  11733. else
  11734. {
  11735. fclose(log);
  11736. }
  11737. }
  11738. // open file for writing
  11739. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11740. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  11741. {
  11742. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  11743. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11744. fputs(data, outfile);
  11745. fclose (outfile);
  11746. }
  11747. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11748. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11749. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11750. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  11751. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11752. }
  11753. void handleStatusNotificationResponse(char *payload, int gun_index)
  11754. {
  11755. mtrace();
  11756. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11757. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11758. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11759. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11760. }
  11761. void handleStopTransactionnResponse(char *payload, int gun_index)
  11762. {
  11763. mtrace();
  11764. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11765. json_object *StopTransaction;
  11766. StopTransaction = json_tokener_parse(payload);
  11767. if(!is_error(StopTransaction))
  11768. {
  11769. // Optional data
  11770. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11771. {
  11772. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11773. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11774. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11775. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11776. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11777. }
  11778. }
  11779. json_object_put(StopTransaction);
  11780. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11781. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11782. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11783. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11784. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11785. }
  11786. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11787. {
  11788. mtrace();
  11789. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11790. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  11791. }
  11792. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11793. {
  11794. mtrace();
  11795. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11796. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  11797. }
  11798. void handleSignCertificateResponse(char *payload, int gun_index)
  11799. {
  11800. mtrace();
  11801. DEBUG_INFO("handleSignCertificateResponse...\n");
  11802. json_object *SignCertificate;
  11803. SignCertificate = json_tokener_parse(payload);
  11804. if(!is_error(SignCertificate))
  11805. {
  11806. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11807. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  11808. }
  11809. json_object_put(SignCertificate);
  11810. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  11811. }
  11812. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11813. {
  11814. mtrace();
  11815. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11816. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11817. }
  11818. //==========================================
  11819. // Handle Error routine
  11820. //==========================================
  11821. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11822. {
  11823. mtrace();
  11824. #ifdef SystemLogMessage
  11825. DEBUG_INFO("errorCode: %s\n", errorCode);
  11826. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11827. DEBUG_INFO("errorDetails: %s\n", payload);
  11828. #endif
  11829. }
  11830. //===============================================
  11831. // Common routine
  11832. //===============================================
  11833. int initialConfigurationTable(void)
  11834. {
  11835. //clock_t start_t, end_t, total_t;
  11836. FILE *fp;
  11837. FILE *outfile;
  11838. char str[512]={0};
  11839. char sstr[256]={0};
  11840. int c = 0;
  11841. char *loc;
  11842. int confVersion = 3;
  11843. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11844. //start_t = clock();
  11845. //printf("Starting of the program, start_t = %ld\n", start_t);
  11846. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11847. // Check configuration file size is correct
  11848. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  11849. {
  11850. struct stat st;
  11851. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  11852. if(st.st_size < 3100)
  11853. {
  11854. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  11855. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11856. }
  11857. }
  11858. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  11859. {
  11860. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11861. if(outfile == NULL)
  11862. {
  11863. DEBUG_INFO("Error opening file\n");
  11864. return FALSE;
  11865. }
  11866. /*Core Profile*/
  11867. //AllowOfflineTxForUnknownId
  11868. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11870. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11872. //AuthorizationCacheEnabled
  11873. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11874. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11877. //AuthorizeRemoteTxRequests
  11878. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11879. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11882. //BlinkRepeat
  11883. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11884. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11885. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11887. //ClockAlignedDataInterval
  11888. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11892. //ConnectionTimeOut
  11893. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11895. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11897. //GetConfigurationMaxKeys
  11898. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11899. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11900. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11902. // HeartbeatInterval
  11903. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11904. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11905. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11907. // LightIntensity
  11908. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11909. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11912. // LocalAuthorizeOffline
  11913. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11917. // LocalPreAuthorize
  11918. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11919. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11920. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11922. // MaxEnergyOnInvalidId
  11923. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11927. // MeterValuesAlignedData
  11928. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11929. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11930. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11932. else
  11933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11935. // MeterValuesAlignedDataMaxLength
  11936. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11938. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11940. else
  11941. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11943. // MeterValuesSampledData
  11944. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11946. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11947. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11948. else
  11949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11951. // MeterValuesSampledDataMaxLength
  11952. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11954. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11955. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11956. else
  11957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11959. // MeterValueSampleInterval
  11960. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11962. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11964. // MinimumStatusDuration
  11965. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11968. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11970. // NumberOfConnectors
  11971. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11972. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11973. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11974. {
  11975. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11976. }
  11977. else
  11978. {
  11979. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11980. }
  11981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11982. // ResetRetries
  11983. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11984. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11987. // ConnectorPhaseRotation
  11988. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11989. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11990. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11992. // ConnectorPhaseRotationMaxLength
  11993. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11997. // StopTransactionOnEVSideDisconnect
  11998. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12002. // StopTransactionOnInvalidId
  12003. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12004. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12005. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12006. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12007. // StopTxnAlignedData
  12008. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12009. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12010. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12012. // StopTxnAlignedDataMaxLength
  12013. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12014. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12017. // StopTxnSampledData
  12018. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12019. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12022. else
  12023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12025. // StopTxnSampledDataMaxLength
  12026. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12027. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12028. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12029. {
  12030. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12031. }
  12032. else
  12033. {
  12034. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12035. }
  12036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12037. // SupportedFeatureProfiles
  12038. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12039. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12040. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12042. // SupportedFeatureProfilesMaxLength
  12043. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12045. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12047. // TransactionMessageAttempts
  12048. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12051. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12053. // TransactionMessageRetryInterval
  12054. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12057. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12059. // UnlockConnectorOnEVSideDisconnect
  12060. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12064. // WebSocketPingInterval
  12065. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12069. // QueueOffLineStartTransactionMessage
  12070. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  12071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12074. // AuthorizationKey
  12075. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12076. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  12078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12079. // SecurityProfile
  12080. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12081. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12082. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12084. // DefaultPrice
  12085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12089. // CustomDisplayCostAndPrice
  12090. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12094. // CustomIdleFeeAfterStop
  12095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12096. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12099. // Configuration Version
  12100. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12102. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12104. //* Local Auth List Management Profile*/
  12105. #if 0
  12106. //For OCTT Test Case
  12107. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12109. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12110. #endif
  12111. #if 1
  12112. //LocalAuthListEnabled
  12113. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12117. #endif
  12118. //LocalAuthListMaxLength
  12119. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12123. //SendLocalListMaxLength
  12124. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  12127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12128. //ReserveConnectorZeroSupported
  12129. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12133. //* Smart Charging Profile */
  12134. //ChargeProfileMaxStackLevel
  12135. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12137. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12139. // ChargingScheduleAllowedChargingRateUnit
  12140. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12142. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12144. // ChargingScheduleMaxPeriods
  12145. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12147. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12149. // ConnectorSwitch3to1PhaseSupported
  12150. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12152. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12154. // MaxChargingProfilesInstalled
  12155. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12159. fclose(outfile);
  12160. }
  12161. else
  12162. {
  12163. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  12164. char keystr[60]={0};
  12165. char readonlystr[10]={0};
  12166. char valuestr[256]={0};
  12167. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  12168. if(fp == NULL) {
  12169. DEBUG_INFO("Error opening file");
  12170. return FALSE;
  12171. }
  12172. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12173. {
  12174. //DEBUG_INFO("Get Configuration \n");
  12175. if(strlen(str) > 0)
  12176. {
  12177. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12178. //*************************key*********************************/
  12179. if(strstr(str, "key") != NULL)
  12180. {
  12181. loc = strstr(str, "key");
  12182. c = 0;
  12183. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12184. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12185. {
  12186. sstr[c] = loc[strlen("key")+3+c];
  12187. c++;
  12188. }
  12189. sstr[c] = '\0';
  12190. strcpy(keystr,sstr);
  12191. }
  12192. //*************************readonly*********************************/
  12193. if(strstr(str, "readonly") != NULL)
  12194. {
  12195. loc = strstr(str, "readonly");
  12196. c = 0;
  12197. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12198. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12199. {
  12200. sstr[c] = loc[strlen("readonly")+2+c];
  12201. c++;
  12202. }
  12203. sstr[c] = '\0';
  12204. strcpy(readonlystr,sstr);
  12205. }
  12206. //*************************value*********************************/
  12207. if(strstr(str, "value") != NULL)
  12208. {
  12209. loc = strstr(str, "value");
  12210. c = 0;
  12211. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12212. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12213. {
  12214. sstr[c] = loc[strlen("value")+3+c];
  12215. c++;
  12216. }
  12217. sstr[c] = '\0';
  12218. strcpy(valuestr,sstr);
  12219. }
  12220. // DEBUG_INFO("keystr=%s\n",keystr);
  12221. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12222. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12223. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12224. {
  12225. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12226. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12227. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12228. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12229. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12230. }
  12231. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12232. {
  12233. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12234. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12235. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12236. }
  12237. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12238. {
  12239. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12240. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12241. }
  12242. if(strcmp(keystr, "BlinkRepeat") == 0)
  12243. {
  12244. //Charger.BlinkRepeat = Integer.parseInt(value);
  12245. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12246. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12247. }
  12248. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12249. {
  12250. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12251. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12252. }
  12253. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12254. {
  12255. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12256. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12257. }
  12258. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12259. {
  12260. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12261. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12262. }
  12263. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12264. {
  12265. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12266. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12267. HeartBeatWaitTime = atoi(valuestr);
  12268. }
  12269. if(strcmp(keystr, "LightIntensity") == 0)
  12270. {
  12271. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12272. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12273. }
  12274. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12275. {
  12276. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12277. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12278. }
  12279. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12280. {
  12281. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12282. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12283. }
  12284. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12285. {
  12286. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12287. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12288. }
  12289. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12290. {
  12291. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12292. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12293. }
  12294. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12295. {
  12296. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12297. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12298. }
  12299. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12300. {
  12301. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12302. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12303. }
  12304. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12305. {
  12306. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12307. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12308. }
  12309. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12310. {
  12311. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12313. }
  12314. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12315. {
  12316. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12317. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12318. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12319. }
  12320. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12321. {
  12322. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12323. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12324. }
  12325. if(strcmp(keystr, "ResetRetries") == 0)
  12326. {
  12327. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12328. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12329. }
  12330. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12331. {
  12332. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12333. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12334. }
  12335. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12336. {
  12337. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12338. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12339. }
  12340. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12341. {
  12342. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12343. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12344. }
  12345. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12346. {
  12347. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12348. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12349. }
  12350. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12351. {
  12352. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12353. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12354. }
  12355. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12356. {
  12357. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12358. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12359. }
  12360. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12361. {
  12362. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12363. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12364. }
  12365. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12366. {
  12367. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12368. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12369. }
  12370. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12371. {
  12372. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12373. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12374. }
  12375. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12376. {
  12377. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12378. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12379. }
  12380. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12381. {
  12382. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12383. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12384. TransactionMessageAttemptsValue = atoi(valuestr);
  12385. }
  12386. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12387. {
  12388. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12389. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12390. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12391. }
  12392. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12393. {
  12394. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12395. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12396. }
  12397. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12398. {
  12399. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12400. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12401. }
  12402. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  12403. {
  12404. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12405. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  12406. }
  12407. if(strcmp(keystr, "AuthorizationKey") == 0)
  12408. {
  12409. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12410. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12411. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12412. }
  12413. if(strcmp(keystr, "SecurityProfile") == 0)
  12414. {
  12415. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12416. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  12417. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12418. }
  12419. if(strcmp(keystr, "DefaultPrice") == 0)
  12420. {
  12421. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12422. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12423. }
  12424. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12425. {
  12426. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12427. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12428. }
  12429. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12430. {
  12431. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12432. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12433. }
  12434. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12435. {
  12436. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12437. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12438. }
  12439. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12440. {
  12441. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12442. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12443. }
  12444. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12445. {
  12446. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12447. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12448. }
  12449. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12450. {
  12451. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12452. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12453. }
  12454. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12455. {
  12456. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12457. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12458. }
  12459. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12460. {
  12461. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12462. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12463. }
  12464. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12465. {
  12466. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12467. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12468. }
  12469. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12470. {
  12471. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12472. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12473. }
  12474. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12475. {
  12476. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12477. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12478. }
  12479. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12480. {
  12481. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12482. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12483. }
  12484. }
  12485. }
  12486. fclose(fp);
  12487. }
  12488. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12489. {
  12490. return PASS;
  12491. }
  12492. else
  12493. {
  12494. return FAIL;
  12495. }
  12496. }
  12497. void StoreConfigurationTable(void)
  12498. {
  12499. FILE *outfile;
  12500. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12501. if(outfile == NULL)
  12502. {
  12503. DEBUG_INFO("Error opening file");
  12504. return ;
  12505. }
  12506. /*Core Profile*/
  12507. //AllowOfflineTxForUnknownId
  12508. /*
  12509. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12510. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12511. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12512. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12513. */
  12514. //DEBUG_INFO("data=%s\n",data);
  12515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12516. //AuthorizationCacheEnabled
  12517. /*
  12518. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12519. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12520. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12521. */
  12522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12523. //AuthorizeRemoteTxRequests
  12524. /*
  12525. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12526. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12527. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12528. */
  12529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12530. //BlinkRepeat
  12531. /*
  12532. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12533. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12534. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12535. */
  12536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12537. //ClockAlignedDataInterval
  12538. /*
  12539. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12540. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12541. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12542. */
  12543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12544. //ConnectionTimeOut
  12545. /*
  12546. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12547. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12548. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12549. */
  12550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12551. //GetConfigurationMaxKeys
  12552. /*
  12553. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12554. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12555. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12556. */
  12557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12558. // HeartbeatInterval
  12559. /*
  12560. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12561. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12562. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12563. */
  12564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12565. // LightIntensity
  12566. /*
  12567. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12568. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12569. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12570. */
  12571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12572. // LocalAuthorizeOffline
  12573. /*
  12574. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12575. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12576. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12577. */
  12578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12579. // LocalPreAuthorize
  12580. /*
  12581. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12582. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12583. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12584. */
  12585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12586. // MaxEnergyOnInvalidId
  12587. /*
  12588. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12589. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12590. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12591. */
  12592. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12594. // MeterValuesAlignedData
  12595. /*
  12596. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12597. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12598. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12599. */
  12600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12601. // MeterValuesAlignedDataMaxLength
  12602. /*
  12603. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12604. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12605. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12606. */
  12607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12608. // MeterValuesSampledData
  12609. /*
  12610. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12611. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12612. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12613. */
  12614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12615. // MeterValuesSampledDataMaxLength
  12616. /*
  12617. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12618. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12619. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12620. */
  12621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12622. // MeterValueSampleInterval
  12623. /*
  12624. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12625. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12626. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12627. */
  12628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12629. // MinimumStatusDuration
  12630. /*
  12631. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12632. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12633. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12634. */
  12635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12636. // NumberOfConnectors
  12637. /*
  12638. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12639. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12640. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12641. {
  12642. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12643. }
  12644. else
  12645. {
  12646. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12647. }
  12648. */
  12649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12650. // ResetRetries
  12651. /*
  12652. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12653. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12654. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12655. */
  12656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12657. // ConnectorPhaseRotation
  12658. /*
  12659. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12660. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12661. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12662. */
  12663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12664. // ConnectorPhaseRotationMaxLength
  12665. /*
  12666. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12667. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12668. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12669. */
  12670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12671. // StopTransactionOnEVSideDisconnect
  12672. /*
  12673. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12674. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12675. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12676. */
  12677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12678. // StopTransactionOnInvalidId
  12679. /*
  12680. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12681. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12682. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12683. */
  12684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12685. // StopTxnAlignedData
  12686. /*
  12687. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12688. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12689. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12690. */
  12691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12692. // StopTxnAlignedDataMaxLength
  12693. /*
  12694. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12695. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12696. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12697. */
  12698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12699. // StopTxnSampledData
  12700. /*
  12701. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12702. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12703. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12704. */
  12705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12706. // StopTxnSampledDataMaxLength
  12707. /*
  12708. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12709. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12710. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12711. */
  12712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12713. // SupportedFeatureProfiles
  12714. /*
  12715. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12716. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12717. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12718. */
  12719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12720. // SupportedFeatureProfilesMaxLength
  12721. /*
  12722. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12723. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12724. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12725. */
  12726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12727. // TransactionMessageAttempts
  12728. /*
  12729. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12730. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12731. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12732. */
  12733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12734. // TransactionMessageRetryInterval
  12735. /*
  12736. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12737. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12738. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12739. */
  12740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12741. // UnlockConnectorOnEVSideDisconnect
  12742. /*
  12743. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12744. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12745. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12746. */
  12747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12748. // WebSocketPingInterval
  12749. /*
  12750. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12751. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12752. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12753. */
  12754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12755. // QueueOffLineStartTransactionMessage
  12756. /*
  12757. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12758. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12759. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12760. */
  12761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12762. // AuthorizationKey
  12763. /*
  12764. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12765. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12766. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12767. */
  12768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12769. // SecurityProfile
  12770. /*
  12771. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12772. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12773. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12774. */
  12775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12776. // DefaultPrice
  12777. /*
  12778. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12779. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12780. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12781. */
  12782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12783. // CustomDisplayCostAndPrice
  12784. /*
  12785. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12786. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12787. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12788. */
  12789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12790. // CustomIdleFeeAfterStop
  12791. /*
  12792. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12793. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12794. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12795. */
  12796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12797. // ConfigurationVersion
  12798. /*
  12799. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12801. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12802. */
  12803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12804. //* Local Auth List Management Profile*/
  12805. //LocalAuthListEnabled
  12806. /*
  12807. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12808. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12810. */
  12811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12812. //LocalAuthListMaxLength
  12813. /*
  12814. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12815. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12816. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12817. */
  12818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12819. //SendLocalListMaxLength
  12820. /*
  12821. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12822. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12823. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12824. */
  12825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12826. //ReserveConnectorZeroSupported
  12827. /*
  12828. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12831. */
  12832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12833. //* Smart Charging Profile */
  12834. //ChargeProfileMaxStackLevel
  12835. /*
  12836. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12838. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12839. */
  12840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12841. // ChargingScheduleAllowedChargingRateUnit
  12842. /*
  12843. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12846. */
  12847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12848. // ChargingScheduleMaxPeriods
  12849. /*
  12850. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12853. */
  12854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12855. // ConnectorSwitch3to1PhaseSupported
  12856. /*
  12857. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12860. */
  12861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12862. // MaxChargingProfilesInstalled
  12863. /*
  12864. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12867. */
  12868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12869. fclose(outfile);
  12870. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12871. }
  12872. void getKeyValue(char *keyReq)
  12873. {
  12874. int isEmpty = FALSE;
  12875. int isKnowKey = FALSE;
  12876. DEBUG_INFO("keyReq = %s\n", keyReq);
  12877. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12878. isEmpty = TRUE;
  12879. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12880. {
  12881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12883. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12884. {
  12885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12886. }
  12887. else
  12888. {
  12889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12890. }
  12891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12892. isKnowKey = TRUE;
  12893. }
  12894. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12895. {
  12896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12898. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12899. {
  12900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12901. }
  12902. else
  12903. {
  12904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12905. }
  12906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12907. isKnowKey = TRUE;
  12908. }
  12909. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12910. {
  12911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12913. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12914. {
  12915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12916. }
  12917. else
  12918. {
  12919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12920. }
  12921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12922. isKnowKey = TRUE;
  12923. }
  12924. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12925. {
  12926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12928. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12929. {
  12930. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12931. }
  12932. else
  12933. {
  12934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12935. }
  12936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12937. isKnowKey = TRUE;
  12938. }
  12939. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12940. {
  12941. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12943. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12944. {
  12945. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12946. }
  12947. else
  12948. {
  12949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12950. }
  12951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12952. isKnowKey = TRUE;
  12953. }
  12954. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12955. {
  12956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12958. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12959. {
  12960. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12961. }
  12962. else
  12963. {
  12964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12965. }
  12966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12967. isKnowKey = TRUE;
  12968. }
  12969. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12970. {
  12971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12973. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12974. {
  12975. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12976. }
  12977. else
  12978. {
  12979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12980. }
  12981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12982. isKnowKey = TRUE;
  12983. }
  12984. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12985. {
  12986. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12988. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12989. {
  12990. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12991. }
  12992. else
  12993. {
  12994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12995. }
  12996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12997. isKnowKey = TRUE;
  12998. }
  12999. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13000. {
  13001. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13003. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13004. {
  13005. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13006. }
  13007. else
  13008. {
  13009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13010. }
  13011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13012. isKnowKey = TRUE;
  13013. }
  13014. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13015. {
  13016. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13018. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13019. {
  13020. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13021. }
  13022. else
  13023. {
  13024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13025. }
  13026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13027. isKnowKey = TRUE;
  13028. }
  13029. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13030. {
  13031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13033. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13034. {
  13035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13036. }
  13037. else
  13038. {
  13039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13040. }
  13041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13042. isKnowKey = TRUE;
  13043. }
  13044. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13045. {
  13046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13048. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13049. {
  13050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13051. }
  13052. else
  13053. {
  13054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13055. }
  13056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13057. isKnowKey = TRUE;
  13058. }
  13059. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13060. {
  13061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13063. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13064. {
  13065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13066. }
  13067. else
  13068. {
  13069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13070. }
  13071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13072. isKnowKey = TRUE;
  13073. }
  13074. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13075. {
  13076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13078. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13079. {
  13080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13081. }
  13082. else
  13083. {
  13084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13085. }
  13086. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13087. isKnowKey = TRUE;
  13088. }
  13089. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13090. {
  13091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13092. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13093. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13094. {
  13095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13096. }
  13097. else
  13098. {
  13099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13100. }
  13101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13102. isKnowKey = TRUE;
  13103. }
  13104. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13105. {
  13106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13108. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13109. {
  13110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13111. }
  13112. else
  13113. {
  13114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13115. }
  13116. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13117. isKnowKey = TRUE;
  13118. }
  13119. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13120. {
  13121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13122. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13123. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13124. {
  13125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13126. }
  13127. else
  13128. {
  13129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13130. }
  13131. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13132. isKnowKey = TRUE;
  13133. }
  13134. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13135. {
  13136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13137. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13138. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13139. {
  13140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13141. }
  13142. else
  13143. {
  13144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13145. }
  13146. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  13147. isKnowKey = TRUE;
  13148. }
  13149. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13150. {
  13151. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13153. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13154. {
  13155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13156. }
  13157. else
  13158. {
  13159. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13160. }
  13161. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13163. isKnowKey = TRUE;
  13164. }
  13165. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13166. {
  13167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13168. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13169. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13170. {
  13171. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13172. }
  13173. else
  13174. {
  13175. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13176. }
  13177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13178. isKnowKey = TRUE;
  13179. }
  13180. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13181. {
  13182. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13184. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13185. {
  13186. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13187. }
  13188. else
  13189. {
  13190. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13191. }
  13192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13193. isKnowKey = TRUE;
  13194. }
  13195. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13196. {
  13197. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13199. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13200. {
  13201. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13202. }
  13203. else
  13204. {
  13205. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13206. }
  13207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13208. isKnowKey = TRUE;
  13209. }
  13210. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13211. {
  13212. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13214. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13215. {
  13216. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13217. }
  13218. else
  13219. {
  13220. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13221. }
  13222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13223. isKnowKey = TRUE;
  13224. }
  13225. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13226. {
  13227. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13229. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13230. {
  13231. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13232. }
  13233. else
  13234. {
  13235. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13236. }
  13237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13238. isKnowKey = TRUE;
  13239. }
  13240. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13241. {
  13242. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13244. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13245. {
  13246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13247. }
  13248. else
  13249. {
  13250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13251. }
  13252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13253. isKnowKey = TRUE;
  13254. }
  13255. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13256. {
  13257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13259. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13260. {
  13261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13262. }
  13263. else
  13264. {
  13265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13266. }
  13267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13268. isKnowKey = TRUE;
  13269. }
  13270. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13271. {
  13272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13274. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13275. {
  13276. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13277. }
  13278. else
  13279. {
  13280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13281. }
  13282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13283. isKnowKey = TRUE;
  13284. }
  13285. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13286. {
  13287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13289. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13290. {
  13291. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13292. }
  13293. else
  13294. {
  13295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13296. }
  13297. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13298. isKnowKey = TRUE;
  13299. }
  13300. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13301. {
  13302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13304. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13305. {
  13306. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13307. }
  13308. else
  13309. {
  13310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13311. }
  13312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13313. isKnowKey = TRUE;
  13314. }
  13315. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13316. {
  13317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13319. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13320. {
  13321. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13322. }
  13323. else
  13324. {
  13325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13326. }
  13327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13328. isKnowKey = TRUE;
  13329. }
  13330. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13331. {
  13332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13334. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13335. {
  13336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13337. }
  13338. else
  13339. {
  13340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13341. }
  13342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13343. isKnowKey = TRUE;
  13344. }
  13345. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13346. {
  13347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13349. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13350. {
  13351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13352. }
  13353. else
  13354. {
  13355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13356. }
  13357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13358. isKnowKey = TRUE;
  13359. }
  13360. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13361. {
  13362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13364. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13365. {
  13366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13367. }
  13368. else
  13369. {
  13370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13371. }
  13372. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13373. isKnowKey = TRUE;
  13374. }
  13375. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13376. {
  13377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13379. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13380. {
  13381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13382. }
  13383. else
  13384. {
  13385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13386. }
  13387. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13388. isKnowKey = TRUE;
  13389. }
  13390. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  13391. {
  13392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  13393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  13394. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13395. {
  13396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  13397. }
  13398. else
  13399. {
  13400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  13401. }
  13402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  13403. isKnowKey = TRUE;
  13404. }
  13405. /*
  13406. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13407. {
  13408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13410. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13411. {
  13412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13413. }
  13414. else
  13415. {
  13416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13417. }
  13418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13419. isKnowKey = TRUE;
  13420. }*/
  13421. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13422. {
  13423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13425. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13426. {
  13427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13428. }
  13429. else
  13430. {
  13431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13432. }
  13433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13434. isKnowKey = TRUE;
  13435. }
  13436. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13437. {
  13438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13440. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13441. {
  13442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13443. }
  13444. else
  13445. {
  13446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13447. }
  13448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13449. isKnowKey = TRUE;
  13450. }
  13451. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13452. {
  13453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13455. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13456. {
  13457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13458. }
  13459. else
  13460. {
  13461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13462. }
  13463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13464. isKnowKey = TRUE;
  13465. }
  13466. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13467. {
  13468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13470. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13471. {
  13472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13473. }
  13474. else
  13475. {
  13476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13477. }
  13478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13479. isKnowKey = TRUE;
  13480. }
  13481. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13482. {
  13483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13485. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13486. {
  13487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13488. }
  13489. else
  13490. {
  13491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13492. }
  13493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13494. isKnowKey = TRUE;
  13495. }
  13496. #if 1
  13497. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13498. {
  13499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13501. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13502. {
  13503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13504. }
  13505. else
  13506. {
  13507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13508. }
  13509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13510. isKnowKey = TRUE;
  13511. }
  13512. #endif
  13513. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13514. {
  13515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13517. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13518. {
  13519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13520. }
  13521. else
  13522. {
  13523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13524. }
  13525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13526. isKnowKey = TRUE;
  13527. }
  13528. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13529. {
  13530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13532. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13533. {
  13534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13535. }
  13536. else
  13537. {
  13538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13539. }
  13540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13541. isKnowKey = TRUE;
  13542. }
  13543. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13544. {
  13545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13547. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13548. {
  13549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13550. }
  13551. else
  13552. {
  13553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13554. }
  13555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13556. isKnowKey = TRUE;
  13557. }
  13558. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13559. {
  13560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13562. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13563. {
  13564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13565. }
  13566. else
  13567. {
  13568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13569. }
  13570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13571. isKnowKey = TRUE;
  13572. }
  13573. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13574. {
  13575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13577. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13578. {
  13579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13580. }
  13581. else
  13582. {
  13583. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13584. }
  13585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13586. isKnowKey = TRUE;
  13587. }
  13588. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13589. {
  13590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13592. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13593. {
  13594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13595. }
  13596. else
  13597. {
  13598. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13599. }
  13600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13601. isKnowKey = TRUE;
  13602. }
  13603. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13604. {
  13605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13607. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13608. {
  13609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13610. }
  13611. else
  13612. {
  13613. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13614. }
  13615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13616. isKnowKey = TRUE;
  13617. }
  13618. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13619. {
  13620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13622. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13623. {
  13624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13625. }
  13626. else
  13627. {
  13628. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13629. }
  13630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13631. isKnowKey = TRUE;
  13632. }
  13633. //=========================================================
  13634. if(!isEmpty && !isKnowKey)
  13635. {
  13636. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13637. strcpy(unknownkey[UnknownKeynum], keyReq);
  13638. UnknownKeynum = UnknownKeynum + 1;
  13639. }
  13640. }
  13641. void processUnkownKey(void)
  13642. {
  13643. DEBUG_INFO("processUnkownKey...\n");
  13644. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13645. for(int index=0; index < UnknownKeynum; index++)
  13646. {
  13647. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13648. {
  13649. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13650. }
  13651. }
  13652. }
  13653. int setKeyValue(char *key, char *value)
  13654. {
  13655. int isSuccess = NotSupported;
  13656. int check_ascii=0;
  13657. char str[256]={0};
  13658. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13659. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13660. {
  13661. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13662. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13663. {
  13664. strcpy(str, (const char*)value);
  13665. for(int i = 0; str[i]; i++){
  13666. str[i] = tolower(str[i]);
  13667. }
  13668. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13669. isSuccess = ConfigurationStatus_Accepted;
  13670. }
  13671. else
  13672. {
  13673. isSuccess = ConfigurationStatus_Rejected;
  13674. }
  13675. }
  13676. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13677. {
  13678. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13679. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13680. {
  13681. strcpy(str, (const char*)value);
  13682. for(int i = 0; str[i]; i++){
  13683. str[i] = tolower(str[i]);
  13684. }
  13685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13686. isSuccess = ConfigurationStatus_Accepted;
  13687. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13688. }
  13689. else
  13690. {
  13691. isSuccess = ConfigurationStatus_Rejected;
  13692. }
  13693. }
  13694. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13695. {
  13696. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13697. {
  13698. strcpy(str, (const char*)value);
  13699. for(int i = 0; str[i]; i++)
  13700. {
  13701. str[i] = tolower(str[i]);
  13702. }
  13703. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13704. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13705. isSuccess = ConfigurationStatus_Accepted;
  13706. }
  13707. else
  13708. {
  13709. isSuccess = ConfigurationStatus_Rejected;
  13710. }
  13711. }
  13712. if(strcmp(key, "BlinkRepeat") == 0)
  13713. {
  13714. //Charger.BlinkRepeat = Integer.parseInt(value);
  13715. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13716. {
  13717. check_ascii = value[0];
  13718. if( (check_ascii < 48) || (check_ascii > 57) )
  13719. {
  13720. isSuccess = ConfigurationStatus_Rejected;
  13721. }
  13722. else
  13723. {
  13724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13725. isSuccess = ConfigurationStatus_Accepted;
  13726. }
  13727. }
  13728. else
  13729. {
  13730. isSuccess = ConfigurationStatus_Rejected;
  13731. }
  13732. }
  13733. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13734. {
  13735. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13736. {
  13737. check_ascii = value[0];
  13738. if( (check_ascii < 48) || (check_ascii > 57) )
  13739. {
  13740. isSuccess = ConfigurationStatus_Rejected;
  13741. }
  13742. else
  13743. {
  13744. if((atoi(value) == 0) || (atoi(value) >= 10))
  13745. {
  13746. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13747. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13748. isSuccess = ConfigurationStatus_Accepted;
  13749. }
  13750. else
  13751. isSuccess = ConfigurationStatus_Rejected;
  13752. }
  13753. }
  13754. else
  13755. {
  13756. isSuccess = ConfigurationStatus_Rejected;
  13757. }
  13758. }
  13759. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13760. {
  13761. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13762. {
  13763. check_ascii = value[0];
  13764. if( (check_ascii < 48) || (check_ascii > 57) )
  13765. {
  13766. isSuccess = ConfigurationStatus_Rejected;
  13767. }
  13768. else
  13769. {
  13770. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13771. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13772. isSuccess = ConfigurationStatus_Accepted;
  13773. }
  13774. }
  13775. else
  13776. {
  13777. isSuccess = ConfigurationStatus_Rejected;
  13778. }
  13779. }
  13780. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13781. {
  13782. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13783. {
  13784. check_ascii = value[0];
  13785. if( (check_ascii < 48) || (check_ascii > 57) )
  13786. {
  13787. isSuccess = ConfigurationStatus_Rejected;
  13788. }
  13789. else
  13790. {
  13791. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13792. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13793. isSuccess = ConfigurationStatus_Accepted;
  13794. }
  13795. }
  13796. else
  13797. {
  13798. isSuccess = ConfigurationStatus_Rejected;
  13799. }
  13800. }
  13801. if(strcmp(key, "HeartbeatInterval") == 0)
  13802. {
  13803. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13804. {
  13805. check_ascii = value[0];
  13806. if( (check_ascii < 48) || (check_ascii > 57) )
  13807. {
  13808. isSuccess = ConfigurationStatus_Rejected;
  13809. }
  13810. else
  13811. {
  13812. if((atoi(value) == 0) || (atoi(value) >= 10))
  13813. {
  13814. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13815. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13816. HeartBeatWaitTime = atoi(value);
  13817. isSuccess = ConfigurationStatus_Accepted;
  13818. }
  13819. else
  13820. {
  13821. isSuccess = ConfigurationStatus_Rejected;
  13822. }
  13823. }
  13824. }
  13825. else
  13826. {
  13827. isSuccess = ConfigurationStatus_Rejected;
  13828. }
  13829. }
  13830. if(strcmp(key, "LightIntensity") == 0)
  13831. {
  13832. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13833. {
  13834. check_ascii = value[0];
  13835. if( (check_ascii < 48) || (check_ascii > 57) )
  13836. {
  13837. isSuccess = ConfigurationStatus_Rejected;
  13838. }
  13839. else
  13840. {
  13841. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13842. isSuccess = ConfigurationStatus_Accepted;
  13843. }
  13844. }
  13845. else
  13846. {
  13847. isSuccess = ConfigurationStatus_Rejected;
  13848. }
  13849. }
  13850. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13851. {
  13852. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].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 *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13860. isSuccess = ConfigurationStatus_Accepted;
  13861. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13862. }
  13863. else
  13864. {
  13865. isSuccess = ConfigurationStatus_Rejected;
  13866. }
  13867. }
  13868. if(strcmp(key, "LocalPreAuthorize") == 0)
  13869. {
  13870. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13871. {
  13872. strcpy(str, (const char*)value);
  13873. for(int i = 0; str[i]; i++)
  13874. {
  13875. str[i] = tolower(str[i]);
  13876. }
  13877. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13878. isSuccess = ConfigurationStatus_Accepted;
  13879. }
  13880. else
  13881. {
  13882. isSuccess = ConfigurationStatus_Rejected;
  13883. }
  13884. }
  13885. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13886. {
  13887. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13888. {
  13889. check_ascii = value[0];
  13890. if( (check_ascii < 48) || (check_ascii > 57) )
  13891. {
  13892. isSuccess = ConfigurationStatus_Rejected;
  13893. }
  13894. else
  13895. {
  13896. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13897. isSuccess = ConfigurationStatus_Accepted;
  13898. }
  13899. }
  13900. else
  13901. {
  13902. isSuccess = ConfigurationStatus_Rejected;
  13903. }
  13904. }
  13905. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13906. {
  13907. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13908. {
  13909. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13910. isSuccess = ConfigurationStatus_Accepted;
  13911. }
  13912. else
  13913. {
  13914. isSuccess = ConfigurationStatus_Rejected;
  13915. }
  13916. }
  13917. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13918. {
  13919. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13920. {
  13921. check_ascii = value[0];
  13922. if( (check_ascii < 48) || (check_ascii > 57) )
  13923. {
  13924. isSuccess = ConfigurationStatus_Rejected;
  13925. }
  13926. else
  13927. {
  13928. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13929. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13930. isSuccess = ConfigurationStatus_Accepted;
  13931. }
  13932. }
  13933. else
  13934. {
  13935. isSuccess = ConfigurationStatus_Rejected;
  13936. }
  13937. }
  13938. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13939. {
  13940. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13941. {
  13942. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13943. isSuccess = ConfigurationStatus_Accepted;
  13944. }
  13945. else
  13946. {
  13947. isSuccess = ConfigurationStatus_Rejected;
  13948. }
  13949. }
  13950. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13951. {
  13952. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13953. {
  13954. check_ascii = value[0];
  13955. if( (check_ascii < 48) || (check_ascii > 57) )
  13956. {
  13957. isSuccess = ConfigurationStatus_Rejected;
  13958. }
  13959. else
  13960. {
  13961. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13962. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13963. isSuccess = ConfigurationStatus_Accepted;
  13964. }
  13965. }
  13966. else
  13967. {
  13968. isSuccess = ConfigurationStatus_Rejected;
  13969. }
  13970. }
  13971. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13972. {
  13973. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13974. {
  13975. check_ascii = value[0];
  13976. if( (check_ascii < 48) || (check_ascii > 57) )
  13977. {
  13978. isSuccess = ConfigurationStatus_Rejected;
  13979. }
  13980. else
  13981. {
  13982. if((atoi(value) == 0) || (atoi(value) >= 10))
  13983. {
  13984. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13985. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13986. isSuccess = ConfigurationStatus_Accepted;
  13987. }
  13988. else
  13989. {
  13990. isSuccess = ConfigurationStatus_Rejected;
  13991. }
  13992. }
  13993. }
  13994. else
  13995. {
  13996. isSuccess = ConfigurationStatus_Rejected;
  13997. }
  13998. }
  13999. if(strcmp(key, "MinimumStatusDuration") == 0)
  14000. {
  14001. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14002. {
  14003. check_ascii = value[0];
  14004. if( (check_ascii < 48) || (check_ascii > 57) )
  14005. {
  14006. isSuccess = ConfigurationStatus_Rejected;
  14007. }
  14008. else
  14009. {
  14010. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14011. {
  14012. isSuccess = ConfigurationStatus_Rejected;
  14013. }
  14014. else
  14015. {
  14016. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14017. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14018. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14019. isSuccess = ConfigurationStatus_Accepted;
  14020. }
  14021. }
  14022. }
  14023. else
  14024. {
  14025. isSuccess = ConfigurationStatus_Rejected;
  14026. }
  14027. }
  14028. if(strcmp(key, "NumberOfConnectors") == 0)
  14029. {
  14030. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14031. {
  14032. check_ascii = value[0];
  14033. if( (check_ascii < 48) || (check_ascii > 57) )
  14034. {
  14035. isSuccess = ConfigurationStatus_Rejected;
  14036. }
  14037. else
  14038. {
  14039. //Charger.ResetRetries = Integer.parseInt(value);
  14040. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14041. isSuccess = ConfigurationStatus_Accepted;
  14042. }
  14043. }
  14044. else
  14045. {
  14046. isSuccess = ConfigurationStatus_Rejected;
  14047. }
  14048. }
  14049. if(strcmp(key, "ResetRetries") == 0)
  14050. {
  14051. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14052. {
  14053. check_ascii = value[0];
  14054. if( (check_ascii < 48) || (check_ascii > 57) )
  14055. {
  14056. isSuccess = ConfigurationStatus_Rejected;
  14057. }
  14058. else
  14059. {
  14060. //Charger.ResetRetries = Integer.parseInt(value);
  14061. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14062. isSuccess = ConfigurationStatus_Accepted;
  14063. }
  14064. }
  14065. else
  14066. {
  14067. isSuccess = ConfigurationStatus_Rejected;
  14068. }
  14069. }
  14070. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14071. {
  14072. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14073. {
  14074. strcpy(str, (const char*)value);
  14075. for(int i = 0; str[i]; i++)
  14076. {
  14077. str[i] = tolower(str[i]);
  14078. }
  14079. if(strcmp(str, "notapplicable")== 0)
  14080. {
  14081. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14082. isSuccess = ConfigurationStatus_Accepted;
  14083. }
  14084. else if(strcmp(str, "unknown")== 0)
  14085. {
  14086. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14087. isSuccess = ConfigurationStatus_Accepted;
  14088. }
  14089. else if(strcmp(str, "rst")== 0)
  14090. {
  14091. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14092. isSuccess = ConfigurationStatus_Accepted;
  14093. }
  14094. else if(strcmp(str, "rts")== 0)
  14095. {
  14096. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14097. isSuccess = ConfigurationStatus_Accepted;
  14098. }
  14099. else if(strcmp(str, "srt")== 0)
  14100. {
  14101. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14102. isSuccess = ConfigurationStatus_Accepted;
  14103. }
  14104. else if(strcmp(str, "str")== 0)
  14105. {
  14106. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14107. isSuccess = ConfigurationStatus_Accepted;
  14108. }
  14109. else if(strcmp(str, "trs")== 0)
  14110. {
  14111. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14112. isSuccess = ConfigurationStatus_Accepted;
  14113. }
  14114. else if(strcmp(str, "tsr")== 0)
  14115. {
  14116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14117. isSuccess = ConfigurationStatus_Accepted;
  14118. }
  14119. else
  14120. {
  14121. isSuccess = ConfigurationStatus_Rejected;
  14122. }
  14123. }
  14124. else
  14125. {
  14126. isSuccess = ConfigurationStatus_Rejected;
  14127. }
  14128. }
  14129. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14130. {
  14131. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14132. {
  14133. check_ascii = value[0];
  14134. if( (check_ascii < 48) || (check_ascii > 57) )
  14135. {
  14136. isSuccess = ConfigurationStatus_Rejected;
  14137. }
  14138. else
  14139. {
  14140. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14141. isSuccess = ConfigurationStatus_Accepted;
  14142. }
  14143. }
  14144. else
  14145. {
  14146. isSuccess = ConfigurationStatus_Rejected;
  14147. }
  14148. }
  14149. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14150. {
  14151. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14152. {
  14153. strcpy(str, (const char*)value);
  14154. for(int i = 0; str[i]; i++)
  14155. {
  14156. str[i] = tolower(str[i]);
  14157. }
  14158. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14159. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14160. isSuccess = ConfigurationStatus_Accepted;
  14161. }
  14162. else
  14163. {
  14164. isSuccess = ConfigurationStatus_Rejected;
  14165. }
  14166. }
  14167. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14168. {
  14169. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14170. {
  14171. strcpy(str, (const char*)value);
  14172. for(int i = 0; str[i]; i++)
  14173. {
  14174. str[i] = tolower(str[i]);
  14175. }
  14176. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14177. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14178. isSuccess = ConfigurationStatus_Accepted;
  14179. }
  14180. else
  14181. {
  14182. isSuccess = ConfigurationStatus_Rejected;
  14183. }
  14184. }
  14185. if(strcmp(key, "StopTxnAlignedData") == 0)
  14186. {
  14187. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14188. {
  14189. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14190. isSuccess = ConfigurationStatus_Accepted;
  14191. }
  14192. else
  14193. {
  14194. isSuccess = ConfigurationStatus_Rejected;
  14195. }
  14196. }
  14197. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14198. {
  14199. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14200. {
  14201. check_ascii = value[0];
  14202. if( (check_ascii < 48) || (check_ascii > 57) )
  14203. {
  14204. isSuccess = ConfigurationStatus_Rejected;
  14205. }
  14206. else
  14207. {
  14208. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14209. isSuccess = ConfigurationStatus_Accepted;
  14210. }
  14211. }
  14212. else
  14213. {
  14214. isSuccess = ConfigurationStatus_Rejected;
  14215. }
  14216. }
  14217. if(strcmp(key, "StopTxnSampledData") == 0)
  14218. {
  14219. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14220. {
  14221. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14222. isSuccess = ConfigurationStatus_Accepted;
  14223. }
  14224. else
  14225. {
  14226. isSuccess = ConfigurationStatus_Rejected;
  14227. }
  14228. }
  14229. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14230. {
  14231. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14232. {
  14233. check_ascii = value[0];
  14234. if( (check_ascii < 48) || (check_ascii > 57) )
  14235. {
  14236. isSuccess = ConfigurationStatus_Rejected;
  14237. }
  14238. else
  14239. {
  14240. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14241. isSuccess = ConfigurationStatus_Accepted;
  14242. }
  14243. }
  14244. else
  14245. {
  14246. isSuccess = ConfigurationStatus_Rejected;
  14247. }
  14248. }
  14249. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14250. {
  14251. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14252. {
  14253. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14254. isSuccess = ConfigurationStatus_Accepted;
  14255. }
  14256. else
  14257. {
  14258. isSuccess = ConfigurationStatus_Rejected;
  14259. }
  14260. }
  14261. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14262. {
  14263. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14264. {
  14265. check_ascii = value[0];
  14266. if( (check_ascii < 48) || (check_ascii > 57) )
  14267. {
  14268. isSuccess = ConfigurationStatus_Rejected;
  14269. }
  14270. else
  14271. {
  14272. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14273. isSuccess = ConfigurationStatus_Accepted;
  14274. }
  14275. }
  14276. else
  14277. {
  14278. isSuccess = ConfigurationStatus_Rejected;
  14279. }
  14280. }
  14281. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14282. {
  14283. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14284. {
  14285. check_ascii = value[0];
  14286. if( (check_ascii < 48) || (check_ascii > 57) )
  14287. {
  14288. isSuccess = ConfigurationStatus_Rejected;
  14289. }
  14290. else
  14291. {
  14292. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14293. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14294. TransactionMessageAttemptsValue = atoi(value);
  14295. isSuccess = ConfigurationStatus_Accepted;
  14296. }
  14297. }
  14298. else
  14299. {
  14300. isSuccess = ConfigurationStatus_Rejected;
  14301. }
  14302. }
  14303. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14304. {
  14305. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14306. {
  14307. check_ascii = value[0];
  14308. if( (check_ascii < 48) || (check_ascii > 57) )
  14309. {
  14310. isSuccess = ConfigurationStatus_Rejected;
  14311. }
  14312. else
  14313. {
  14314. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14315. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14316. TransactionMessageRetryIntervalValue = atoi(value);
  14317. isSuccess = ConfigurationStatus_Accepted;
  14318. }
  14319. }
  14320. else
  14321. {
  14322. isSuccess = ConfigurationStatus_Rejected;
  14323. }
  14324. }
  14325. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14326. {
  14327. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14328. {
  14329. strcpy(str, (const char*)value);
  14330. for(int i = 0; str[i]; i++)
  14331. {
  14332. str[i] = tolower(str[i]);
  14333. }
  14334. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14335. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14336. isSuccess = ConfigurationStatus_Accepted;
  14337. }
  14338. else
  14339. {
  14340. isSuccess = ConfigurationStatus_Rejected;
  14341. }
  14342. }
  14343. if(strcmp(key, "WebSocketPingInterval") == 0)
  14344. {
  14345. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14346. {
  14347. check_ascii = value[0];
  14348. if( (check_ascii < 48) || (check_ascii > 57) )
  14349. {
  14350. isSuccess = ConfigurationStatus_Rejected;
  14351. }
  14352. else
  14353. {
  14354. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14355. isSuccess = ConfigurationStatus_Accepted;
  14356. }
  14357. }
  14358. else
  14359. {
  14360. isSuccess = ConfigurationStatus_Rejected;
  14361. }
  14362. }
  14363. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  14364. {
  14365. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  14366. {
  14367. strcpy(str, (const char*)value);
  14368. for(int i = 0; str[i]; i++)
  14369. {
  14370. str[i] = tolower(str[i]);
  14371. }
  14372. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14373. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14374. isSuccess = ConfigurationStatus_Accepted;
  14375. }
  14376. else
  14377. {
  14378. isSuccess = ConfigurationStatus_Rejected;
  14379. }
  14380. }
  14381. if(strcmp(key, "AuthorizationKey") == 0)
  14382. {
  14383. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14384. {
  14385. strcpy(str, (const char*)value);
  14386. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14387. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14388. isSuccess = ConfigurationStatus_Accepted;
  14389. }
  14390. else
  14391. {
  14392. isSuccess = ConfigurationStatus_Rejected;
  14393. }
  14394. }
  14395. if(strcmp(key, "SecurityProfile") == 0)
  14396. {
  14397. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14398. {
  14399. check_ascii = value[0];
  14400. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14401. {
  14402. isSuccess = ConfigurationStatus_Rejected;
  14403. }
  14404. else if(check_ascii == 0x33)
  14405. {
  14406. isSuccess = NotSupported;
  14407. }
  14408. else
  14409. {
  14410. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14411. {
  14412. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14413. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14414. isSuccess = ConfigurationStatus_Accepted;
  14415. }
  14416. else
  14417. isSuccess = ConfigurationStatus_Rejected;
  14418. }
  14419. }
  14420. else
  14421. {
  14422. isSuccess = ConfigurationStatus_Rejected;
  14423. }
  14424. }
  14425. if(strcmp(key, "DefaultPrice") == 0)
  14426. {
  14427. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14428. {
  14429. strcpy(str, (const char*)value);
  14430. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14431. isSuccess = ConfigurationStatus_Accepted;
  14432. }
  14433. else
  14434. {
  14435. isSuccess = ConfigurationStatus_Rejected;
  14436. }
  14437. }
  14438. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14439. {
  14440. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14441. {
  14442. strcpy(str, (const char*)value);
  14443. for(int i = 0; str[i]; i++)
  14444. {
  14445. str[i] = tolower(str[i]);
  14446. }
  14447. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14448. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14449. isSuccess = ConfigurationStatus_Accepted;
  14450. }
  14451. else
  14452. {
  14453. isSuccess = ConfigurationStatus_Rejected;
  14454. }
  14455. }
  14456. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14457. {
  14458. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14459. {
  14460. strcpy(str, (const char*)value);
  14461. for(int i = 0; str[i]; i++)
  14462. {
  14463. str[i] = tolower(str[i]);
  14464. }
  14465. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14466. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14467. isSuccess = ConfigurationStatus_Accepted;
  14468. }
  14469. else
  14470. {
  14471. isSuccess = ConfigurationStatus_Rejected;
  14472. }
  14473. }
  14474. #if 0
  14475. //For OCPP Test Case
  14476. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14477. {
  14478. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14479. {
  14480. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14481. isSuccess = ConfigurationStatus_Accepted;
  14482. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14483. }
  14484. else
  14485. {
  14486. isSuccess = ConfigurationStatus_Rejected;
  14487. }
  14488. }
  14489. #endif
  14490. #if 1
  14491. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14492. {
  14493. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14494. {
  14495. strcpy(str, (const char*)value);
  14496. for(int i = 0; str[i]; i++)
  14497. {
  14498. str[i] = tolower(str[i]);
  14499. }
  14500. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14501. isSuccess = ConfigurationStatus_Accepted;
  14502. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14503. }
  14504. else
  14505. {
  14506. isSuccess = ConfigurationStatus_Rejected;
  14507. }
  14508. }
  14509. #endif
  14510. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14511. {
  14512. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14513. {
  14514. check_ascii = value[0];
  14515. if( (check_ascii < 48) || (check_ascii > 57) )
  14516. {
  14517. isSuccess = ConfigurationStatus_Rejected;
  14518. }
  14519. else
  14520. {
  14521. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14522. isSuccess = ConfigurationStatus_Accepted;
  14523. }
  14524. }
  14525. else
  14526. {
  14527. isSuccess = ConfigurationStatus_Rejected;
  14528. }
  14529. }
  14530. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14531. {
  14532. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14533. {
  14534. check_ascii = value[0];
  14535. if( (check_ascii < 48) || (check_ascii > 57) )
  14536. {
  14537. isSuccess = ConfigurationStatus_Rejected;
  14538. }
  14539. else
  14540. {
  14541. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14542. isSuccess = ConfigurationStatus_Accepted;
  14543. }
  14544. }
  14545. else
  14546. {
  14547. isSuccess = ConfigurationStatus_Rejected;
  14548. }
  14549. }
  14550. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14551. {
  14552. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14553. {
  14554. strcpy(str, (const char*)value);
  14555. for(int i = 0; str[i]; i++)
  14556. {
  14557. str[i] = tolower(str[i]);
  14558. }
  14559. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14560. isSuccess = ConfigurationStatus_Accepted;
  14561. }
  14562. else
  14563. {
  14564. isSuccess = ConfigurationStatus_Rejected;
  14565. }
  14566. }
  14567. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14568. {
  14569. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14570. {
  14571. check_ascii = value[0];
  14572. if( (check_ascii < 48) || (check_ascii > 57) )
  14573. {
  14574. isSuccess = ConfigurationStatus_Rejected;
  14575. }
  14576. else
  14577. {
  14578. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14579. isSuccess = ConfigurationStatus_Accepted;
  14580. }
  14581. }
  14582. else
  14583. {
  14584. isSuccess = ConfigurationStatus_Rejected;
  14585. }
  14586. }
  14587. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14588. {
  14589. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14590. {
  14591. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14592. isSuccess = ConfigurationStatus_Accepted;
  14593. }
  14594. else
  14595. {
  14596. isSuccess = ConfigurationStatus_Rejected;
  14597. }
  14598. }
  14599. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14600. {
  14601. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14602. {
  14603. check_ascii = value[0];
  14604. if( (check_ascii < 48) || (check_ascii > 57) )
  14605. {
  14606. isSuccess = ConfigurationStatus_Rejected;
  14607. }
  14608. else
  14609. {
  14610. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14611. isSuccess = ConfigurationStatus_Accepted;
  14612. }
  14613. }
  14614. else
  14615. {
  14616. isSuccess = ConfigurationStatus_Rejected;
  14617. }
  14618. }
  14619. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14620. {
  14621. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14622. {
  14623. strcpy(str, (const char*)value);
  14624. for(int i = 0; str[i]; i++)
  14625. {
  14626. str[i] = tolower(str[i]);
  14627. }
  14628. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14629. isSuccess = ConfigurationStatus_Accepted;
  14630. }
  14631. else
  14632. {
  14633. isSuccess = ConfigurationStatus_Rejected;
  14634. }
  14635. }
  14636. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14637. {
  14638. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14639. {
  14640. check_ascii = value[0];
  14641. if( (check_ascii < 48) || (check_ascii > 57) )
  14642. {
  14643. isSuccess = ConfigurationStatus_Rejected;
  14644. }
  14645. else
  14646. {
  14647. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14648. isSuccess = ConfigurationStatus_Accepted;
  14649. }
  14650. }
  14651. else
  14652. {
  14653. isSuccess = ConfigurationStatus_Rejected;
  14654. }
  14655. }
  14656. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14657. return isSuccess;
  14658. }
  14659. int TransactionMessageAttemptsGet(void)
  14660. {
  14661. return TransactionMessageAttemptsValue;
  14662. }
  14663. int FirstHeartBeatResponse(void)
  14664. {
  14665. return FirstHeartBeat;
  14666. }
  14667. int TransactionMessageRetryIntervalGet(void)
  14668. {
  14669. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14670. }
  14671. int ReadHttpStatus(int sock)
  14672. {
  14673. //char c;
  14674. char buff[1024]="",*ptr=buff+1;
  14675. int bytes_received, status;
  14676. DEBUG_INFO("Begin Response ..\n");
  14677. while((bytes_received = recv(sock, ptr, 1, 0))){
  14678. if(bytes_received==-1){
  14679. perror("ReadHttpStatus");
  14680. exit(1);
  14681. }
  14682. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14683. ptr++;
  14684. }
  14685. *ptr=0;
  14686. ptr=buff+1;
  14687. sscanf(ptr,"%*s %d ", &status);
  14688. DEBUG_INFO("%s\n",ptr);
  14689. DEBUG_INFO("status=%d\n",status);
  14690. DEBUG_INFO("End Response ..\n");
  14691. return (bytes_received>0)?status:0;
  14692. }
  14693. //the only filed that it parsed is 'Content-Length'
  14694. int ParseHeader(int sock)
  14695. {
  14696. //char c;
  14697. char buff[1024]="",*ptr=buff+4;
  14698. int bytes_received;
  14699. DEBUG_INFO("Begin HEADER ..\n");
  14700. while((bytes_received = recv(sock, ptr, 1, 0))){
  14701. if(bytes_received==-1){
  14702. perror("Parse Header");
  14703. exit(1);
  14704. }
  14705. if(
  14706. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14707. (ptr[-1]=='\r') && (*ptr=='\n' )
  14708. ) break;
  14709. ptr++;
  14710. }
  14711. *ptr=0;
  14712. ptr=buff+4;
  14713. //printf("%s",ptr);
  14714. if(bytes_received){
  14715. ptr=strstr(ptr,"Content-Length:");
  14716. if(ptr){
  14717. sscanf(ptr,"%*s %d",&bytes_received);
  14718. }else
  14719. bytes_received=-1; //unknown size
  14720. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14721. }
  14722. DEBUG_INFO("End HEADER ..\n");
  14723. return bytes_received ;
  14724. }
  14725. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14726. {
  14727. int result = TRUE;
  14728. char rmFileCmd[100]={0};
  14729. char FilePath[100]={0};
  14730. char ftpbuf[200];
  14731. int systemresult;
  14732. //DEBUG_INFO("filename=%s\n",filename);
  14733. //DEBUG_INFO("url=%s\n",url);
  14734. sprintf(FilePath,"/mnt/%s",filename);
  14735. system("ping 8.8.8.8 &");
  14736. if((access(FilePath,F_OK))!=-1)
  14737. {
  14738. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14739. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14740. system(rmFileCmd);
  14741. }
  14742. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14743. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14744. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14745. systemresult = system(ftpbuf);
  14746. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14747. if(systemresult != 0)
  14748. {
  14749. DEBUG_INFO("http DownLoad error!\n");
  14750. result = FALSE;
  14751. }
  14752. system("pkill ping");
  14753. return result;
  14754. }
  14755. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14756. {
  14757. int result = TRUE;
  14758. char rmFileCmd[100]={0};
  14759. char FilePath[100]={0};
  14760. char ftpbuf[200];
  14761. int systemresult;
  14762. //char temp[100];
  14763. sprintf(FilePath,"/mnt/%s",filename);
  14764. system("ping 8.8.8.8 &");
  14765. if((access(FilePath,F_OK))!=-1)
  14766. {
  14767. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14768. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14769. system(rmFileCmd);
  14770. }
  14771. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14772. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14773. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14774. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14775. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14776. systemresult = system(ftpbuf);
  14777. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14778. if(systemresult != 0)
  14779. {
  14780. DEBUG_WARN("wget error!\n");
  14781. result = FALSE;
  14782. }
  14783. system("pkill ping");
  14784. return result;
  14785. }
  14786. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14787. {
  14788. char rmFileCmd[100]={0};
  14789. char FilePath[100]={0};
  14790. char buf[512];
  14791. int systemresult = 0;
  14792. //DEBUG_INFO("filename=%s\n",filename);
  14793. //DEBUG_INFO("url=%s\n",url);
  14794. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14795. if((access(FilePath,F_OK))!=-1)
  14796. {
  14797. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14798. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14799. system(rmFileCmd);
  14800. }
  14801. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14802. if(fp == NULL)
  14803. {
  14804. DEBUG_INFO("log is NULL\n");
  14805. return FALSE;
  14806. }
  14807. else
  14808. {
  14809. fprintf(fp, "%s\n", url);
  14810. fprintf(fp, "%s\n", filename);
  14811. fclose(fp);
  14812. }
  14813. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14814. if(phpFP == NULL)
  14815. {
  14816. DEBUG_INFO("PHP upload fail.\n");
  14817. return FALSE;
  14818. }
  14819. else
  14820. {
  14821. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14822. {
  14823. if(strstr(buf, "result") != NULL)
  14824. {
  14825. sscanf(buf, "result: %d", &systemresult);
  14826. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14827. }
  14828. }
  14829. pclose(phpFP);
  14830. }
  14831. if(systemresult != 1)
  14832. {
  14833. DEBUG_INFO("HTTP upload error!\n");
  14834. return FALSE;
  14835. }
  14836. return TRUE;
  14837. }
  14838. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14839. {
  14840. struct hostent* server;
  14841. char *IPbuffer;
  14842. char ftpbuf[200];
  14843. int systemresult;
  14844. // To retrieve host information
  14845. server = gethostbyname(location);
  14846. // To convert an Internet network
  14847. // address into ASCII string
  14848. IPbuffer = inet_ntoa(*((struct in_addr*)
  14849. server->h_addr_list[0]));
  14850. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14851. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14852. /* format : ftpput -u username -p passwd IP target source*/
  14853. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14854. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14855. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14856. systemresult = system(ftpbuf);
  14857. DEBUG_INFO("systemresult=%d\n",systemresult);
  14858. if(systemresult != 0)
  14859. {
  14860. DEBUG_INFO("ftpput error!\n");
  14861. return FALSE;
  14862. }
  14863. return TRUE;
  14864. }
  14865. int GetOcppServerURL()
  14866. {
  14867. int result = FALSE;
  14868. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14869. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14870. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14871. struct yuarel url;
  14872. char urlStr[512];
  14873. // OCPPPH only
  14874. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  14875. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14876. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  14877. {
  14878. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  14879. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14880. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14881. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  14882. if(yuarel_parse(&url, urlStr) != -1)
  14883. {
  14884. sprintf(OcppProtocol, "%s", url.scheme);
  14885. sprintf(OcppHost, "%s", url.host);
  14886. if(url.path == NULL)
  14887. OcppTempPath[0] = '\0';
  14888. else
  14889. sprintf(OcppTempPath, "%s", url.path);
  14890. if(url.port == 0)
  14891. {
  14892. if(strcmp(OcppProtocol, "wss") == 0)
  14893. OcppPort = 443;
  14894. else
  14895. OcppPort = 80;
  14896. }
  14897. else
  14898. OcppPort = url.port;
  14899. result = TRUE;
  14900. }
  14901. }
  14902. else
  14903. {
  14904. strcpy(OcppHost,"");
  14905. }
  14906. return result;
  14907. }
  14908. int GetOcppPath()
  14909. {
  14910. int result = FALSE;
  14911. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  14912. {
  14913. if(OcppTempPath == NULL)
  14914. {
  14915. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  14916. }
  14917. else
  14918. {
  14919. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  14920. }
  14921. result = TRUE;
  14922. goto End;
  14923. }
  14924. else
  14925. {
  14926. strcpy(OcppPath,"");
  14927. }
  14928. End:
  14929. return result;
  14930. }
  14931. int GetOcppPort()
  14932. {
  14933. return OcppPort;
  14934. }
  14935. int GetOcppConnStatus(void)
  14936. {
  14937. return ShmOCPP16DataPH->OcppConnStatus;
  14938. }
  14939. void SetOcppConnStatus(uint8_t status)
  14940. {
  14941. ShmOCPP16DataPH->OcppConnStatus = status;
  14942. }
  14943. int GetHeartBeatWithNOResponse(void)
  14944. {
  14945. return HeartBeatWithNOResponse;
  14946. }
  14947. void SetHeartBeatWithNOResponse(void)
  14948. {
  14949. HeartBeatWithNOResponse = 0;
  14950. }
  14951. void GetStartTransactionIdTag(int gun_index)
  14952. {
  14953. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14954. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14955. }
  14956. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14957. {
  14958. char ch;
  14959. FILE *fptr1;
  14960. int temptransactionId;
  14961. char str[100]={0};
  14962. temptransactionId = 0;
  14963. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14964. {
  14965. DEBUG_INFO("IdTag is empty.\n");
  14966. return temptransactionId;
  14967. }
  14968. /*------ Read the file ----------------*/
  14969. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  14970. if (!fptr1)
  14971. {
  14972. DEBUG_INFO("QueueTransactionId file open error.\n");
  14973. //printf(" File not found or unable to open the input file!!\n");
  14974. return temptransactionId;
  14975. }
  14976. ch=fgetc(fptr1);
  14977. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  14978. rewind(fptr1);
  14979. if(ch!=EOF)
  14980. {
  14981. // printf("%c",ch);
  14982. while (fgets(str, 100, fptr1) != NULL)
  14983. {
  14984. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14985. if(str[0]=='\0')
  14986. {
  14987. break;
  14988. }
  14989. char *revbuf[8] = {0}; // Variable store string split
  14990. int num = 0;// Quantity after string split
  14991. DEBUG_INFO("Transaction queue data= %s\n", str);
  14992. splitstring(str,",",revbuf,&num); // String split
  14993. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14994. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14995. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14996. DEBUG_INFO("------------------------------\n");
  14997. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14998. {
  14999. if(isStopTransaction)
  15000. {
  15001. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15002. {
  15003. temptransactionId = atoi(revbuf[2]);
  15004. //break;
  15005. }
  15006. }
  15007. else
  15008. {
  15009. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15010. {
  15011. temptransactionId = atoi(revbuf[2]);
  15012. //break;
  15013. }
  15014. }
  15015. }
  15016. }
  15017. }
  15018. else
  15019. DEBUG_INFO("EOF\n");
  15020. fclose(fptr1);
  15021. /*------- End of reading ---------------*/
  15022. return temptransactionId;
  15023. }
  15024. void SetTransactionIdZero(int transactionId)
  15025. {
  15026. char ch;
  15027. FILE *fptr1, *fptr2;
  15028. int temptransactionId = 0;
  15029. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  15030. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  15031. if (!fptr1)
  15032. {
  15033. //printf(" File not found or unable to open the input file!!\n");
  15034. return ;
  15035. }
  15036. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15037. if (!fptr2)
  15038. {
  15039. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15040. fclose(fptr1);
  15041. return ;
  15042. }
  15043. ch=fgetc(fptr1);
  15044. rewind(fptr1);
  15045. if(ch!=EOF)
  15046. {
  15047. // copy all contents to the temporary file except the specific line
  15048. while (fgets(str, 100, fptr1) != NULL)
  15049. {
  15050. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15051. if(str[0]=='\0')
  15052. {
  15053. break;
  15054. }
  15055. char *revbuf[8] = {0};
  15056. int num = 0;
  15057. strcpy(strtemp, str);
  15058. splitstring(str,",",revbuf,&num);
  15059. if(revbuf[2][0] != '\0')
  15060. {
  15061. temptransactionId = atoi(revbuf[2]);
  15062. if(transactionId != temptransactionId)
  15063. {
  15064. fprintf(fptr2, "%s\n", strtemp);
  15065. }
  15066. }
  15067. }
  15068. }
  15069. fclose(fptr1);
  15070. fclose(fptr2);
  15071. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  15072. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  15073. /*------ Read the file ----------------*/
  15074. }
  15075. int InternetDisconnect(void)
  15076. {
  15077. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15078. }
  15079. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15080. void storeTempStopTransaction(int gun_index)
  15081. {
  15082. char guid[37]={0};
  15083. int tempIndex = 0;
  15084. char TempStopTransaction[256];
  15085. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15086. DEBUG_INFO("storeTempStopTransaction...\n");
  15087. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15088. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  15089. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15090. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15091. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15092. {
  15093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15094. {
  15095. tempIndex = ((gun_index==2) ? 1: 0);
  15096. }
  15097. else
  15098. {
  15099. tempIndex = gun_index;
  15100. }
  15101. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15102. {
  15103. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15104. {
  15105. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15106. }
  15107. }// END OF CHAdeMO_QUANTITY
  15108. }
  15109. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15110. {
  15111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15112. {
  15113. tempIndex = ((gun_index==2) ? 1: 0);
  15114. }
  15115. else
  15116. {
  15117. tempIndex = gun_index;
  15118. }
  15119. for (int index = 0; index < CCS_QUANTITY; index++)
  15120. {
  15121. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15122. {
  15123. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15124. }
  15125. }// END OF CCS_QUANTITY
  15126. }
  15127. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15128. {
  15129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15130. {
  15131. tempIndex = ((gun_index==2) ? 1: 0);
  15132. }
  15133. else
  15134. {
  15135. tempIndex = gun_index;
  15136. }
  15137. for (int index = 0; index < GB_QUANTITY; index++)
  15138. {
  15139. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15140. {
  15141. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15142. }
  15143. }// END OF GB_QUANTITY
  15144. }
  15145. else if(gunType[gun_index] == GUN_TYPE_DO)
  15146. {
  15147. tempIndex = gun_index;
  15148. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15149. {
  15150. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15151. {
  15152. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15153. }
  15154. }
  15155. }
  15156. else
  15157. {
  15158. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15159. {
  15160. tempIndex = 2;
  15161. }
  15162. else
  15163. {
  15164. tempIndex = gun_index;
  15165. }
  15166. for (int index = 0; index < AC_QUANTITY; index++)
  15167. {
  15168. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15169. {
  15170. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15171. }
  15172. }// END OF AC_QUANTITY
  15173. }
  15174. //Stop Transaction Time
  15175. struct timeval tmnow;
  15176. struct tm *tm;
  15177. char buf[28];//, usec_buf[6];
  15178. gettimeofday(&tmnow, NULL);
  15179. time_t t;
  15180. t = time(NULL);
  15181. /*UTC time and date*/
  15182. tm = gmtime(&t);
  15183. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15184. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  15185. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  15186. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15187. random_uuid(guid);
  15188. /***********************************transactionData******************************************************/
  15189. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15190. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15191. //=================================
  15192. //1. Transaction_Begin
  15193. //=================================
  15194. //============================== Energy.Active.Import.Interval ===========================================
  15195. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15196. {
  15197. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15198. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15199. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15200. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  15201. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15202. 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))
  15203. {
  15204. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15205. }
  15206. else
  15207. {
  15208. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15209. }
  15210. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15211. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15212. }
  15213. //=================================
  15214. //2. Transaction_End
  15215. //=================================
  15216. //2.1====================================== Current.Import L1 ==============================================
  15217. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15218. {
  15219. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15220. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15221. {
  15222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15223. {
  15224. tempIndex = ((gun_index==2) ? 1: 0);
  15225. }
  15226. else
  15227. {
  15228. tempIndex = gun_index;
  15229. }
  15230. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15231. {
  15232. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15233. {
  15234. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15235. }
  15236. }// End of for CHAdeMO_QUANTITY
  15237. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15238. }
  15239. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15240. {
  15241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15242. {
  15243. tempIndex = ((gun_index==2) ? 1: 0);
  15244. }
  15245. else
  15246. {
  15247. tempIndex = gun_index;
  15248. }
  15249. for (int index = 0; index < CCS_QUANTITY; index++)
  15250. {
  15251. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15252. {
  15253. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15254. }
  15255. }// End of for CCS_QUANTITY
  15256. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15257. }
  15258. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15259. {
  15260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15261. {
  15262. tempIndex = ((gun_index==2) ? 1: 0);
  15263. }
  15264. else
  15265. {
  15266. tempIndex = gun_index;
  15267. }
  15268. for (int index = 0; index < GB_QUANTITY; index++)
  15269. {
  15270. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15271. {
  15272. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15273. }
  15274. }// End of for GB_QUANTITY
  15275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15276. }
  15277. else if(gunType[gun_index] == GUN_TYPE_DO)
  15278. {
  15279. tempIndex = gun_index;
  15280. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15281. {
  15282. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15283. {
  15284. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15285. }
  15286. }
  15287. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15288. }
  15289. else
  15290. {
  15291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15292. {
  15293. tempIndex = 2;
  15294. }
  15295. else
  15296. {
  15297. tempIndex = gun_index;
  15298. }
  15299. for (int index = 0; index < AC_QUANTITY; index++)
  15300. {
  15301. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15302. {
  15303. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15304. }
  15305. }// End of for AC_QUANTITY
  15306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15307. }
  15308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15309. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15310. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15311. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15312. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15313. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15314. }
  15315. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15316. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15317. {
  15318. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15319. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15320. {
  15321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15322. {
  15323. tempIndex = ((gun_index==2) ? 1: 0);
  15324. }
  15325. else
  15326. {
  15327. tempIndex = gun_index;
  15328. }
  15329. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15330. {
  15331. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15332. {
  15333. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15334. }
  15335. }// END OF CHAdeMO_QUANTITY
  15336. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15337. }
  15338. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15339. {
  15340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15341. {
  15342. tempIndex = ((gun_index==2) ? 1: 0);
  15343. }
  15344. else
  15345. {
  15346. tempIndex = gun_index;
  15347. }
  15348. for (int index = 0; index < CCS_QUANTITY; index++)
  15349. {
  15350. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15351. {
  15352. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15353. }
  15354. }// END OF CCS_QUANTITY
  15355. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15356. }
  15357. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15358. {
  15359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15360. {
  15361. tempIndex = ((gun_index==2) ? 1: 0);
  15362. }
  15363. else
  15364. {
  15365. tempIndex = gun_index;
  15366. }
  15367. for (int index = 0; index < GB_QUANTITY; index++)
  15368. {
  15369. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15370. {
  15371. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15372. }
  15373. }// END OF GB_QUANTITY
  15374. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15375. }
  15376. else if(gunType[gun_index] == GUN_TYPE_DO)
  15377. {
  15378. tempIndex = gun_index;
  15379. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15380. {
  15381. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15382. {
  15383. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15384. }
  15385. }
  15386. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15387. }
  15388. else
  15389. {
  15390. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15391. {
  15392. tempIndex = 2;
  15393. }
  15394. else
  15395. {
  15396. tempIndex = gun_index;
  15397. }
  15398. for (int index = 0; index < AC_QUANTITY; index++)
  15399. {
  15400. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15401. {
  15402. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15403. }
  15404. }// END OF AC_QUANTITY
  15405. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15406. }
  15407. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15408. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15409. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15410. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15411. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15412. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15413. }
  15414. //2.3====================================== Power.Active.Import =========================================
  15415. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15416. {
  15417. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15418. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15419. {
  15420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15421. {
  15422. tempIndex = ((gun_index==2) ? 1: 0);
  15423. }
  15424. else
  15425. {
  15426. tempIndex = gun_index;
  15427. }
  15428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15429. {
  15430. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15431. {
  15432. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15433. }
  15434. } // End for CHAdeMO_QUANTITY
  15435. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15436. }
  15437. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15438. {
  15439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15440. {
  15441. tempIndex = ((gun_index==2) ? 1: 0);
  15442. }
  15443. else
  15444. {
  15445. tempIndex = gun_index;
  15446. }
  15447. for (int index = 0; index < CCS_QUANTITY; index++)
  15448. {
  15449. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15450. {
  15451. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15452. }
  15453. } // END for CCS_QUANTITY
  15454. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15455. }
  15456. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15457. {
  15458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15459. {
  15460. tempIndex = ((gun_index==2) ? 1: 0);
  15461. }
  15462. else
  15463. {
  15464. tempIndex = gun_index;
  15465. }
  15466. for (int index = 0; index < GB_QUANTITY; index++)
  15467. {
  15468. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15469. {
  15470. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15471. }
  15472. }// END for GB_QUANTITY
  15473. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15474. }
  15475. else if(gunType[gun_index] == GUN_TYPE_DO)
  15476. {
  15477. tempIndex = gun_index;
  15478. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15479. {
  15480. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15481. {
  15482. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15483. }
  15484. }
  15485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15486. }
  15487. else
  15488. {
  15489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15490. {
  15491. tempIndex = 2;
  15492. }
  15493. else
  15494. {
  15495. tempIndex = gun_index;
  15496. }
  15497. for (int index = 0; index < AC_QUANTITY; index++)
  15498. {
  15499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15500. {
  15501. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15502. }
  15503. } // END for AC_QUANTITY
  15504. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15505. }
  15506. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15507. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15508. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15509. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15510. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15511. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15512. }
  15513. //2.4====================================== Voltage L1 ====================================================
  15514. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15515. {
  15516. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15517. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15518. {
  15519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15520. {
  15521. tempIndex = ((gun_index==2) ? 1: 0);
  15522. }
  15523. else
  15524. {
  15525. tempIndex = gun_index;
  15526. }
  15527. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15528. {
  15529. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15530. {
  15531. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15532. }
  15533. } // END OF FOR CHAdeMO_QUANTITY
  15534. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15535. }
  15536. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15537. {
  15538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15539. {
  15540. tempIndex = ((gun_index==2) ? 1: 0);
  15541. }
  15542. else
  15543. {
  15544. tempIndex = gun_index;
  15545. }
  15546. for (int index = 0; index < CCS_QUANTITY; index++)
  15547. {
  15548. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15549. {
  15550. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15551. }
  15552. } // END OF FOR CCS_QUANTITY
  15553. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15554. }
  15555. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15556. {
  15557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15558. {
  15559. tempIndex = ((gun_index==2) ? 1: 0);
  15560. }
  15561. else
  15562. {
  15563. tempIndex = gun_index;
  15564. }
  15565. for (int index = 0; index < GB_QUANTITY; index++)
  15566. {
  15567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15568. {
  15569. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15570. }
  15571. } // END OF FOR GB_QUANTITY
  15572. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15573. }
  15574. else if(gunType[gun_index] == GUN_TYPE_DO)
  15575. {
  15576. tempIndex = gun_index;
  15577. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15578. {
  15579. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15580. {
  15581. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15582. }
  15583. }
  15584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15585. }
  15586. else
  15587. {
  15588. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15589. {
  15590. tempIndex = 2;
  15591. }
  15592. else
  15593. {
  15594. tempIndex = gun_index;
  15595. }
  15596. for (int index = 0; index < AC_QUANTITY; index++)
  15597. {
  15598. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15599. {
  15600. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15601. }
  15602. } // END OF FOR AC_QUANTITY
  15603. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15604. }
  15605. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15608. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15609. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15610. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15611. }
  15612. //2.5============================================== End SoC =========================================================
  15613. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15614. {
  15615. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15616. 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))
  15617. {
  15618. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15619. {
  15620. tempIndex = ((gun_index==2) ? 1: 0);
  15621. }
  15622. else
  15623. {
  15624. tempIndex = gun_index;
  15625. }
  15626. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15627. {
  15628. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15629. {
  15630. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15631. {
  15632. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15633. }
  15634. }
  15635. }
  15636. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15637. {
  15638. for (int index = 0; index < CCS_QUANTITY; index++)
  15639. {
  15640. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15641. {
  15642. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15643. }
  15644. }
  15645. }
  15646. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15647. {
  15648. for (int index = 0; index < GB_QUANTITY; index++)
  15649. {
  15650. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15651. {
  15652. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15653. }
  15654. }
  15655. }
  15656. else if(gunType[gun_index] == GUN_TYPE_DO)
  15657. {
  15658. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15659. {
  15660. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15661. {
  15662. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15663. }
  15664. }
  15665. }
  15666. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15667. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15668. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15669. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15670. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15671. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15672. } // END FOR DC CASE
  15673. }
  15674. //2.6====================================== Current.Import L2 ==============================================
  15675. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15676. {
  15677. // AC 3 phase L2 current
  15678. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15679. {
  15680. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15681. {
  15682. tempIndex = 2;
  15683. }
  15684. else
  15685. {
  15686. tempIndex = gun_index;
  15687. }
  15688. for (int index = 0; index < AC_QUANTITY; index++)
  15689. {
  15690. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15691. {
  15692. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15693. }
  15694. }// End of for AC_QUANTITY
  15695. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15696. }
  15697. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15698. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15699. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15700. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15701. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15702. }
  15703. //2.7====================================== Current.Import L3 ==============================================
  15704. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15705. {
  15706. // AC 3 phase L3 current
  15707. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15708. {
  15709. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15710. {
  15711. tempIndex = 2;
  15712. }
  15713. else
  15714. {
  15715. tempIndex = gun_index;
  15716. }
  15717. for (int index = 0; index < AC_QUANTITY; index++)
  15718. {
  15719. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15720. {
  15721. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15722. }
  15723. }// End of for AC_QUANTITY
  15724. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15725. }
  15726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15727. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15728. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15730. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15731. }
  15732. //2.9====================================== Voltage L2 ====================================================
  15733. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15734. {
  15735. // AC 3 phase L2 volatge
  15736. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15737. {
  15738. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15739. {
  15740. tempIndex = 2;
  15741. }
  15742. else
  15743. {
  15744. tempIndex = gun_index;
  15745. }
  15746. for (int index = 0; index < AC_QUANTITY; index++)
  15747. {
  15748. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15749. {
  15750. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15751. }
  15752. } // END OF FOR AC_QUANTITY
  15753. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15754. }
  15755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15756. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15757. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15758. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15759. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15760. }
  15761. //2.10====================================== Voltage L3 ====================================================
  15762. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15763. {
  15764. // AC 3 phase L3 volatge
  15765. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15766. {
  15767. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15768. {
  15769. tempIndex = 2;
  15770. }
  15771. else
  15772. {
  15773. tempIndex = gun_index;
  15774. }
  15775. for (int index = 0; index < AC_QUANTITY; index++)
  15776. {
  15777. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15778. {
  15779. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15780. }
  15781. } // END OF FOR AC_QUANTITY
  15782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15783. }
  15784. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15786. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15787. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15788. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15789. }
  15790. //====================== Start SoC ================================
  15791. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15792. {
  15793. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15794. 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))
  15795. {
  15796. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15797. {
  15798. tempIndex = ((gun_index==2) ? 1: 0);
  15799. }
  15800. else
  15801. {
  15802. tempIndex = gun_index;
  15803. }
  15804. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15805. {
  15806. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15807. {
  15808. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15809. {
  15810. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15811. }
  15812. }
  15813. }
  15814. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15815. {
  15816. for (int index = 0; index < CCS_QUANTITY; index++)
  15817. {
  15818. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15819. {
  15820. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15821. }
  15822. }
  15823. }
  15824. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15825. {
  15826. for (int index = 0; index < GB_QUANTITY; index++)
  15827. {
  15828. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15829. {
  15830. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15831. }
  15832. }
  15833. }
  15834. else if(gunType[gun_index] == GUN_TYPE_DO)
  15835. {
  15836. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15837. {
  15838. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15839. {
  15840. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15841. }
  15842. }
  15843. }
  15844. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15845. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15847. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15848. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15849. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15850. } // END FOR DC CASE
  15851. }
  15852. //======================================== Message create ==============================================
  15853. json_object *StopTransaction = json_object_new_object();
  15854. json_object *transactionDatas = json_object_new_array();
  15855. json_object *sampledValues = json_object_new_array();
  15856. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  15857. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  15858. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  15859. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  15860. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  15861. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15862. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  15863. {
  15864. json_object *transactionData = json_object_new_object();
  15865. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15866. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15867. {
  15868. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15869. {
  15870. json_object *sampledValue = json_object_new_object();
  15871. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15872. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15873. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15874. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15875. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15876. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15877. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15878. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15879. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15880. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15881. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15882. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15883. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15884. json_object_array_add(sampledValues, sampledValue);
  15885. }
  15886. }
  15887. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15888. json_object_array_add(transactionDatas, transactionData);
  15889. }
  15890. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15891. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15892. ,MESSAGE_TYPE_CALL
  15893. ,guid
  15894. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15895. json_object_put(StopTransaction);
  15896. // Check File "TempStopTransaction" Exist
  15897. if((access(TempStopTransaction,F_OK))!=-1)
  15898. {
  15899. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15900. fclose(fopen(TempStopTransaction, "w"));
  15901. }
  15902. else
  15903. {
  15904. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15905. FILE *log = fopen(TempStopTransaction, "w+");
  15906. if(log == NULL)
  15907. {
  15908. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15909. return ;
  15910. }
  15911. else
  15912. {
  15913. fclose(log);
  15914. }
  15915. }
  15916. //Add TempStopTransaction | Update TempStopTransaction
  15917. // open file for writing
  15918. FILE *outfile;
  15919. outfile = fopen (TempStopTransaction, "a");
  15920. //DEBUG_INFO("data = %s\n", queuedata);
  15921. fputs(queuedata, outfile);
  15922. fputs("\n", outfile);
  15923. fclose (outfile);
  15924. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15925. }
  15926. void checkTempStopTransaction(int gun_index)
  15927. {
  15928. FILE *fptr1;
  15929. char ch;
  15930. char str[QUEUE_MESSAGE_LENGTH]={0};
  15931. char guid[37]={0};
  15932. char tempdata[65]={0};
  15933. char connectorStr[2]={0};
  15934. char TempStopTransaction[256];
  15935. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15936. fptr1 = fopen(TempStopTransaction, "r");
  15937. //TempStopTransaction格式: 槍號,StopTransaction封包
  15938. if (!fptr1)
  15939. {
  15940. //printf(" File not found or unable to open the input file!!\n");
  15941. return ;
  15942. }
  15943. ch=fgetc(fptr1);
  15944. //printf(" Now the content of the file %s is : \n",fname);
  15945. rewind(fptr1);
  15946. if(ch!=EOF)
  15947. {
  15948. // copy all contents to the temporary file except the specific line
  15949. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15950. {
  15951. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15952. if(str[0]=='\0')
  15953. {
  15954. break;
  15955. }
  15956. //TempStopTransaction格式: 槍號,StopTransaction封包
  15957. strncpy(connectorStr, str, 1);
  15958. if(atoi(connectorStr) != (gun_index+1))
  15959. {
  15960. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15961. fclose(fptr1);
  15962. return ;
  15963. }
  15964. //random_uuid(guid);
  15965. strncpy(guid, str+6, 36); //copy guid
  15966. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15967. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15968. {
  15969. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15970. }
  15971. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15972. OCPP_insert_transaction_msg(NO, str);
  15973. memset(str,0,ARRAY_SIZE(str));
  15974. }
  15975. }
  15976. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15977. fclose(fptr1);
  15978. remove(TempStopTransaction); // remove the original file
  15979. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15980. }
  15981. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15982. {
  15983. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15984. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15985. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15986. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15987. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15988. }
  15989. int GetWebSocketPingInterval(void)
  15990. {
  15991. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15992. }
  15993. int GetServerSign(void)
  15994. {
  15995. return server_sign;
  15996. }
  15997. uint8_t GetOcppSecurityProfile()
  15998. {
  15999. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16000. }
  16001. void GetOcppChargerBoxId(uint8_t *data)
  16002. {
  16003. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  16004. }
  16005. void GetOcppSecurityPassword(uint8_t *data)
  16006. {
  16007. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16008. }
  16009. void SetOcppVersion(uint8_t *version)
  16010. {
  16011. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16012. DEBUG_INFO("ocpp version: %s\n", version);
  16013. if(strstr((char*)version, "ocpp1.6") != NULL)
  16014. {
  16015. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16016. }
  16017. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16018. {
  16019. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16020. system("pkill OcppBackend");
  16021. }
  16022. }
  16023. void SetServerSign(int value)
  16024. {
  16025. server_sign = value;
  16026. }
  16027. int GetBootNotificationInterval(void)
  16028. {
  16029. return BootNotificationInterval;
  16030. }
  16031. int GetInternetConn(void)
  16032. {
  16033. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16034. }
  16035. int GetBackendConnectionTimeout(void)
  16036. {
  16037. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16038. }
  16039. int isConnectorInitMode(int gun_index)
  16040. {
  16041. int tempIndex = 0;
  16042. int result = TRUE;
  16043. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16044. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16045. {
  16046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16047. {
  16048. tempIndex = ((gun_index==2) ? 1: 0);
  16049. }
  16050. else
  16051. {
  16052. tempIndex = gun_index;
  16053. }
  16054. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16055. {
  16056. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16057. {
  16058. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16059. } //end of the same index
  16060. }//end of for CHAdeMO_QUANTITY
  16061. }
  16062. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16063. {
  16064. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16065. {
  16066. tempIndex = ((gun_index==2) ? 1: 0);
  16067. }
  16068. else
  16069. {
  16070. tempIndex = gun_index;
  16071. }
  16072. for (int index = 0; index < CCS_QUANTITY; index++)
  16073. {
  16074. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16075. {
  16076. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16077. } //end of the same index
  16078. } // end of for CCS_QUANTITY
  16079. }
  16080. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16081. {
  16082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16083. {
  16084. tempIndex = ((gun_index==2) ? 1: 0);
  16085. }
  16086. else
  16087. {
  16088. tempIndex = gun_index;
  16089. }
  16090. for (int index = 0; index < GB_QUANTITY; index++)
  16091. {
  16092. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16093. {
  16094. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16095. } //end of the same index
  16096. } // end of for GB_QUANTITY
  16097. }
  16098. else if(gunType[gun_index] == GUN_TYPE_DO)
  16099. {
  16100. tempIndex = gun_index;
  16101. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16102. {
  16103. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16104. {
  16105. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16106. } //end of the same index
  16107. }
  16108. }
  16109. else
  16110. {
  16111. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16112. {
  16113. tempIndex = 2;
  16114. }
  16115. else
  16116. {
  16117. tempIndex = gun_index;
  16118. }
  16119. for (int index = 0; index < AC_QUANTITY; index++)
  16120. {
  16121. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16122. {
  16123. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16124. }//end of the same index
  16125. }//end of for AC_QUANTITY
  16126. }
  16127. return result;
  16128. }
  16129. void refreshProcDogTimer()
  16130. {
  16131. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  16132. }
  16133. void InitialSystemValue(void)
  16134. {
  16135. int connectorIndex = 0;
  16136. //int valueASCII = 0;
  16137. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16138. gunTotalNumber=0;
  16139. SystemInitial = 0;
  16140. locallistVersion=0;
  16141. BootNotificationInterval = 0;
  16142. authorizeRetryTimes = 0;
  16143. GunStatusInterval = 10;
  16144. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16145. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16146. //Hear Beat
  16147. HeartBeatWithNOResponse = 0;
  16148. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16149. FirstHeartBeat = 0;
  16150. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16151. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16152. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16153. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16154. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16155. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16156. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16157. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16158. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16159. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16160. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16161. memset(gunType, 0, ARRAY_SIZE(gunType));
  16162. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16163. {
  16164. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16165. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16166. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16167. {
  16168. // DO series
  16169. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16170. {
  16171. SystemInitial = SystemInitial + 1;
  16172. gunTotalNumber = gunTotalNumber + 1;
  16173. gunType[connectorIndex] = GUN_TYPE_DO;
  16174. connectorIndex = connectorIndex + 1;
  16175. }
  16176. }
  16177. else
  16178. {
  16179. // DM, DW, DS series
  16180. //check connector / socket type (index: 8, 9, 10)
  16181. for(int index=7; index <10 ; index++)
  16182. {
  16183. if(index != 8)
  16184. {
  16185. // DC Connector
  16186. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16187. {
  16188. SystemInitial = SystemInitial + 1;
  16189. gunTotalNumber = gunTotalNumber + 1;
  16190. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16191. connectorIndex = connectorIndex + 1;
  16192. }
  16193. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16194. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16195. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16196. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16197. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16198. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16199. {
  16200. SystemInitial = SystemInitial + 1;
  16201. gunTotalNumber = gunTotalNumber + 1;
  16202. gunType[connectorIndex] = GUN_TYPE_CCS;
  16203. connectorIndex = connectorIndex + 1;
  16204. }
  16205. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16206. {
  16207. SystemInitial = SystemInitial + 1;
  16208. gunTotalNumber = gunTotalNumber + 1;
  16209. gunType[connectorIndex] = GUN_TYPE_GBT;
  16210. connectorIndex = connectorIndex + 1;
  16211. }
  16212. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16213. {
  16214. SystemInitial = SystemInitial + 1;
  16215. gunTotalNumber = gunTotalNumber + 1;
  16216. gunType[connectorIndex] = GUN_TYPE_DO;
  16217. connectorIndex = connectorIndex + 1;
  16218. }
  16219. }
  16220. else
  16221. {
  16222. // AC Connector
  16223. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16224. {
  16225. SystemInitial = SystemInitial + 1;
  16226. gunTotalNumber = gunTotalNumber + 1;
  16227. gunType[connectorIndex] = GUN_TYPE_AC;
  16228. connectorIndex = connectorIndex + 1;
  16229. }
  16230. }
  16231. }
  16232. }
  16233. //DEBUG_INFO("DC ...\n");
  16234. }
  16235. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16236. {
  16237. //check connector / socket type (index: 8, 9, 10)
  16238. for(int index=7; index <10 ; index++)
  16239. {
  16240. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16241. {
  16242. SystemInitial = SystemInitial + 1;
  16243. gunTotalNumber = gunTotalNumber + 1;
  16244. gunType[connectorIndex] = GUN_TYPE_AC;
  16245. connectorIndex = connectorIndex + 1;
  16246. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16247. }
  16248. }
  16249. }
  16250. //Status && ConnectorPlugIn Setting
  16251. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16252. {
  16253. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16254. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16255. }
  16256. for (int index = 0; index < CCS_QUANTITY; index++)
  16257. {
  16258. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16259. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16260. }
  16261. for (int index = 0; index < GB_QUANTITY; index++)
  16262. {
  16263. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16264. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16265. }
  16266. for (int index = 0; index < AC_QUANTITY; index++)
  16267. {
  16268. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16269. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16270. }
  16271. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16272. {
  16273. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16274. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16275. }
  16276. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16277. {
  16278. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16279. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16280. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16281. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16282. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16283. }
  16284. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16285. clientTime.Heartbeat=time((time_t*)NULL);
  16286. sleep(1);
  16287. }
  16288. void LWS_Send(char *str)
  16289. {
  16290. //=====================================================
  16291. // Check InternetConn 0: disconnected, 1: connected
  16292. //====================================================
  16293. if(GetOcppConnStatus() == 0)
  16294. {
  16295. DEBUG_INFO("offline now !!!\n");
  16296. return;
  16297. }
  16298. // Only disable isWebsocketSendable operation initiated by charger
  16299. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16300. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16301. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16302. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16303. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16304. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16305. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16306. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16307. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16308. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16309. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16310. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16311. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16312. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16313. {
  16314. isWebsocketSendable = 0;
  16315. }
  16316. pthread_mutex_lock(&lock_send);
  16317. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16318. sprintf((char *)SendBuffer, "%s", str);
  16319. SendBufLen = strlen(str);
  16320. pthread_mutex_unlock(&lock_send);
  16321. lws_callback_on_writable(wsi_client);
  16322. //lws_service(context, 0);
  16323. //sleep(1);
  16324. }
  16325. void LWS_SendNow(char *str)
  16326. {
  16327. //=====================================================
  16328. // Check InternetConn 0: disconnected, 1: connected
  16329. //====================================================
  16330. if(GetOcppConnStatus() == 0)
  16331. {
  16332. DEBUG_INFO("offline now !!!\n");
  16333. return;
  16334. }
  16335. // Only disable isWebsocketSendable operation initiated by charger
  16336. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16337. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16338. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16339. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16340. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16341. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16342. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16343. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16344. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16345. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16346. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16347. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16348. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16349. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16350. {
  16351. isWebsocketSendable = 0;
  16352. }
  16353. pthread_mutex_lock(&lock_send);
  16354. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16355. sprintf((char *)SendBuffer, "%s", str);
  16356. SendBufLen = strlen(str);
  16357. pthread_mutex_unlock(&lock_send);
  16358. lws_callback_on_writable(wsi_client);
  16359. lws_service(context, 0);
  16360. //sleep(1);
  16361. }