MessageHandler.c 1008 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  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. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = FALSE;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  54. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t Connector0PreviousSystemStatus;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. //============================================
  91. // OCPP California Pricing Requirements
  92. //============================================
  93. static char dmsVersion[21] = {0};
  94. extern sqlite3 *db;
  95. int TransactionMessageAttemptsGet(void);
  96. int TransactionMessageRetryIntervalGet(void);
  97. int GetOcppConnStatus(void);
  98. void SetOcppConnStatus(uint8_t status);
  99. int setKeyValue(char *key, char *value);
  100. void OCPP_get_TableAuthlocalAllData(void);
  101. void processUnkownKey(void);
  102. struct InterLock
  103. {
  104. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  105. unsigned char isGetDiagnosticGoing:1;
  106. unsigned char isUpdateFirmwareGoing:1;
  107. }interLock;
  108. struct ClientTime
  109. {
  110. struct timespec Heartbeat;
  111. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  112. struct timespec StartTransaction;
  113. struct timespec StopTransaction;
  114. struct timespec MeterValues[CONNECTOR_QUANTITY];
  115. struct timespec RemoteStartWait;
  116. struct timespec TcciQueryDeduct;
  117. struct timespec TcciQueryOccupancyDeduct;
  118. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  119. }clientTime;
  120. typedef union
  121. {
  122. //Operations Initiated by Central System
  123. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  124. struct
  125. {
  126. //CsMsgValue[0]
  127. unsigned char StatusNotificationReq:1; //bit 0,
  128. unsigned char StatusNotificationConf:1; //bit 1,
  129. unsigned char TriggerMeterValue:1; //bit 2,
  130. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  131. unsigned char isOnCharging:1; //bit 4,
  132. unsigned char :3; //bit5~7
  133. }bits[CONNECTOR_QUANTITY];
  134. }CpinitiateMsg;
  135. CpinitiateMsg cpinitateMsg;
  136. //GetConfiguration Array
  137. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  138. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  139. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  140. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  141. static char *ChargePointErrorCodeStr[] = {
  142. MACROSTR(ConnectorLockFailure),
  143. MACROSTR(EVCommunicationError),
  144. MACROSTR(GroundFailure),
  145. MACROSTR(HighTemperature),
  146. MACROSTR(InternalError),
  147. MACROSTR(LocalListConflict),
  148. MACROSTR(NoError),
  149. MACROSTR(OtherError),
  150. MACROSTR(OverCurrentFailure),
  151. MACROSTR(OverVoltage),
  152. MACROSTR(PowerMeterFailure),
  153. MACROSTR(PowerSwitchFailure),
  154. MACROSTR(ReaderFailure),
  155. MACROSTR(ResetFailure),
  156. MACROSTR(UnderVoltage),
  157. MACROSTR(WeakSignal)
  158. };
  159. static char * ChargePointStatusStr[] = {
  160. MACROSTR(Available),
  161. MACROSTR(Preparing),
  162. MACROSTR(Charging),
  163. MACROSTR(SuspendedEVSE),
  164. MACROSTR(SuspendedEV),
  165. MACROSTR(Finishing),
  166. MACROSTR(Reserved),
  167. MACROSTR(Unavailable),
  168. MACROSTR(Faulted)
  169. };
  170. static char *RegistrationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Pending),
  173. MACROSTR(Rejected)
  174. };
  175. static char *AvailabilityTypeStr[] = {
  176. MACROSTR(Inoperative),
  177. MACROSTR(Operative)
  178. };
  179. static char *AvailabilityStatusStr[] = {
  180. MACROSTR(Accepted),
  181. MACROSTR(Rejected),
  182. MACROSTR(Scheduled)
  183. };
  184. static char *ConfigurationStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(RebootRequired),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearCacheStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Rejected)
  193. };
  194. static char *ChargingProfilePurposeTypeStr[] = {
  195. MACROSTR(ChargePointMaxProfile),
  196. MACROSTR(TxDefaultProfile),
  197. MACROSTR(TxProfile)
  198. };
  199. static char *ChargingProfileStatusStr[] = {
  200. MACROSTR(Accepted),
  201. MACROSTR(Rejected),
  202. MACROSTR(NotSupported)
  203. };
  204. static char *ClearChargingProfileStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Unknown)
  207. };
  208. static char *GetCompositeScheduleStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *UpdateTypeStr[] = {
  213. MACROSTR(Differential),
  214. MACROSTR(Full)
  215. };
  216. static char *UpdateStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Failed),
  219. MACROSTR(NotSupported),
  220. MACROSTR(VersionMismatch)
  221. };
  222. static char *RemoteStartStopStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char *ReservationStatusStr[] = {
  227. MACROSTR(Accepted),
  228. MACROSTR(Faulted),
  229. MACROSTR(Occupied),
  230. MACROSTR(Rejected),
  231. MACROSTR(Unavailable)
  232. };
  233. static char *ResetTypeStr[] = {
  234. MACROSTR(Hard),
  235. MACROSTR(Soft)
  236. };
  237. static char *ResetStatusStr[] = {
  238. MACROSTR(Accepted),
  239. MACROSTR(Rejected)
  240. };
  241. static char * DiagnosticsStatusStr[] = {
  242. MACROSTR(Idle),
  243. MACROSTR(Uploaded),
  244. MACROSTR(UploadFailed),
  245. MACROSTR(Uploading)
  246. };
  247. static char * FirmwareStatusStr[] = {
  248. MACROSTR(Downloaded),
  249. MACROSTR(DownloadFailed),
  250. MACROSTR(Downloading),
  251. MACROSTR(Idle),
  252. MACROSTR(InstallationFailed),
  253. MACROSTR(Installing),
  254. MACROSTR(Installed)
  255. };
  256. static char * MessageTriggerStr[] = {
  257. MACROSTR(BootNotification),
  258. MACROSTR(DiagnosticsStatusNotification),
  259. MACROSTR(FirmwareStatusNotification),
  260. MACROSTR(Heartbeat),
  261. MACROSTR(MeterValues),
  262. MACROSTR(StatusNotification)
  263. };
  264. static char * TriggerMessageStatusStr[] = {
  265. MACROSTR(Accepted),
  266. MACROSTR(Rejected),
  267. MACROSTR(NotImplemented)
  268. };
  269. static char * UnlockStatusStr[] = {
  270. MACROSTR(Unlocked),
  271. MACROSTR(UnlockFailed),
  272. MACROSTR(NotSupported)
  273. };
  274. #if 0
  275. static char * StopTransactionReasonStr[] = {
  276. MACROSTR(EmergencyStop),
  277. MACROSTR(EVDisconnected),
  278. MACROSTR(HardReset),
  279. MACROSTR(Local),
  280. MACROSTR(Other),
  281. MACROSTR(PowerLoss),
  282. MACROSTR(Reboot),
  283. MACROSTR(Remote),
  284. MACROSTR(SoftReset),
  285. MACROSTR(UnlockCommand),
  286. MACROSTR(DeAuthorized)
  287. };
  288. #endif
  289. static char * CancelReservationStatusStr[] = {
  290. MACROSTR(Accepted),
  291. MACROSTR(Rejected)
  292. };
  293. static char * ReadingContextStr[] = {
  294. MACROSTR(Interruption.Begin),
  295. MACROSTR(Interruption.End),
  296. MACROSTR(Other),
  297. MACROSTR(Sample.Clock),
  298. MACROSTR(Sample.Periodic),
  299. MACROSTR(Transaction.Begin),
  300. MACROSTR(Transaction.End),
  301. MACROSTR(Trigger)
  302. };
  303. static char * ValueFormatStr[] = {
  304. MACROSTR(Raw),
  305. MACROSTR(SignedData)
  306. };
  307. static char * MeasurandStr[] = {
  308. MACROSTR(Current.Export),
  309. MACROSTR(Current.Import),
  310. MACROSTR(Current.Offered),
  311. MACROSTR(Energy.Active.Export.Register),
  312. MACROSTR(Energy.Active.Import.Register),
  313. MACROSTR(Energy.Reactive.Export.Register),
  314. MACROSTR(Energy.Reactive.Import.Register),
  315. MACROSTR(Energy.Active.Export.Interval),
  316. MACROSTR(Energy.Active.Import.Interval),
  317. MACROSTR(Energy.Reactive.Export.Interval),
  318. MACROSTR(Energy.Reactive.Import.Interval),
  319. MACROSTR(Frequency),
  320. MACROSTR(Power.Active.Export),
  321. MACROSTR(Power.Active.Import),
  322. MACROSTR(Power.Factor),
  323. MACROSTR(Power.Offered),
  324. MACROSTR(Power.Reactive.ExportMACROSTR),
  325. MACROSTR(Power.Reactive.Import),
  326. MACROSTR(RPM),
  327. MACROSTR(SoC),
  328. MACROSTR(Temperature),
  329. MACROSTR(Voltage)
  330. };
  331. static char * LocationStr[] = {
  332. MACROSTR(Body),
  333. MACROSTR(Cable),
  334. MACROSTR(EV),
  335. MACROSTR(Inlet),
  336. MACROSTR(Outlet)
  337. };
  338. static char * PhaseStr[] = {
  339. MACROSTR(L1),
  340. MACROSTR(L2),
  341. MACROSTR(L3),
  342. MACROSTR(N),
  343. MACROSTR(L1-N),
  344. MACROSTR(L2-N),
  345. MACROSTR(L3-N),
  346. MACROSTR(L1-L2),
  347. MACROSTR(L2-L3),
  348. MACROSTR(L3-L1)
  349. };
  350. static char * UnitOfMeasureStr[] = {
  351. MACROSTR(Wh),
  352. MACROSTR(kWh),
  353. MACROSTR(varh),
  354. MACROSTR(kvarh),
  355. MACROSTR(W),
  356. MACROSTR(kW),
  357. MACROSTR(VA),
  358. MACROSTR(kVA),
  359. MACROSTR(var),
  360. MACROSTR(kvar),
  361. MACROSTR(A),
  362. MACROSTR(V),
  363. MACROSTR(Celsius),
  364. MACROSTR(Fahrenheit),
  365. MACROSTR(K),
  366. MACROSTR(Percent)
  367. };
  368. //=========================================
  369. // Meter buffer process
  370. //=========================================
  371. int meterValueBufferDataQuantity(uint8_t gun_index, ReadingContext dataType)
  372. {
  373. uint32_t result = 0;
  374. char sqlCmd[8192];
  375. char zErrMsg[200];
  376. int rows, cols;
  377. char **resultData;
  378. sprintf(sqlCmd, "select count(idx) as dataQuantity from meterValuesBuffer where gun_index='%d' and ReadingContext='%d' order by ReadingContext, idx", gun_index, (dataType==ReadingContext_Sample_Periodic?0:1));
  379. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  380. {
  381. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  382. }
  383. else
  384. {
  385. if(rows >= 1)
  386. {
  387. result = atoi(resultData[1]);
  388. }
  389. }
  390. return result;
  391. }
  392. int meterValueBufferClear(uint8_t gun_index)
  393. {
  394. int result = PASS;
  395. char sqlCmd[512];
  396. char *errMsg = 0;
  397. sprintf(sqlCmd, "delete from meterValuesBuffer where gun_index=%d", gun_index);
  398. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  399. {
  400. DEBUG_INFO("SQL error: %s\n",errMsg);
  401. result = FAIL;
  402. }
  403. return result;
  404. }
  405. int meterValueBufferInsert(uint8_t gun_index, ReadingContext dataType, uint32_t transactionId, char *meterValue)
  406. {
  407. int result = PASS;
  408. char sqlCmd[8192];
  409. char *errMsg = 0;
  410. sprintf(sqlCmd, "insert into meterValuesBuffer(occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values(CURRENT_TIMESTAMP, '%d', '%d','%d','%s')", gun_index
  411. , transactionId
  412. , (dataType==ReadingContext_Sample_Periodic?0:1)
  413. , meterValue);
  414. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  415. {
  416. result = FAIL;
  417. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  418. }
  419. return result;
  420. }
  421. int meterValueBufferReplace(int bufferIdx, uint8_t gun_index, ReadingContext dataType, uint32_t transactionId, char *meterValue)
  422. {
  423. int result = PASS;
  424. char sqlCmd[8192];
  425. char *errMsg = 0;
  426. sprintf(sqlCmd, "replace into meterValuesBuffer(idx, occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values('%d', CURRENT_TIMESTAMP, '%d', '%d','%d','%s')", bufferIdx
  427. , gun_index
  428. , transactionId
  429. , (dataType==ReadingContext_Sample_Periodic?0:1)
  430. , meterValue);
  431. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  432. {
  433. result = FAIL;
  434. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  435. }
  436. return result;
  437. }
  438. int meterValueBufferQuery(uint8_t gun_index, json_object *MeterValues)
  439. {
  440. int result = PASS;
  441. char sqlCmd[8192];
  442. char zErrMsg[200];
  443. int rows, cols;
  444. char **resultData;
  445. sprintf(sqlCmd, "select * from meterValuesBuffer where gun_index='%d' order by ReadingContext, idx", gun_index);
  446. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  447. {
  448. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  449. result = FAIL;
  450. }
  451. else
  452. {
  453. for(uint32_t idxRow=1;idxRow<=rows;idxRow++)
  454. {
  455. json_object *MeterValue = json_tokener_parse(resultData[(idxRow*cols)+5]);
  456. json_object_array_add(MeterValues, MeterValue);
  457. }
  458. }
  459. return result;
  460. }
  461. //=========================================
  462. // Certificate related routine
  463. //=========================================
  464. int certVerify(char *privateKey, char *cert)
  465. {
  466. int result = PASS;
  467. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  468. // Load certificate file
  469. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  470. {
  471. DEBUG_ERROR("Load certificate error!\n");
  472. result = FAIL;
  473. }
  474. // Load private key file
  475. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  476. {
  477. DEBUG_ERROR("Load private key error!\n");
  478. result = FAIL;
  479. }
  480. if(!SSL_CTX_check_private_key(ctx))
  481. {
  482. result = FAIL;
  483. }
  484. SSL_CTX_free(ctx);
  485. return result;
  486. }
  487. //=========================================
  488. // TTIA routine
  489. //=========================================
  490. int sendTTIAInfo(uint8_t gun_index)
  491. {
  492. static int sn = 0;
  493. int result = FAIL;
  494. struct hostent *server;
  495. int udp_socket_fd;
  496. struct sockaddr_in dest_addr = {0};
  497. uint8_t tx_buf[80] = {0};
  498. uint8_t logBuf[256]= {0};
  499. uint8_t tx_len, tempIndex, socStart, socEnd;
  500. uint16_t PresentChargedEnergy;
  501. struct tm tmStart, tmEnd;
  502. DEBUG_INFO("sendTTIAInfo...\n");
  503. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  504. {
  505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  506. {
  507. tempIndex = ((gun_index==2) ? 1: 0);
  508. }
  509. else
  510. {
  511. tempIndex = gun_index;
  512. }
  513. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  514. {
  515. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  516. {
  517. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  518. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  519. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  520. }
  521. }
  522. }
  523. else if(gunType[gun_index] == GUN_TYPE_CCS)
  524. {
  525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  526. {
  527. tempIndex = ((gun_index==2) ? 1: 0);
  528. }
  529. else
  530. {
  531. tempIndex = gun_index;
  532. }
  533. for (int index = 0; index < CCS_QUANTITY; index++)
  534. {
  535. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  536. {
  537. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  538. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  539. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  540. }
  541. }
  542. }
  543. else if(gunType[gun_index] == GUN_TYPE_GBT)
  544. {
  545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  546. {
  547. tempIndex = ((gun_index==2) ? 1: 0);
  548. }
  549. else
  550. {
  551. tempIndex = gun_index;
  552. }
  553. for (int index = 0; index < GB_QUANTITY; index++)
  554. {
  555. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  556. {
  557. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  558. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  559. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  560. }
  561. }
  562. }
  563. else if(gunType[gun_index] == GUN_TYPE_DO)
  564. {
  565. tempIndex = gun_index;
  566. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  567. {
  568. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  569. {
  570. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  571. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  572. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  573. }
  574. }
  575. }
  576. else
  577. {
  578. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  579. {
  580. tempIndex = 2;
  581. }
  582. else
  583. {
  584. tempIndex = gun_index;
  585. }
  586. for (int index = 0; index < AC_QUANTITY; index++)
  587. {
  588. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  589. {
  590. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  591. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  592. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  593. }
  594. }// END
  595. }
  596. // Message assembly
  597. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  598. tx_buf[4] = 0x02; // Protocol Version
  599. tx_buf[5] = 0xb0; // Message ID
  600. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  601. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  602. tx_buf[8] = 0x00; // CarID low byte
  603. tx_buf[9] = 0x00; // CarID high byte
  604. tx_buf[10] = 0x00; // ID Storage
  605. tx_buf[11] = 0x00; // Driver lowest byte
  606. tx_buf[12] = 0x00; // Driver 2nd byte
  607. tx_buf[13] = 0x00; // Driver 3rd byte
  608. tx_buf[14] = 0x00; // Driver highest byte
  609. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  610. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  611. tx_buf[17] = 0x00; // Reserve
  612. tx_buf[18] = 60 & 0xff; // Payload length low byte
  613. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  614. // EVSE provider
  615. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  616. // EVSE provider
  617. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  618. // EVSE id
  619. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  620. // Connector id
  621. tx_buf[37] = gun_index;
  622. // EVSE station
  623. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  624. // Vehicle SN
  625. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  626. // Mileage
  627. tx_buf[61] = 0x00; // lowest byte
  628. tx_buf[62] = 0x00; // 2nd byte
  629. tx_buf[63] = 0x00; // highest byte
  630. // Start date time 6 bytes
  631. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%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))
  632. {
  633. struct tm *tmTarget;
  634. struct timeb tbTarget;
  635. tmStart.tm_year -= 1900;
  636. tmStart.tm_mon -= 1;
  637. tmStart.tm_gmtoff = 0;
  638. tbTarget.time = mktime(&tmStart);
  639. tbTarget.timezone = 0;
  640. tbTarget.time += (8*3600);
  641. tmTarget = gmtime(&tbTarget.time);
  642. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  643. tx_buf[65] = (tmTarget->tm_mon+1);
  644. tx_buf[66] = tmTarget->tm_mday;
  645. tx_buf[67] = tmTarget->tm_hour;
  646. tx_buf[68] = tmTarget->tm_min;
  647. tx_buf[69] = tmTarget->tm_sec;
  648. }
  649. // Stop date time 6 bytes
  650. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  651. {
  652. struct tm *tmTarget;
  653. struct timeb tbTarget;
  654. tmEnd.tm_year -= 1900;
  655. tmEnd.tm_mon -= 1;
  656. tmEnd.tm_gmtoff = 0;
  657. tbTarget.time = mktime(&tmEnd);
  658. tbTarget.timezone = 0;
  659. tbTarget.time += (8*3600);
  660. tmTarget = gmtime(&tbTarget.time);
  661. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  662. tx_buf[71] = (tmTarget->tm_mon+1);
  663. tx_buf[72] = tmTarget->tm_mday;
  664. tx_buf[73] = tmTarget->tm_hour;
  665. tx_buf[74] = tmTarget->tm_min;
  666. tx_buf[75] = tmTarget->tm_sec;
  667. }
  668. // Session energy 2 bytes
  669. tx_buf[76] = PresentChargedEnergy & 0xff;
  670. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  671. // Start SOC 1 byte
  672. tx_buf[78] = socStart;
  673. // Stop SOC 1 byte
  674. tx_buf[79] = socEnd;
  675. // Open socket
  676. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  677. if(udp_socket_fd == -1)
  678. {
  679. DEBUG_ERROR("UDP socket create failed!\n");
  680. }
  681. else
  682. {
  683. // Get server DNS entry
  684. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  685. if (server == NULL)
  686. {
  687. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  688. }
  689. else
  690. {
  691. // Build the server's Internet address
  692. bzero((char *) &dest_addr, sizeof(dest_addr));
  693. dest_addr.sin_family = AF_INET;
  694. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  695. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  696. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  697. {
  698. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  699. {
  700. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  701. }
  702. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  703. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  704. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  705. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  706. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  707. DEBUG_TTIA_INFO("---------- Header ----------\n");
  708. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  709. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  710. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  711. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  712. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  713. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  714. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  715. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  716. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  717. DEBUG_TTIA_INFO("Len: 0x3C\n");
  718. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  719. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  720. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  721. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  722. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  723. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  724. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  725. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  726. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  727. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  728. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  729. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  730. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  731. DEBUG_TTIA_INFO("=========================================\n");
  732. sn++;
  733. result = PASS;
  734. }
  735. else
  736. {
  737. DEBUG_ERROR("UDP sent out fail.\n");
  738. }
  739. }
  740. }
  741. return result;
  742. }
  743. //=========================================
  744. // Save configuration
  745. //=========================================
  746. int runShellCmd(const char*cmd)
  747. {
  748. int result = FAIL;
  749. char buf[256];
  750. FILE *fp;
  751. fp = popen(cmd, "r");
  752. if(fp != NULL)
  753. {
  754. while(fgets(buf, sizeof(buf), fp) != NULL)
  755. {
  756. DEBUG_INFO("%s\n", buf);
  757. }
  758. result = PASS;
  759. }
  760. pclose(fp);
  761. return result;
  762. }
  763. int StoreUsrConfigData(struct SysConfigData *UsrData)
  764. {
  765. int result = PASS;
  766. int fd,wrd;
  767. unsigned int i,Chk;
  768. unsigned char *ptr, *BufTmp;
  769. int MtdBlockSize = 0x300000;
  770. Chk=0;
  771. ptr=(unsigned char *)UsrData;
  772. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  773. {
  774. memset(BufTmp,0,MtdBlockSize);
  775. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  776. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  777. Chk+=*(BufTmp+i);
  778. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  779. // Output configuration to file.
  780. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  781. if (fd < 0)
  782. {
  783. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  784. free(BufTmp);
  785. return 0;
  786. }
  787. wrd=write(fd, BufTmp, MtdBlockSize);
  788. close(fd);
  789. if(wrd<MtdBlockSize)
  790. {
  791. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  792. free(BufTmp);
  793. return 0;
  794. }
  795. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  796. DEBUG_INFO("Erase /dev/mtd10.\n");
  797. runShellCmd("flash_erase /dev/mtd10 0 0");
  798. DEBUG_INFO("Write /dev/mtd10.\n");
  799. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  800. DEBUG_INFO("Erase /dev/mtd11.\n");
  801. runShellCmd("flash_erase /dev/mtd11 0 0");
  802. DEBUG_INFO("Write /dev/mtd11.\n");
  803. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  804. system("rm -f /mnt/EvseConfig.bin");
  805. DEBUG_INFO("EvseConfig write to flash OK\n");
  806. }
  807. else
  808. {
  809. DEBUG_ERROR("alloc BlockSize NG\r\n");
  810. result = FAIL;
  811. }
  812. if(BufTmp!=NULL)
  813. free(BufTmp);
  814. return result;
  815. }
  816. //=========================================
  817. // Sqlite3 related function
  818. //=========================================
  819. static int selectSqlCount = 0;
  820. static int callback(void *data, int argc, char **argv, char **azColName){
  821. int i;
  822. //printf("%s: ", (const char*)data);
  823. selectSqlCount = argc;
  824. for(i = 0; i<argc; i++){
  825. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  826. }
  827. //printf("\n");
  828. return 0;
  829. }
  830. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  831. //int i;
  832. //printf("%s:\n", (const char*)data);
  833. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  834. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  835. return 0;
  836. }
  837. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  838. //printf("%s:\n", (const char*)data);
  839. //idTag
  840. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  841. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  842. //parentIdTag
  843. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  844. //expir_date
  845. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  846. //status
  847. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  848. //version
  849. if(columenCount > 5)
  850. idTagQuery.listVersionInt = atoi(columnValue[5]);
  851. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  852. return 0;
  853. }
  854. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  855. {
  856. // localversion = argv[5] ? atoi(argv[5]) : 0;
  857. // printf("localversion=%d\n", localversion);
  858. return 0;
  859. }
  860. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  861. {
  862. for (int i = 0; i < n_columns; i++)
  863. {
  864. DEBUG_INFO("%s\t", col_values[i]);
  865. }
  866. DEBUG_INFO("\n");
  867. return 0;
  868. }
  869. int OCPP_cleanLocalCache()
  870. {
  871. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  872. char *errMsg = 0;
  873. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  874. if (SQLITE_OK != rc)
  875. {
  876. DEBUG_INFO("SQL error: %s\n",errMsg);
  877. return FALSE;
  878. }
  879. return TRUE;
  880. }
  881. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  882. {
  883. int isSuccess = TRUE;
  884. int ret = 0;
  885. //const char* data = "Callback function called";
  886. char sql[300];
  887. char zErrMsg[200];
  888. memset(sql, 0, 300);
  889. memset(zErrMsg, 0, 200);
  890. 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);
  891. //* Execute SQL statement */
  892. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  893. if( ret != SQLITE_OK )
  894. {
  895. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  896. isSuccess = FALSE;
  897. }
  898. return isSuccess;
  899. }
  900. void OCPP_getIdTagFromLocalCache(char idTag[])
  901. {
  902. int rc = 0;
  903. char sql[100];
  904. char zErrMsg[100];
  905. memset(sql, 0, 100);
  906. memset(zErrMsg, 0, 100);
  907. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  908. memset(&idTagQuery, 0, sizeof(idTagQuery));
  909. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  910. /* Execute SQL statement */
  911. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  912. if( rc != SQLITE_OK )
  913. {
  914. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  915. }
  916. }
  917. void OCPP_getListVerion()
  918. {
  919. int rc = 0;
  920. // const char* data = "Callback function called";
  921. char sql[100];
  922. char zErrMsg[100];
  923. memset(sql, 0, 100);
  924. memset(zErrMsg, 0, 100);
  925. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  926. /* Execute SQL statement */
  927. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  928. if( rc != SQLITE_OK )
  929. {
  930. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  931. }
  932. }
  933. void OCPP_get_TableAuthlocalAllData(void)
  934. {
  935. int rc = 0;
  936. char sql[100];
  937. char zErrMsg[100];
  938. memset(sql, 0, 100);
  939. memset(zErrMsg, 0, 100);
  940. sprintf(sql,"select * from ocpp_auth_local ");
  941. /* Execute SQL statement */
  942. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  943. if( rc != SQLITE_OK )
  944. {
  945. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  946. }
  947. //return ver;
  948. }
  949. int OCPP_cleanLocalList()
  950. {
  951. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  952. char *errMsg = 0;
  953. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  954. if (SQLITE_OK != rc)
  955. {
  956. DEBUG_INFO("%s\n",errMsg);
  957. return FALSE;
  958. }
  959. return TRUE;
  960. }
  961. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  962. {
  963. int isSuccess = FALSE;
  964. int ret = 0;
  965. //const char* data = "Callback function called";
  966. char sql[300];
  967. char zErrMsg[200];
  968. memset(sql, 0, 300);
  969. memset(zErrMsg, 0, 200);
  970. 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);
  971. //* Execute SQL statement */
  972. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  973. if( ret != SQLITE_OK )
  974. {
  975. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  976. return isSuccess;
  977. }
  978. memset(sql, 0, 300);
  979. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  980. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  981. if( ret != SQLITE_OK )
  982. {
  983. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  984. return isSuccess;
  985. }
  986. isSuccess = TRUE;
  987. return isSuccess;
  988. }
  989. void OCPP_getIdTagFromLocalList(char idTag[])
  990. {
  991. int rc = 0;
  992. // const char* data = "Callback function called";
  993. char sql[100];
  994. char zErrMsg[100];
  995. memset(sql, 0, 100);
  996. memset(zErrMsg, 0, 100);
  997. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  998. memset(&idTagQuery, 0, sizeof(idTagQuery));
  999. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1000. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  1001. /* Execute SQL statement */
  1002. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  1003. if( rc != SQLITE_OK )
  1004. {
  1005. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1006. }
  1007. //return ver;
  1008. }
  1009. void OCPP_deleteIdTagFromLocalList(char idTag[])
  1010. {
  1011. //int ver = 0;
  1012. //int isSuccess = FALSE;
  1013. int rc = 0;
  1014. char sql[100];
  1015. char zErrMsg[100];
  1016. memset(sql, 0, 100);
  1017. memset(zErrMsg, 0, 100);
  1018. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  1019. //* Execute SQL statement */
  1020. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  1021. if( rc != SQLITE_OK )
  1022. {
  1023. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1024. }
  1025. }
  1026. int getCurrentYear()
  1027. {
  1028. int result = 0;
  1029. time_t CurrentTime;
  1030. struct tm *tm;
  1031. CurrentTime = time(NULL);
  1032. tm=localtime(&CurrentTime);
  1033. result = (tm->tm_year + 1900);
  1034. return result;
  1035. }
  1036. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  1037. {
  1038. int result = PASS;
  1039. char* errMsg = NULL;
  1040. char sqlStr[WEBSOCKET_BUFFER_SIZE];
  1041. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  1042. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1043. {
  1044. result = FAIL;
  1045. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  1046. }
  1047. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-100) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1048. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1049. {
  1050. result = FAIL;
  1051. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  1052. }
  1053. return result;
  1054. }
  1055. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  1056. {
  1057. int isSuccess = TRUE;
  1058. int tempIndex;
  1059. json_object *EnergyDataTransfer = json_object_new_object();
  1060. json_object *periodEnergys = json_object_new_object();
  1061. char sql[1024];
  1062. char zErrMsg[200];
  1063. memset(sql, 0, ARRAY_SIZE(sql));
  1064. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  1065. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  1066. {
  1067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1068. {
  1069. tempIndex = ((gun_index==2) ? 1: 0);
  1070. }
  1071. else
  1072. {
  1073. tempIndex = gun_index;
  1074. }
  1075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1076. {
  1077. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1078. {
  1079. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1080. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1081. {
  1082. uint8_t period[3];
  1083. sprintf((char*)period, "%d", idxPeriod);
  1084. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1085. }
  1086. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1087. } //end of the same index
  1088. }//end of for CHAdeMO_QUANTITY
  1089. }
  1090. else if(gunType[gun_index] == GUN_TYPE_CCS)
  1091. {
  1092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1093. {
  1094. tempIndex = ((gun_index==2) ? 1: 0);
  1095. }
  1096. else
  1097. {
  1098. tempIndex = gun_index;
  1099. }
  1100. for (int index = 0; index < CCS_QUANTITY; index++)
  1101. {
  1102. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1103. {
  1104. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1105. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1106. {
  1107. uint8_t period[3];
  1108. sprintf((char*)period, "%d", idxPeriod);
  1109. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1110. }
  1111. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1112. } //end of the same index
  1113. } // end of for CCS_QUANTITY
  1114. }
  1115. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1116. {
  1117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1118. {
  1119. tempIndex = ((gun_index==2) ? 1: 0);
  1120. }
  1121. else
  1122. {
  1123. tempIndex = gun_index;
  1124. }
  1125. for (int index = 0; index < GB_QUANTITY; index++)
  1126. {
  1127. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1128. {
  1129. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1130. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1131. {
  1132. uint8_t period[3];
  1133. sprintf((char*)period, "%d", idxPeriod);
  1134. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1135. }
  1136. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1137. } //end of the same index
  1138. } // end of for GB_QUANTITY
  1139. }
  1140. else if(gunType[gun_index] == GUN_TYPE_DO)
  1141. {
  1142. tempIndex = gun_index;
  1143. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1144. {
  1145. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1146. {
  1147. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1148. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1149. {
  1150. uint8_t period[3];
  1151. sprintf((char*)period, "%d", idxPeriod);
  1152. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1153. }
  1154. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1155. } //end of the same index
  1156. }
  1157. }
  1158. else
  1159. {
  1160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1161. {
  1162. tempIndex = 2;
  1163. }
  1164. else
  1165. {
  1166. tempIndex = gun_index;
  1167. }
  1168. for (int index = 0; index < AC_QUANTITY; index++)
  1169. {
  1170. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1171. {
  1172. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1173. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1174. {
  1175. uint8_t period[3];
  1176. sprintf((char*)period, "%d", idxPeriod);
  1177. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1178. }
  1179. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1180. }//end of the same index
  1181. }//end of for AC_QUANTITY
  1182. }
  1183. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1184. json_object_put(EnergyDataTransfer);
  1185. //* Execute SQL statement */
  1186. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1187. {
  1188. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1189. isSuccess = FALSE;
  1190. }
  1191. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1192. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1193. {
  1194. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1195. isSuccess = FALSE;
  1196. }
  1197. return isSuccess;
  1198. }
  1199. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1200. {
  1201. int isSuccess = TRUE;
  1202. char sql[512];
  1203. char zErrMsg[200];
  1204. int rows, cols;
  1205. char **resultData;
  1206. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1207. /* Execute SQL statement */
  1208. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1209. {
  1210. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1211. isSuccess = FALSE;
  1212. }
  1213. else
  1214. {
  1215. if((rows > 0) && (atoi(resultData[4]) > 0))
  1216. {
  1217. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1218. }
  1219. else
  1220. {
  1221. DEBUG_WARN("There is not match transaction data.\n");
  1222. isSuccess = FALSE;
  1223. }
  1224. }
  1225. return isSuccess;
  1226. }
  1227. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1228. {
  1229. int result = PASS;
  1230. char* errMsg = NULL;
  1231. char sqlStr[8192];
  1232. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1233. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1234. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1235. {
  1236. result = FAIL;
  1237. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1238. }
  1239. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1240. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1241. {
  1242. result = FAIL;
  1243. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1244. }
  1245. return result;
  1246. }
  1247. int OCPP_update_deduct_info(int txId, char *creditNo)
  1248. {
  1249. int result = PASS;
  1250. char* errMsg = NULL;
  1251. char sqlStr[8192];
  1252. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1253. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1254. {
  1255. result = FAIL;
  1256. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1257. }
  1258. return result;
  1259. }
  1260. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1261. {
  1262. json_object *dataBuf = json_object_new_object();
  1263. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1264. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1265. json_object_object_add(dataBuf, "txId", json_object_new_int(atoi(columnValue[1])));
  1266. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1267. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1268. json_object_object_add(dataBuf, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  1269. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[5])));
  1270. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[9]));
  1271. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1272. json_object_put(dataBuf);
  1273. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1274. return 0;
  1275. }
  1276. void OCPP_query_deduct_info()
  1277. {
  1278. int rc = 0;
  1279. char sql[100];
  1280. char zErrMsg[100];
  1281. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1282. /* Execute SQL statement */
  1283. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1284. if( rc != SQLITE_OK )
  1285. {
  1286. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1287. }
  1288. }
  1289. // Occupancy fee deduct queue process
  1290. int OCPP_insert_occupancyDeduct_info(char *occupancySN, char *creditNo, uint8_t deductResult, double amount, char *approvalNo)
  1291. {
  1292. int result = PASS;
  1293. char* errMsg = NULL;
  1294. char sqlStr[8192];
  1295. sprintf(sqlStr, "insert or replace into report_occupancyDeduct_info(occupancySN, creditNo, deductResult, amount, approvalNo, isUploaded) values('%s', '%s', '%d', '%.2f', '%s', '0');",
  1296. occupancySN, creditNo, deductResult, amount, approvalNo);
  1297. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1298. {
  1299. result = FAIL;
  1300. DEBUG_WARN( "Insert local report_occupancyDeduct_info error message: %s\n", errMsg);
  1301. }
  1302. sprintf(sqlStr, "delete from report_occupancyDeduct_info where (idx < (select idx from report_occupancyDeduct_info order by idx desc limit 1)-5000);");
  1303. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1304. {
  1305. result = FAIL;
  1306. DEBUG_WARN( "delete local report_occupancyDeduct_info error message: %s\n", errMsg);
  1307. }
  1308. return result;
  1309. }
  1310. int OCPP_update_occupancyDeduct_info(char *occupancySN)
  1311. {
  1312. int result = PASS;
  1313. char* errMsg = NULL;
  1314. char sqlStr[8192];
  1315. sprintf(sqlStr, "update report_occupancyDeduct_info set isUploaded='1' where occupancySN='%s';", occupancySN);
  1316. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1317. {
  1318. result = FAIL;
  1319. DEBUG_WARN( "Update local report_occupancyDeduct_info error message: %s\n", errMsg);
  1320. }
  1321. return result;
  1322. }
  1323. int queryOccupancyDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1324. {
  1325. json_object *dataBuf = json_object_new_object();
  1326. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1327. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_OccupancyDeductResult");
  1328. json_object_object_add(dataBuf, "occupancySN", json_object_new_string(columnValue[1]));
  1329. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1330. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1331. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[4])));
  1332. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[5]));
  1333. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1334. json_object_put(dataBuf);
  1335. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1336. return 0;
  1337. }
  1338. void OCPP_query_occupancyDeduct_info()
  1339. {
  1340. int rc = 0;
  1341. char sql[100];
  1342. char zErrMsg[100];
  1343. sprintf(sql,"select * from report_occupancyDeduct_info where isUploaded='0' order by idx limit 1");
  1344. /* Execute SQL statement */
  1345. rc = sqlite3_exec(db, sql, queryOccupancyDeductCallBack, 0, (char **)&zErrMsg);
  1346. if( rc != SQLITE_OK )
  1347. {
  1348. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1349. }
  1350. }
  1351. void reportReaderStatus(int gun_index)
  1352. {
  1353. struct timeval tmnow;
  1354. struct tm *tm;
  1355. char buf[28];//, usec_buf[6];
  1356. gettimeofday(&tmnow, NULL);
  1357. time_t t;
  1358. t = time(NULL);
  1359. /*UTC time and date*/
  1360. tm = gmtime(&t);
  1361. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1362. #if 0 // remove temporally
  1363. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1364. strcat(buf,".");
  1365. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1366. strcat(buf,usec_buf);
  1367. #endif
  1368. json_object *dataBuf = json_object_new_object();
  1369. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1370. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1371. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1372. json_object_object_add(dataBuf, "readerStatus", json_object_new_int(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus));
  1373. json_object_object_add(dataBuf, "timestamp", json_object_new_string(buf));
  1374. json_object_object_add(dataBuf, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  1375. json_object_object_add(dataBuf, "creditNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
  1376. json_object_object_add(dataBuf, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  1377. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1378. json_object_put(dataBuf);
  1379. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1380. }
  1381. void occupancyFeeAct(int gun_index)
  1382. {
  1383. struct timeval tmnow;
  1384. struct tm *tm;
  1385. char buf[28];//, usec_buf[6];
  1386. gettimeofday(&tmnow, NULL);
  1387. time_t t;
  1388. t = time(NULL);
  1389. /*UTC time and date*/
  1390. tm = gmtime(&t);
  1391. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1392. #if 0 // remove temporally
  1393. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1394. strcat(buf,".");
  1395. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1396. strcat(buf,usec_buf);
  1397. #endif
  1398. json_object *dataBuf = json_object_new_object();
  1399. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1400. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_OccupancyFeeAct");
  1401. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1402. json_object_object_add(dataBuf, "occupancySN", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].occupancySN));
  1403. json_object_object_add(dataBuf, "action", json_object_new_int(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].action));
  1404. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1405. json_object_put(dataBuf);
  1406. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1407. }
  1408. //==========================================
  1409. // Check time passed since today
  1410. //==========================================
  1411. long long DiffTimebWithNow(struct timeb ST)
  1412. {
  1413. //return milli-second
  1414. struct timeb ET;
  1415. long long StartTime,StopTime;
  1416. ftime(&ET);
  1417. StartTime=(long long)ST.time;
  1418. StopTime=(long long)ET.time;
  1419. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1420. }
  1421. int getTimePassSinceToday(uint8_t gun_index)
  1422. {
  1423. int result = -1;
  1424. static time_t lastTime[4];
  1425. time_t t;
  1426. struct tm *tmStartToday;
  1427. struct timeb tbStartToday;
  1428. t=time(NULL);
  1429. if(difftime(t, lastTime[gun_index])>0)
  1430. {
  1431. tmStartToday=localtime(&t);
  1432. tmStartToday->tm_hour = 0;
  1433. tmStartToday->tm_min = 0;
  1434. tmStartToday->tm_sec = 0;
  1435. tbStartToday.time = mktime(tmStartToday);
  1436. tbStartToday.millitm = 0;
  1437. result = DiffTimebWithNow(tbStartToday)/1000;
  1438. lastTime[gun_index] = t;
  1439. }
  1440. return result;
  1441. }
  1442. void getNowDatetime(uint8_t *data)
  1443. {
  1444. time_t t = time(NULL);
  1445. struct tm tm = *localtime(&t);
  1446. 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);
  1447. }
  1448. int syncDateTimeRTC(uint8_t *data)
  1449. {
  1450. struct ParsingResult
  1451. {
  1452. int result;
  1453. int scanedElement;
  1454. int year;
  1455. int month;
  1456. int mday;
  1457. int hour;
  1458. int min;
  1459. int sec;
  1460. int tz_hour;
  1461. int tz_min;
  1462. float minSec;
  1463. }result;
  1464. struct tm tmOrg;
  1465. struct tm *tmTarget;
  1466. struct timeb tbTarget;
  1467. char buf[128];
  1468. memset(&result, 0x00, sizeof(struct ParsingResult));
  1469. result.result = PASS;
  1470. if(strstr((char*)data, ".") != NULL)
  1471. {
  1472. // Original data with mini second
  1473. if(strstr((char*)data, "Z") != NULL)
  1474. {
  1475. // Original data with Z
  1476. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1477. &result.year,
  1478. &result.month,
  1479. &result.mday,
  1480. &result.hour,
  1481. &result.min,
  1482. &result.sec,
  1483. &result.minSec);
  1484. }
  1485. else
  1486. {
  1487. // Original data without Z
  1488. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1489. &result.year,
  1490. &result.month,
  1491. &result.mday,
  1492. &result.hour,
  1493. &result.min,
  1494. &result.sec,
  1495. &result.minSec,
  1496. &result.tz_hour,
  1497. &result.tz_min);
  1498. }
  1499. }
  1500. else
  1501. {
  1502. // Original data without mini second
  1503. if(strstr((char*)data, "Z") != NULL)
  1504. {
  1505. // Original data with Z
  1506. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1507. &result.year,
  1508. &result.month,
  1509. &result.mday,
  1510. &result.hour,
  1511. &result.min,
  1512. &result.sec);
  1513. }
  1514. else
  1515. {
  1516. // Original data without Z
  1517. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1518. &result.year,
  1519. &result.month,
  1520. &result.mday,
  1521. &result.hour,
  1522. &result.min,
  1523. &result.sec,
  1524. &result.tz_hour,
  1525. &result.tz_min);
  1526. }
  1527. }
  1528. tmOrg.tm_year = result.year - 1900;
  1529. tmOrg.tm_mon = result.month - 1;
  1530. tmOrg.tm_mday = result.mday;
  1531. tmOrg.tm_hour = result.hour;
  1532. tmOrg.tm_min = result.min;
  1533. tmOrg.tm_sec = result.sec;
  1534. tmOrg.tm_gmtoff = 0;
  1535. tbTarget.time = mktime(&tmOrg);
  1536. tbTarget.timezone = 0;
  1537. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1538. tmTarget = gmtime(&tbTarget.time);
  1539. 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);
  1540. //DEBUG_INFO(" org date time: %s\n", data);
  1541. //DEBUG_INFO("parse date time: %s\n", buf);
  1542. system(buf);
  1543. system("/sbin/hwclock -w --systohc");
  1544. if(result.scanedElement < 6)
  1545. result.result = FAIL;
  1546. return result.result;
  1547. }
  1548. //==========================================
  1549. // Parse certificate content
  1550. //==========================================
  1551. int parseCertInfo(char *certPath, int parseType, char *data)
  1552. {
  1553. int result = FAIL;
  1554. int count = 0;
  1555. int showupLine = 0;
  1556. memset(data, 0, ARRAY_SIZE(data));
  1557. if(access(certPath,F_OK) != -1)
  1558. {
  1559. char temp[512] = {0};
  1560. char capturedData[256] = {0};
  1561. char hashType[10] = "SHA256";
  1562. FILE *fp;
  1563. // Need to get hash type first
  1564. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  1565. fp = popen(temp, "r");
  1566. if(fp)
  1567. {
  1568. while(fgets(temp, sizeof(temp), fp) != NULL)
  1569. {
  1570. if(strstr(temp, "Signature Algorithm:") != NULL)
  1571. {
  1572. result = PASS;
  1573. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  1574. sprintf((char*)hashType, "SHA256");
  1575. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  1576. sprintf((char*)hashType, "SHA384");
  1577. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  1578. sprintf((char*)hashType, "SHA512");
  1579. else
  1580. {
  1581. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  1582. result = FAIL;
  1583. }
  1584. break;
  1585. }
  1586. }
  1587. }
  1588. switch(parseType)
  1589. {
  1590. case CERT_PARSE_HashAlgorithm:
  1591. sprintf((char*)data, hashType);
  1592. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  1593. break;
  1594. case CERT_PARSE_SerialNumber:
  1595. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  1596. fp = popen(temp, "r");
  1597. if(fp)
  1598. {
  1599. while(fgets(temp, sizeof(temp), fp) != NULL)
  1600. {
  1601. if(strstr(temp, "serial=") != NULL)
  1602. {
  1603. sscanf(temp, "%*[^=]=%s", capturedData);
  1604. result = PASS;
  1605. break;
  1606. }
  1607. }
  1608. DEBUG_INFO("serialNumber: %s\n", capturedData);
  1609. sprintf((char*)data, capturedData);
  1610. }
  1611. break;
  1612. case CERT_PARSE_IssuerNameHash:
  1613. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1614. fp = popen(temp, "r");
  1615. if(fp)
  1616. {
  1617. while(fgets(temp, sizeof(temp), fp) != NULL)
  1618. {
  1619. if(strstr(temp, "SEQUENCE") != NULL)
  1620. {
  1621. count++;
  1622. if(count==4)
  1623. {
  1624. sscanf(temp, "%[^:]", capturedData);
  1625. showupLine = atoi(capturedData);
  1626. break;
  1627. }
  1628. }
  1629. }
  1630. }
  1631. if(showupLine > 0)
  1632. {
  1633. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerNameHash", certPath, showupLine);
  1634. system(temp);
  1635. }
  1636. else
  1637. {
  1638. break;
  1639. }
  1640. if(access("/Storage/OCPP/IssuerNameHash",F_OK) != -1)
  1641. {
  1642. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerNameHash", (char*)hashType);
  1643. fp = popen(temp, "r");
  1644. if(fp)
  1645. {
  1646. while(fgets(temp, sizeof(temp), fp) != NULL)
  1647. {
  1648. if(strstr(temp, "(stdin)=") != NULL)
  1649. {
  1650. sscanf(temp, "%*[^=]=%s", capturedData);
  1651. result = PASS;
  1652. break;
  1653. }
  1654. }
  1655. stringtrimspace(capturedData);
  1656. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1657. sprintf((char*)data, capturedData);
  1658. }
  1659. }
  1660. break;
  1661. case CERT_PARSE_IssuerKeyHash:
  1662. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1663. fp = popen(temp, "r");
  1664. if(fp)
  1665. {
  1666. while(fgets(temp, sizeof(temp), fp) != NULL)
  1667. {
  1668. if(strstr(temp, "BIT STRING") != NULL)
  1669. {
  1670. sscanf(temp, "%[^:]", capturedData);
  1671. showupLine = atoi(capturedData);
  1672. break;
  1673. }
  1674. }
  1675. }
  1676. if(showupLine > 0)
  1677. {
  1678. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerKeyHash", certPath, showupLine);
  1679. system(temp);
  1680. }
  1681. else
  1682. {
  1683. break;
  1684. }
  1685. if(access("/Storage/OCPP/IssuerKeyHash",F_OK) != -1)
  1686. {
  1687. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerKeyHash", (char*)hashType);
  1688. fp = popen(temp, "r");
  1689. if(fp)
  1690. {
  1691. while(fgets(temp, sizeof(temp), fp) != NULL)
  1692. {
  1693. if(strstr(temp, "(stdin)=") != NULL)
  1694. {
  1695. sscanf(temp, "%*[^=]=%s", capturedData);
  1696. result = PASS;
  1697. break;
  1698. }
  1699. }
  1700. stringtrimspace(capturedData);
  1701. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1702. sprintf((char*)data, capturedData);
  1703. }
  1704. }
  1705. break;
  1706. case CERT_PARSE_OcspUrl:
  1707. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1708. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1709. fp = popen(temp, "r");
  1710. if(fp)
  1711. {
  1712. while(fgets(temp, sizeof(temp), fp) != NULL)
  1713. {
  1714. if(strstr(temp, "OCSP - URI:") != NULL)
  1715. {
  1716. //strcpy((char*)data, temp);
  1717. sscanf(temp, "%*[^:]:%s", capturedData);
  1718. sprintf((char*)data, capturedData);
  1719. DEBUG_INFO("OCSP_URI: %s\n", data);
  1720. result = PASS;
  1721. break;
  1722. }
  1723. }
  1724. }
  1725. break;
  1726. default:
  1727. DEBUG_INFO("Parse type is invalid.\n");
  1728. break;
  1729. }
  1730. pclose(fp);
  1731. }
  1732. return result;
  1733. }
  1734. //==========================================
  1735. // GetCompositeSchedule logic related function
  1736. //==========================================
  1737. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1738. {
  1739. //return milli-second
  1740. unsigned int StartTime,StopTime;
  1741. StartTime=(unsigned int)ST.time;
  1742. StopTime=(unsigned int)ET.time;
  1743. return (StopTime-StartTime);
  1744. }
  1745. int DiffTimebWithNowSec(struct timeb ST)
  1746. {
  1747. //return milli-second
  1748. struct timeb ET;
  1749. unsigned int StartTime,StopTime;
  1750. ftime(&ET);
  1751. StartTime=(unsigned int)ST.time;
  1752. StopTime=(unsigned int)ET.time;
  1753. return (StopTime-StartTime);
  1754. }
  1755. int getStartStop(uint8_t *start, uint8_t *stop)
  1756. {
  1757. struct ParsingResult
  1758. {
  1759. int result;
  1760. int scanedElement;
  1761. int year;
  1762. int month;
  1763. int mday;
  1764. int hour;
  1765. int min;
  1766. int sec;
  1767. int tz_hour;
  1768. int tz_min;
  1769. float minSec;
  1770. };
  1771. struct ParsingResult parseStart;
  1772. struct ParsingResult parseStop;
  1773. int result = -1;
  1774. struct tm tmStart;
  1775. struct timeb tbStart;
  1776. struct tm tmStop;
  1777. struct timeb tbStop;
  1778. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1779. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1780. // Scan start & stop date time
  1781. if(strstr((char*)start, ".") != NULL)
  1782. {
  1783. // Original data with mini second
  1784. if(strstr((char*)start, "Z") != NULL)
  1785. {
  1786. // Original data with Z
  1787. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1788. &parseStart.year,
  1789. &parseStart.month,
  1790. &parseStart.mday,
  1791. &parseStart.hour,
  1792. &parseStart.min,
  1793. &parseStart.sec,
  1794. &parseStart.minSec);
  1795. }
  1796. else
  1797. {
  1798. // Original data without Z
  1799. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1800. &parseStart.year,
  1801. &parseStart.month,
  1802. &parseStart.mday,
  1803. &parseStart.hour,
  1804. &parseStart.min,
  1805. &parseStart.sec,
  1806. &parseStart.minSec,
  1807. &parseStart.tz_hour,
  1808. &parseStart.tz_min);
  1809. }
  1810. }
  1811. else
  1812. {
  1813. // Original data without mini second
  1814. if(strstr((char*)start, "Z") != NULL)
  1815. {
  1816. // Original data with Z
  1817. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1818. &parseStart.year,
  1819. &parseStart.month,
  1820. &parseStart.mday,
  1821. &parseStart.hour,
  1822. &parseStart.min,
  1823. &parseStart.sec);
  1824. }
  1825. else
  1826. {
  1827. // Original data without Z
  1828. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1829. &parseStart.year,
  1830. &parseStart.month,
  1831. &parseStart.mday,
  1832. &parseStart.hour,
  1833. &parseStart.min,
  1834. &parseStart.sec,
  1835. &parseStart.tz_hour,
  1836. &parseStart.tz_min);
  1837. }
  1838. }
  1839. if(strstr((char*)stop, ".") != NULL)
  1840. {
  1841. // Original data with mini second
  1842. if(strstr((char*)stop, "Z") != NULL)
  1843. {
  1844. // Original data with Z
  1845. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1846. &parseStop.year,
  1847. &parseStop.month,
  1848. &parseStop.mday,
  1849. &parseStop.hour,
  1850. &parseStop.min,
  1851. &parseStop.sec,
  1852. &parseStop.minSec);
  1853. }
  1854. else
  1855. {
  1856. // Original data without Z
  1857. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1858. &parseStop.year,
  1859. &parseStop.month,
  1860. &parseStop.mday,
  1861. &parseStop.hour,
  1862. &parseStop.min,
  1863. &parseStop.sec,
  1864. &parseStop.minSec,
  1865. &parseStop.tz_hour,
  1866. &parseStop.tz_min);
  1867. }
  1868. }
  1869. else
  1870. {
  1871. // Original data without mini second
  1872. if(strstr((char*)stop, "Z") != NULL)
  1873. {
  1874. // Original data with Z
  1875. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1876. &parseStop.year,
  1877. &parseStop.month,
  1878. &parseStop.mday,
  1879. &parseStop.hour,
  1880. &parseStop.min,
  1881. &parseStop.sec);
  1882. }
  1883. else
  1884. {
  1885. // Original data without Z
  1886. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1887. &parseStop.year,
  1888. &parseStop.month,
  1889. &parseStop.mday,
  1890. &parseStop.hour,
  1891. &parseStop.min,
  1892. &parseStop.sec,
  1893. &parseStop.tz_hour,
  1894. &parseStop.tz_min);
  1895. }
  1896. }
  1897. // Calculate date time difference
  1898. if((parseStart.scanedElement >=6) &&
  1899. (parseStop.scanedElement >=6))
  1900. {
  1901. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1902. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1903. tmStart.tm_year = parseStart.year - 1900;
  1904. tmStart.tm_mon = parseStart.month - 1;
  1905. tmStart.tm_mday = parseStart.mday;
  1906. tmStart.tm_hour = parseStart.hour;
  1907. tmStart.tm_min = parseStart.min;
  1908. tmStart.tm_sec = parseStart.sec;
  1909. tmStart.tm_gmtoff = 0;
  1910. tbStart.time = mktime(&tmStart);
  1911. tbStart.timezone = 0;
  1912. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1913. tmStop.tm_year = parseStop.year - 1900;
  1914. tmStop.tm_mon = parseStop.month - 1;
  1915. tmStop.tm_mday = parseStop.mday;
  1916. tmStop.tm_hour = parseStop.hour;
  1917. tmStop.tm_min = parseStop.min;
  1918. tmStop.tm_sec = parseStop.sec;
  1919. tmStop.tm_gmtoff = 0;
  1920. tbStop.time = mktime(&tmStop);
  1921. tbStop.timezone = 0;
  1922. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1923. result = DiffTimebSec(tbStart, tbStop);
  1924. //DEBUG_INFO("getStartStop(): %d\n", result);
  1925. }
  1926. else
  1927. {
  1928. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1929. }
  1930. return result;
  1931. }
  1932. int isOvertNow(uint8_t *start)
  1933. {
  1934. int result = NO;
  1935. struct ParsingResult
  1936. {
  1937. int result;
  1938. int scanedElement;
  1939. int year;
  1940. int month;
  1941. int mday;
  1942. int hour;
  1943. int min;
  1944. int sec;
  1945. int tz_hour;
  1946. int tz_min;
  1947. float minSec;
  1948. }parsingResult;
  1949. struct tm tmStart;
  1950. struct timeb tbStart;
  1951. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1952. if(strstr((char*)start, ".") != NULL)
  1953. {
  1954. // Original data with mini second
  1955. if(strstr((char*)start, "Z") != NULL)
  1956. {
  1957. // Original data with Z
  1958. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1959. &parsingResult.year,
  1960. &parsingResult.month,
  1961. &parsingResult.mday,
  1962. &parsingResult.hour,
  1963. &parsingResult.min,
  1964. &parsingResult.sec,
  1965. &parsingResult.minSec);
  1966. }
  1967. else
  1968. {
  1969. // Original data without Z
  1970. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1971. &parsingResult.year,
  1972. &parsingResult.month,
  1973. &parsingResult.mday,
  1974. &parsingResult.hour,
  1975. &parsingResult.min,
  1976. &parsingResult.sec,
  1977. &parsingResult.minSec,
  1978. &parsingResult.tz_hour,
  1979. &parsingResult.tz_min);
  1980. }
  1981. }
  1982. else
  1983. {
  1984. // Original data without mini second
  1985. if(strstr((char*)start, "Z") != NULL)
  1986. {
  1987. // Original data with Z
  1988. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1989. &parsingResult.year,
  1990. &parsingResult.month,
  1991. &parsingResult.mday,
  1992. &parsingResult.hour,
  1993. &parsingResult.min,
  1994. &parsingResult.sec);
  1995. }
  1996. else
  1997. {
  1998. // Original data without Z
  1999. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  2000. &parsingResult.year,
  2001. &parsingResult.month,
  2002. &parsingResult.mday,
  2003. &parsingResult.hour,
  2004. &parsingResult.min,
  2005. &parsingResult.sec,
  2006. &parsingResult.tz_hour,
  2007. &parsingResult.tz_min);
  2008. }
  2009. }
  2010. if(parsingResult.scanedElement >= 6)
  2011. {
  2012. tmStart.tm_year = parsingResult.year - 1900;
  2013. tmStart.tm_mon = parsingResult.month - 1;
  2014. tmStart.tm_mday = parsingResult.mday;
  2015. tmStart.tm_hour = parsingResult.hour;
  2016. tmStart.tm_min = parsingResult.min;
  2017. tmStart.tm_sec = parsingResult.sec;
  2018. tmStart.tm_gmtoff = 0;
  2019. tbStart.time = mktime(&tmStart);
  2020. tbStart.timezone = 0;
  2021. tbStart.millitm = 0;
  2022. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  2023. if(DiffTimebWithNowSec(tbStart) <= 0)
  2024. result = NO;
  2025. else
  2026. result = YES;
  2027. }
  2028. else
  2029. {
  2030. DEBUG_WARN("Start date parsing error.\n");
  2031. }
  2032. return result;
  2033. }
  2034. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  2035. {
  2036. struct ParsingResult
  2037. {
  2038. int result;
  2039. int scanedElement;
  2040. int year;
  2041. int month;
  2042. int mday;
  2043. int hour;
  2044. int min;
  2045. int sec;
  2046. int tz_hour;
  2047. int tz_min;
  2048. float minSec;
  2049. };
  2050. struct ParsingResult parseStart;
  2051. struct ParsingResult parseStop;
  2052. int result = -1;
  2053. struct tm tmStart;
  2054. struct timeb tbStart;
  2055. struct tm tmStop;
  2056. struct timeb tbStop;
  2057. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  2058. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  2059. // Scan start & stop date time
  2060. if(strstr((char*)start, ".") != NULL)
  2061. {
  2062. // Original data with mini second
  2063. if(strstr((char*)start, "Z") != NULL)
  2064. {
  2065. // Original data with Z
  2066. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  2067. &parseStart.year,
  2068. &parseStart.month,
  2069. &parseStart.mday,
  2070. &parseStart.hour,
  2071. &parseStart.min,
  2072. &parseStart.sec,
  2073. &parseStart.minSec);
  2074. }
  2075. else
  2076. {
  2077. // Original data without Z
  2078. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2079. &parseStart.year,
  2080. &parseStart.month,
  2081. &parseStart.mday,
  2082. &parseStart.hour,
  2083. &parseStart.min,
  2084. &parseStart.sec,
  2085. &parseStart.minSec,
  2086. &parseStart.tz_hour,
  2087. &parseStart.tz_min);
  2088. }
  2089. }
  2090. else
  2091. {
  2092. // Original data without mini second
  2093. if(strstr((char*)start, "Z") != NULL)
  2094. {
  2095. // Original data with Z
  2096. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  2097. &parseStart.year,
  2098. &parseStart.month,
  2099. &parseStart.mday,
  2100. &parseStart.hour,
  2101. &parseStart.min,
  2102. &parseStart.sec);
  2103. }
  2104. else
  2105. {
  2106. // Original data without Z
  2107. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  2108. &parseStart.year,
  2109. &parseStart.month,
  2110. &parseStart.mday,
  2111. &parseStart.hour,
  2112. &parseStart.min,
  2113. &parseStart.sec,
  2114. &parseStart.tz_hour,
  2115. &parseStart.tz_min);
  2116. }
  2117. }
  2118. if(strstr((char*)stop, ".") != NULL)
  2119. {
  2120. // Original data with mini second
  2121. if(strstr((char*)stop, "Z") != NULL)
  2122. {
  2123. // Original data with Z
  2124. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  2125. &parseStop.year,
  2126. &parseStop.month,
  2127. &parseStop.mday,
  2128. &parseStop.hour,
  2129. &parseStop.min,
  2130. &parseStop.sec,
  2131. &parseStop.minSec);
  2132. }
  2133. else
  2134. {
  2135. // Original data without Z
  2136. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2137. &parseStop.year,
  2138. &parseStop.month,
  2139. &parseStop.mday,
  2140. &parseStop.hour,
  2141. &parseStop.min,
  2142. &parseStop.sec,
  2143. &parseStop.minSec,
  2144. &parseStop.tz_hour,
  2145. &parseStop.tz_min);
  2146. }
  2147. }
  2148. else
  2149. {
  2150. // Original data without mini second
  2151. if(strstr((char*)stop, "Z") != NULL)
  2152. {
  2153. // Original data with Z
  2154. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  2155. &parseStop.year,
  2156. &parseStop.month,
  2157. &parseStop.mday,
  2158. &parseStop.hour,
  2159. &parseStop.min,
  2160. &parseStop.sec);
  2161. }
  2162. else
  2163. {
  2164. // Original data without Z
  2165. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  2166. &parseStop.year,
  2167. &parseStop.month,
  2168. &parseStop.mday,
  2169. &parseStop.hour,
  2170. &parseStop.min,
  2171. &parseStop.sec,
  2172. &parseStop.tz_hour,
  2173. &parseStop.tz_min);
  2174. }
  2175. }
  2176. // Calculate date time difference
  2177. if((parseStart.scanedElement >=6) &&
  2178. (parseStop.scanedElement >=6))
  2179. {
  2180. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  2181. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  2182. tmStart.tm_year = parseStart.year - 1900;
  2183. tmStart.tm_mon = parseStart.month - 1;
  2184. tmStart.tm_mday = parseStart.mday;
  2185. tmStart.tm_hour = parseStart.hour;
  2186. tmStart.tm_min = parseStart.min;
  2187. tmStart.tm_sec = parseStart.sec;
  2188. tmStart.tm_gmtoff = 0;
  2189. tbStart.time = mktime(&tmStart);
  2190. tbStart.timezone = 0;
  2191. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  2192. tmStop.tm_year = parseStop.year - 1900;
  2193. tmStop.tm_mon = parseStop.month - 1;
  2194. tmStop.tm_mday = parseStop.mday;
  2195. tmStop.tm_hour = parseStop.hour;
  2196. tmStop.tm_min = parseStop.min;
  2197. tmStop.tm_sec = parseStop.sec;
  2198. tmStop.tm_gmtoff = 0;
  2199. tbStop.time = mktime(&tmStop);
  2200. tbStop.timezone = 0;
  2201. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  2202. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2203. //DEBUG_INFO("getStartStop(): %d\n", result);
  2204. }
  2205. else
  2206. {
  2207. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2208. }
  2209. return result;
  2210. }
  2211. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2212. {
  2213. FILE *fp;
  2214. char profileFileName[128];
  2215. char *line = NULL;
  2216. size_t len = 0;
  2217. time_t CurrentTime;
  2218. struct tm *tmComposite;
  2219. struct StructChargingProfile maxProfile;
  2220. struct StructChargingProfile compositeProfile;
  2221. uint8_t limitMax=0;
  2222. int compositePeriodIdx = 0;
  2223. //uint8_t isDurationNull = FALSE;
  2224. CurrentTime = time(NULL);
  2225. tmComposite=localtime(&CurrentTime);
  2226. 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);
  2227. if(isUnitA)
  2228. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2229. else
  2230. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2231. compositeProfile.ChargingSchedule.Duration = durationReq;
  2232. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2233. {
  2234. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2235. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2236. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2237. }
  2238. compositeProfile.ChargingProfileId = 0;
  2239. compositeProfile.StackLevel = 99 ;
  2240. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2241. maxProfile.ChargingProfileId = -1;
  2242. maxProfile.ChargingSchedule.Duration = -1;
  2243. system("rm -f /tmp/*.json");
  2244. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2245. // Search max profile
  2246. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2247. if((access(profileFileName, F_OK))!=-1)
  2248. {
  2249. fp = fopen(profileFileName, "r");
  2250. while(getline(&line, &len, fp) != -1)
  2251. {
  2252. json_object *obj = NULL;
  2253. obj = json_tokener_parse(line);
  2254. if(is_error(obj))
  2255. {
  2256. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2257. }
  2258. else
  2259. {
  2260. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2261. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2262. )
  2263. {
  2264. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2265. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2266. )
  2267. {
  2268. struct tm tmFrom, tmTo;
  2269. struct timeb tbFrom, tbTo;
  2270. 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) &&
  2271. (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))
  2272. {
  2273. tmFrom.tm_year -= 1900;
  2274. tmFrom.tm_mon -= 1;
  2275. tbFrom.time = mktime(&tmFrom);
  2276. tmTo.tm_year -= 1900;
  2277. tmTo.tm_mon -= 1;
  2278. tbTo.time = mktime(&tmTo);
  2279. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2280. {
  2281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2282. {
  2283. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2285. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2286. }
  2287. if(maxProfile.ChargingProfileId == -1)
  2288. DEBUG_INFO("MaxProfile found.\n");
  2289. else
  2290. DEBUG_INFO("MaxProfile updated.\n");
  2291. // Required item
  2292. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2293. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2294. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2295. if(isUnitA)
  2296. {
  2297. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2298. 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++)
  2299. {
  2300. 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"));
  2301. 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?
  2302. 3:
  2303. 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")));
  2304. 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")));
  2305. }
  2306. }
  2307. else
  2308. {
  2309. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2310. 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++)
  2311. {
  2312. 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"));
  2313. 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?
  2314. 3:
  2315. 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")));
  2316. 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));
  2317. }
  2318. }
  2319. // Optional item
  2320. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2321. {
  2322. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2323. }
  2324. else
  2325. {
  2326. sprintf((char*)maxProfile.ValidFrom, " ");
  2327. }
  2328. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2329. {
  2330. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2331. }
  2332. else
  2333. {
  2334. sprintf((char*)maxProfile.ValidTo, " ");
  2335. }
  2336. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2337. {
  2338. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2339. }
  2340. else
  2341. {
  2342. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2343. }
  2344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2345. {
  2346. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2347. }
  2348. else
  2349. {
  2350. maxProfile.TransactionId = -1;
  2351. }
  2352. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2353. {
  2354. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2355. }
  2356. else
  2357. {
  2358. maxProfile.ChargingSchedule.Duration = 86400;
  2359. //isDurationNull = TRUE;
  2360. }
  2361. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2362. {
  2363. 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")));
  2364. }
  2365. else
  2366. {
  2367. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2368. }
  2369. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2370. {
  2371. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2372. }
  2373. else
  2374. {
  2375. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2376. }
  2377. }
  2378. }
  2379. }
  2380. else
  2381. {
  2382. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2383. {
  2384. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2385. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2386. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2387. }
  2388. if(maxProfile.ChargingProfileId == -1)
  2389. DEBUG_INFO("MaxProfile found.\n");
  2390. else
  2391. DEBUG_INFO("MaxProfile updated.\n");
  2392. // Required item
  2393. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2394. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2395. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2396. if(isUnitA)
  2397. {
  2398. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2399. 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++)
  2400. {
  2401. 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"));
  2402. 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?
  2403. 3:
  2404. 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")));
  2405. 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")));
  2406. }
  2407. }
  2408. else
  2409. {
  2410. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2411. 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++)
  2412. {
  2413. 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"));
  2414. 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?
  2415. 3:
  2416. 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")));
  2417. 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));
  2418. }
  2419. }
  2420. // Optional item
  2421. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2422. {
  2423. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2424. }
  2425. else
  2426. {
  2427. sprintf((char*)maxProfile.ValidFrom, " ");
  2428. }
  2429. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2430. {
  2431. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2432. }
  2433. else
  2434. {
  2435. sprintf((char*)maxProfile.ValidTo, " ");
  2436. }
  2437. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2438. {
  2439. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2440. }
  2441. else
  2442. {
  2443. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2444. }
  2445. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2446. {
  2447. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2448. }
  2449. else
  2450. {
  2451. maxProfile.TransactionId = -1;
  2452. }
  2453. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2454. {
  2455. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2456. }
  2457. else
  2458. {
  2459. maxProfile.ChargingSchedule.Duration = 86400;
  2460. //isDurationNull = TRUE;
  2461. }
  2462. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2463. {
  2464. 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")));
  2465. }
  2466. else
  2467. {
  2468. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2469. }
  2470. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2471. {
  2472. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2473. }
  2474. else
  2475. {
  2476. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2477. }
  2478. }
  2479. }
  2480. }
  2481. json_object_put(obj);
  2482. }
  2483. fclose(fp);
  2484. /*
  2485. if(maxProfile.ChargingProfileId !=-1)
  2486. {
  2487. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2488. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2489. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2490. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2491. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2492. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2493. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2494. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2495. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2496. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2497. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2498. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2499. {
  2500. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2501. {
  2502. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2503. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2504. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2505. }
  2506. }
  2507. }
  2508. else
  2509. DEBUG_INFO("MaxProfile not found.\n");
  2510. DEBUG_INFO("------------------------------------\n");*/
  2511. }
  2512. if(maxProfile.ChargingProfileId != -1)
  2513. {
  2514. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2515. {
  2516. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2517. {
  2518. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2519. 0:
  2520. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2521. }
  2522. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2523. {
  2524. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2525. {
  2526. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2527. 0:
  2528. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2529. if(idxPeriod > 0)
  2530. {
  2531. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2532. {
  2533. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2534. }
  2535. }
  2536. }
  2537. }
  2538. }
  2539. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2540. {
  2541. if(maxProfile.ChargingSchedule.Duration != -1)
  2542. {
  2543. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2544. }
  2545. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2546. {
  2547. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2548. {
  2549. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2550. if(idxPeriod > 0)
  2551. {
  2552. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2553. {
  2554. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2555. }
  2556. }
  2557. }
  2558. }
  2559. }
  2560. else
  2561. {
  2562. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2563. {
  2564. if(maxProfile.ChargingSchedule.Duration != -1)
  2565. {
  2566. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2567. 0:
  2568. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2569. }
  2570. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2571. {
  2572. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2573. {
  2574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2575. 0:
  2576. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2577. if(idxPeriod > 0)
  2578. {
  2579. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2580. {
  2581. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2582. }
  2583. }
  2584. }
  2585. }
  2586. }
  2587. else
  2588. {
  2589. if(maxProfile.ChargingSchedule.Duration != -1)
  2590. {
  2591. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2592. 0:
  2593. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2594. }
  2595. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2596. {
  2597. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2598. {
  2599. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2600. 0:
  2601. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2602. if(idxPeriod > 0)
  2603. {
  2604. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2605. {
  2606. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2607. }
  2608. }
  2609. }
  2610. }
  2611. }
  2612. }
  2613. /*
  2614. DEBUG_INFO("MaxProfile after align.\n");
  2615. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2616. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2617. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2618. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2619. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2620. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2621. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2622. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2623. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2624. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2625. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2626. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2627. {
  2628. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2629. {
  2630. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2631. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2632. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2633. }
  2634. }
  2635. DEBUG_INFO("------------------------------------\n");*/
  2636. }
  2637. // Find each profile period quantity
  2638. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2639. {
  2640. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2641. limitMax = idx+1;
  2642. }
  2643. if(maxProfile.ChargingProfileId != -1)
  2644. {
  2645. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2646. {
  2647. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2648. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2649. (maxProfile.ChargingSchedule.Duration > 0))
  2650. {
  2651. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2652. {
  2653. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2654. compositePeriodIdx++;
  2655. }
  2656. else
  2657. {
  2658. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2659. }
  2660. }
  2661. }
  2662. }
  2663. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2664. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2665. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2666. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2667. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2668. {
  2669. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2670. {
  2671. compositeProfile.ChargingProfileId = 1;
  2672. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2673. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2674. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2675. }
  2676. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2677. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2678. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2679. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2680. }
  2681. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2682. if(line)
  2683. free(line);
  2684. }
  2685. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2686. {
  2687. FILE *fp;
  2688. char profileFileName[128];
  2689. char *line = NULL;
  2690. size_t len = 0;
  2691. time_t CurrentTime;
  2692. struct tm *tmComposite;
  2693. struct StructChargingProfile maxProfile;
  2694. struct StructChargingProfile defaultTxProfile;
  2695. struct StructChargingProfile txProfile;
  2696. struct StructChargingProfile compositeProfile;
  2697. struct StructChargingSchedulePeriod tmpPeriod;
  2698. uint8_t limitMax=0;
  2699. uint8_t limitDef=0;
  2700. uint8_t limitTx=0;
  2701. int compositePeriodIdx = 0;
  2702. CurrentTime = time(NULL);
  2703. tmComposite=localtime(&CurrentTime);
  2704. 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);
  2705. if(isUnitA)
  2706. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2707. else
  2708. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2709. compositeProfile.ChargingSchedule.Duration = durationReq;
  2710. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2711. {
  2712. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2713. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2714. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2715. }
  2716. compositeProfile.ChargingProfileId = 0;
  2717. compositeProfile.StackLevel = 99 ;
  2718. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2719. maxProfile.ChargingProfileId = -1;
  2720. defaultTxProfile.ChargingProfileId = -1;
  2721. txProfile.ChargingProfileId = -1;
  2722. maxProfile.ChargingSchedule.Duration = -1;
  2723. defaultTxProfile.ChargingSchedule.Duration = -1;
  2724. txProfile.ChargingSchedule.Duration = -1;
  2725. system("rm -f /tmp/*.json");
  2726. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2727. /*
  2728. * Search valid charging profile
  2729. */
  2730. //DEBUG_INFO("====================================\n");
  2731. // Search tx profile
  2732. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2733. if((access(profileFileName, F_OK))!=-1)
  2734. {
  2735. fp = fopen(profileFileName, "r");
  2736. while(getline(&line, &len, fp) != -1)
  2737. {
  2738. json_object *obj = NULL;
  2739. obj = json_tokener_parse(line);
  2740. if(is_error(obj))
  2741. {
  2742. DEBUG_ERROR("Parse txProfile from file error.\n");
  2743. }
  2744. else
  2745. {
  2746. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2747. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2748. )
  2749. {
  2750. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2751. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2752. )
  2753. {
  2754. struct tm tmFrom, tmTo;
  2755. struct timeb tbFrom, tbTo;
  2756. 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) &&
  2757. (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))
  2758. {
  2759. tmFrom.tm_year -= 1900;
  2760. tmFrom.tm_mon -= 1;
  2761. tbFrom.time = mktime(&tmFrom);
  2762. tmTo.tm_year -= 1900;
  2763. tmTo.tm_mon -= 1;
  2764. tbTo.time = mktime(&tmTo);
  2765. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2766. {
  2767. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2768. {
  2769. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2770. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2771. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2772. }
  2773. if(txProfile.ChargingProfileId == -1)
  2774. DEBUG_INFO("TxProfile found.\n");
  2775. else
  2776. DEBUG_INFO("TxProfile updated.\n");
  2777. // Required item
  2778. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2779. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2780. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2781. if(isUnitA)
  2782. {
  2783. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2784. 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++)
  2785. {
  2786. 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"));
  2787. 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?
  2788. 3:
  2789. 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")));
  2790. 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")));
  2791. }
  2792. }
  2793. else
  2794. {
  2795. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2796. 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++)
  2797. {
  2798. 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"));
  2799. 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?
  2800. 3:
  2801. 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")));
  2802. 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));
  2803. }
  2804. }
  2805. // Optional item
  2806. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2807. {
  2808. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2809. }
  2810. else
  2811. {
  2812. sprintf((char*)txProfile.ValidFrom, " ");
  2813. }
  2814. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2815. {
  2816. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2817. }
  2818. else
  2819. {
  2820. sprintf((char*)txProfile.ValidTo, " ");
  2821. }
  2822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2823. {
  2824. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2825. }
  2826. else
  2827. {
  2828. sprintf((char*)txProfile.RecurrencyKind, " ");
  2829. }
  2830. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2831. {
  2832. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2833. }
  2834. else
  2835. {
  2836. txProfile.TransactionId = -1;
  2837. }
  2838. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2839. {
  2840. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2841. }
  2842. else
  2843. {
  2844. txProfile.ChargingSchedule.Duration = 86400;
  2845. }
  2846. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2847. {
  2848. 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")));
  2849. }
  2850. else
  2851. {
  2852. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2853. }
  2854. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2855. {
  2856. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2857. }
  2858. else
  2859. {
  2860. txProfile.ChargingSchedule.MinChargingRate = -1;
  2861. }
  2862. }
  2863. }
  2864. }
  2865. else
  2866. {
  2867. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2868. {
  2869. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2870. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2871. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2872. }
  2873. if(txProfile.ChargingProfileId == -1)
  2874. DEBUG_INFO("TxProfile found.\n");
  2875. else
  2876. DEBUG_INFO("TxProfile updated.\n");
  2877. // Required item
  2878. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2879. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2880. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2881. if(isUnitA)
  2882. {
  2883. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2884. 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++)
  2885. {
  2886. 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"));
  2887. 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?
  2888. 3:
  2889. 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")));
  2890. 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")));
  2891. }
  2892. }
  2893. else
  2894. {
  2895. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2896. 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++)
  2897. {
  2898. 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"));
  2899. 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?
  2900. 3:
  2901. 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")));
  2902. 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));
  2903. }
  2904. }
  2905. // Optional item
  2906. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2907. {
  2908. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2909. }
  2910. else
  2911. {
  2912. sprintf((char*)txProfile.ValidFrom, " ");
  2913. }
  2914. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2915. {
  2916. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2917. }
  2918. else
  2919. {
  2920. sprintf((char*)txProfile.ValidTo, " ");
  2921. }
  2922. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2923. {
  2924. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2925. }
  2926. else
  2927. {
  2928. sprintf((char*)txProfile.RecurrencyKind, " ");
  2929. }
  2930. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2931. {
  2932. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2933. }
  2934. else
  2935. {
  2936. txProfile.TransactionId = -1;
  2937. }
  2938. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2939. {
  2940. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2941. }
  2942. else
  2943. {
  2944. txProfile.ChargingSchedule.Duration = 86400;
  2945. }
  2946. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2947. {
  2948. 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")));
  2949. }
  2950. else
  2951. {
  2952. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2953. }
  2954. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2955. {
  2956. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2957. }
  2958. else
  2959. {
  2960. txProfile.ChargingSchedule.MinChargingRate = -1;
  2961. }
  2962. }
  2963. }
  2964. }
  2965. json_object_put(obj);
  2966. }
  2967. fclose(fp);
  2968. /*
  2969. if(txProfile.ChargingProfileId != -1)
  2970. {
  2971. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2972. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2973. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2974. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2975. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2976. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2977. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2978. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2979. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2980. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2981. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2982. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2983. {
  2984. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2985. {
  2986. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2987. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2988. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2989. }
  2990. }
  2991. }
  2992. else
  2993. DEBUG_INFO("TxProfile not found.\n");*/
  2994. }
  2995. // Search default tx profile
  2996. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2997. if((access(profileFileName, F_OK))==-1)
  2998. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2999. if((access(profileFileName, F_OK))!=-1)
  3000. {
  3001. fp = fopen(profileFileName, "r");
  3002. while(getline(&line, &len, fp) != -1)
  3003. {
  3004. json_object *obj = NULL;
  3005. obj = json_tokener_parse(line);
  3006. if(is_error(obj))
  3007. {
  3008. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  3009. }
  3010. else
  3011. {
  3012. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  3013. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  3014. )
  3015. {
  3016. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3017. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3018. )
  3019. {
  3020. struct tm tmFrom, tmTo;
  3021. struct timeb tbFrom, tbTo;
  3022. 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) &&
  3023. (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))
  3024. {
  3025. tmFrom.tm_year -= 1900;
  3026. tmFrom.tm_mon -= 1;
  3027. tbFrom.time = mktime(&tmFrom);
  3028. tmTo.tm_year -= 1900;
  3029. tmTo.tm_mon -= 1;
  3030. tbTo.time = mktime(&tmTo);
  3031. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3032. {
  3033. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3034. {
  3035. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3036. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3037. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3038. }
  3039. if(defaultTxProfile.ChargingProfileId == -1)
  3040. DEBUG_INFO("TxDefaultProfile found.\n");
  3041. else
  3042. DEBUG_INFO("TxDefaultProfile updated.\n");
  3043. // Required item
  3044. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3045. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3046. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3047. if(isUnitA)
  3048. {
  3049. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3050. 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++)
  3051. {
  3052. 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"));
  3053. 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?
  3054. 3:
  3055. 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")));
  3056. 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")));
  3057. }
  3058. }
  3059. else
  3060. {
  3061. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3062. 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++)
  3063. {
  3064. 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"));
  3065. 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?
  3066. 3:
  3067. 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")));
  3068. 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));
  3069. }
  3070. }
  3071. // Optional item
  3072. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3073. {
  3074. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3075. }
  3076. else
  3077. {
  3078. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3079. }
  3080. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3081. {
  3082. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3083. }
  3084. else
  3085. {
  3086. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3087. }
  3088. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3089. {
  3090. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3091. }
  3092. else
  3093. {
  3094. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3095. }
  3096. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3097. {
  3098. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3099. }
  3100. else
  3101. {
  3102. defaultTxProfile.TransactionId = -1;
  3103. }
  3104. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3105. {
  3106. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3107. }
  3108. else
  3109. {
  3110. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3111. }
  3112. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3113. {
  3114. 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")));
  3115. }
  3116. else
  3117. {
  3118. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3119. }
  3120. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3121. {
  3122. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3123. }
  3124. else
  3125. {
  3126. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3127. }
  3128. }
  3129. }
  3130. }
  3131. else
  3132. {
  3133. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3134. {
  3135. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3136. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3137. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3138. }
  3139. if(defaultTxProfile.ChargingProfileId == -1)
  3140. DEBUG_INFO("TxDefaultProfile found.\n");
  3141. else
  3142. DEBUG_INFO("TxDefaultProfile updated.\n");
  3143. // Required item
  3144. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3145. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3146. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3147. if(isUnitA)
  3148. {
  3149. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3150. 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++)
  3151. {
  3152. 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"));
  3153. 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?
  3154. 3:
  3155. 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")));
  3156. 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")));
  3157. }
  3158. }
  3159. else
  3160. {
  3161. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3162. 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++)
  3163. {
  3164. 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"));
  3165. 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?
  3166. 3:
  3167. 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")));
  3168. 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));
  3169. }
  3170. }
  3171. // Optional item
  3172. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3173. {
  3174. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3175. }
  3176. else
  3177. {
  3178. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3179. }
  3180. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3181. {
  3182. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3183. }
  3184. else
  3185. {
  3186. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3187. }
  3188. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3189. {
  3190. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3191. }
  3192. else
  3193. {
  3194. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3195. }
  3196. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3197. {
  3198. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3199. }
  3200. else
  3201. {
  3202. defaultTxProfile.TransactionId = -1;
  3203. }
  3204. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3205. {
  3206. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3207. }
  3208. else
  3209. {
  3210. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3211. }
  3212. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3213. {
  3214. 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")));
  3215. }
  3216. else
  3217. {
  3218. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3219. }
  3220. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3221. {
  3222. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3223. }
  3224. else
  3225. {
  3226. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3227. }
  3228. }
  3229. }
  3230. }
  3231. json_object_put(obj);
  3232. }
  3233. fclose(fp);
  3234. /*
  3235. if(defaultTxProfile.ChargingProfileId != -1)
  3236. {
  3237. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3238. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3239. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3240. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3241. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3242. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3243. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3244. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  3245. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3246. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3247. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3248. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3249. {
  3250. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3251. {
  3252. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3253. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3254. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3255. }
  3256. }
  3257. }
  3258. else
  3259. DEBUG_INFO("TxDefaultProfile not found.\n");
  3260. DEBUG_INFO("------------------------------------\n");*/
  3261. }
  3262. // Search max profile
  3263. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3264. if((access(profileFileName, F_OK))!=-1)
  3265. {
  3266. fp = fopen(profileFileName, "r");
  3267. while(getline(&line, &len, fp) != -1)
  3268. {
  3269. json_object *obj = NULL;
  3270. obj = json_tokener_parse(line);
  3271. if(is_error(obj))
  3272. {
  3273. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3274. }
  3275. else
  3276. {
  3277. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  3278. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  3279. )
  3280. {
  3281. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3282. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3283. )
  3284. {
  3285. struct tm tmFrom, tmTo;
  3286. struct timeb tbFrom, tbTo;
  3287. 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) &&
  3288. (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))
  3289. {
  3290. tmFrom.tm_year -= 1900;
  3291. tmFrom.tm_mon -= 1;
  3292. tbFrom.time = mktime(&tmFrom);
  3293. tmTo.tm_year -= 1900;
  3294. tmTo.tm_mon -= 1;
  3295. tbTo.time = mktime(&tmTo);
  3296. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3297. {
  3298. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3299. {
  3300. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3301. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3302. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3303. }
  3304. if(maxProfile.ChargingProfileId == -1)
  3305. DEBUG_INFO("MaxProfile found.\n");
  3306. else
  3307. DEBUG_INFO("MaxProfile updated.\n");
  3308. // Required item
  3309. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3310. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3311. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3312. if(isUnitA)
  3313. {
  3314. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3315. 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++)
  3316. {
  3317. 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"));
  3318. 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?
  3319. 3:
  3320. 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")));
  3321. 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")));
  3322. }
  3323. }
  3324. else
  3325. {
  3326. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3327. 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++)
  3328. {
  3329. 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"));
  3330. 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?
  3331. 3:
  3332. 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")));
  3333. 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));
  3334. }
  3335. }
  3336. // Optional item
  3337. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3338. {
  3339. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3340. }
  3341. else
  3342. {
  3343. sprintf((char*)maxProfile.ValidFrom, " ");
  3344. }
  3345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3346. {
  3347. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3348. }
  3349. else
  3350. {
  3351. sprintf((char*)maxProfile.ValidTo, " ");
  3352. }
  3353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3354. {
  3355. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3356. }
  3357. else
  3358. {
  3359. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3360. }
  3361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3362. {
  3363. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3364. }
  3365. else
  3366. {
  3367. maxProfile.TransactionId = -1;
  3368. }
  3369. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3370. {
  3371. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3372. }
  3373. else
  3374. {
  3375. maxProfile.ChargingSchedule.Duration = 86400;
  3376. }
  3377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3378. {
  3379. 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")));
  3380. }
  3381. else
  3382. {
  3383. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3384. }
  3385. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3386. {
  3387. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3388. }
  3389. else
  3390. {
  3391. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3392. }
  3393. }
  3394. }
  3395. }
  3396. else
  3397. {
  3398. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3399. {
  3400. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3401. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3402. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3403. }
  3404. if(maxProfile.ChargingProfileId == -1)
  3405. DEBUG_INFO("MaxProfile found.\n");
  3406. else
  3407. DEBUG_INFO("MaxProfile updated.\n");
  3408. // Required item
  3409. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3410. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3411. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3412. if(isUnitA)
  3413. {
  3414. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3415. 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++)
  3416. {
  3417. 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"));
  3418. 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?
  3419. 3:
  3420. 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")));
  3421. 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")));
  3422. }
  3423. }
  3424. else
  3425. {
  3426. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3427. 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++)
  3428. {
  3429. 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"));
  3430. 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?
  3431. 3:
  3432. 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")));
  3433. 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));
  3434. }
  3435. }
  3436. // Optional item
  3437. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3438. {
  3439. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3440. }
  3441. else
  3442. {
  3443. sprintf((char*)maxProfile.ValidFrom, " ");
  3444. }
  3445. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3446. {
  3447. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3448. }
  3449. else
  3450. {
  3451. sprintf((char*)maxProfile.ValidTo, " ");
  3452. }
  3453. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3454. {
  3455. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3456. }
  3457. else
  3458. {
  3459. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3460. }
  3461. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3462. {
  3463. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3464. }
  3465. else
  3466. {
  3467. maxProfile.TransactionId = -1;
  3468. }
  3469. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3470. {
  3471. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3472. }
  3473. else
  3474. {
  3475. maxProfile.ChargingSchedule.Duration = 86400;
  3476. }
  3477. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3478. {
  3479. 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")));
  3480. }
  3481. else
  3482. {
  3483. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3484. }
  3485. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3486. {
  3487. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3488. }
  3489. else
  3490. {
  3491. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3492. }
  3493. }
  3494. }
  3495. }
  3496. json_object_put(obj);
  3497. }
  3498. fclose(fp);
  3499. /*
  3500. if(maxProfile.ChargingProfileId !=-1)
  3501. {
  3502. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3503. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3504. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3505. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3506. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3507. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3508. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3509. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3510. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3511. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3512. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3513. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3514. {
  3515. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3516. {
  3517. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3518. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3519. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3520. }
  3521. }
  3522. }
  3523. else
  3524. DEBUG_INFO("MaxProfile not found.\n");
  3525. DEBUG_INFO("------------------------------------\n");*/
  3526. }
  3527. /*
  3528. * Align found profile start schedule & periods
  3529. */
  3530. //DEBUG_INFO("====================================\n");
  3531. /*
  3532. // For local test usage, force modify found profile start schedule info
  3533. 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);
  3534. 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);
  3535. 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);
  3536. */
  3537. if(txProfile.ChargingProfileId != -1)
  3538. {
  3539. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3540. {
  3541. if(txProfile.ChargingSchedule.Duration != -1)
  3542. {
  3543. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3544. 0:
  3545. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3546. }
  3547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3548. {
  3549. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3550. {
  3551. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3552. 0:
  3553. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3554. if(idxPeriod > 0)
  3555. {
  3556. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3557. {
  3558. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3559. }
  3560. }
  3561. }
  3562. }
  3563. }
  3564. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3565. {
  3566. if(txProfile.ChargingSchedule.Duration != -1)
  3567. {
  3568. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3569. 0:
  3570. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3571. }
  3572. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3573. {
  3574. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3575. {
  3576. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3577. 0:
  3578. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3579. if(idxPeriod > 0)
  3580. {
  3581. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3582. {
  3583. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3584. }
  3585. }
  3586. }
  3587. }
  3588. }
  3589. else
  3590. {
  3591. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3592. {
  3593. if(txProfile.ChargingSchedule.Duration != -1)
  3594. {
  3595. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3596. 0:
  3597. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3598. }
  3599. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3600. {
  3601. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3602. {
  3603. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3604. 0:
  3605. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3606. if(idxPeriod > 0)
  3607. {
  3608. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3609. {
  3610. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3611. }
  3612. }
  3613. }
  3614. }
  3615. }
  3616. else
  3617. {
  3618. if(txProfile.ChargingSchedule.Duration != -1)
  3619. {
  3620. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3621. 0:
  3622. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3623. }
  3624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3625. {
  3626. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3627. {
  3628. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3629. 0:
  3630. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3631. if(idxPeriod > 0)
  3632. {
  3633. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3634. {
  3635. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3636. }
  3637. }
  3638. }
  3639. }
  3640. }
  3641. }
  3642. /*
  3643. DEBUG_INFO("txProfile after align.\n");
  3644. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3645. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3646. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3647. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3648. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3649. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3650. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3651. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3652. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3653. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3654. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3655. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3656. {
  3657. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3658. {
  3659. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3660. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3661. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3662. }
  3663. }*/
  3664. }
  3665. if(defaultTxProfile.ChargingProfileId != -1)
  3666. {
  3667. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3668. {
  3669. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3670. {
  3671. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3672. 0:
  3673. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3674. }
  3675. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3676. {
  3677. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3678. {
  3679. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3680. 0:
  3681. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3682. if(idxPeriod > 0)
  3683. {
  3684. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3685. {
  3686. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3687. }
  3688. }
  3689. }
  3690. }
  3691. }
  3692. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3693. {
  3694. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3695. {
  3696. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3697. 0:
  3698. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3699. }
  3700. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3701. {
  3702. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3703. {
  3704. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3705. 0:
  3706. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3707. if(idxPeriod > 0)
  3708. {
  3709. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3710. {
  3711. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3712. }
  3713. }
  3714. }
  3715. }
  3716. }
  3717. else
  3718. {
  3719. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3720. {
  3721. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3722. {
  3723. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3724. 0:
  3725. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3726. }
  3727. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3728. {
  3729. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3730. {
  3731. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3732. 0:
  3733. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3734. if(idxPeriod > 0)
  3735. {
  3736. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3737. {
  3738. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3739. }
  3740. }
  3741. }
  3742. }
  3743. }
  3744. else
  3745. {
  3746. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3747. {
  3748. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3749. 0:
  3750. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3751. }
  3752. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3753. {
  3754. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3755. {
  3756. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3757. 0:
  3758. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3759. if(idxPeriod > 0)
  3760. {
  3761. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3762. {
  3763. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3764. }
  3765. }
  3766. }
  3767. }
  3768. }
  3769. }
  3770. /*
  3771. DEBUG_INFO("defaultTxProfile after align.\n");
  3772. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3773. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3774. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3775. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3776. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3777. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3778. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3779. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3780. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3781. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3782. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3783. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3784. {
  3785. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3786. {
  3787. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3788. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3789. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3790. }
  3791. }
  3792. DEBUG_INFO("------------------------------------\n");*/
  3793. }
  3794. if(maxProfile.ChargingProfileId != -1)
  3795. {
  3796. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3797. {
  3798. if(maxProfile.ChargingSchedule.Duration != -1)
  3799. {
  3800. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3801. 0:
  3802. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3803. }
  3804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3805. {
  3806. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3807. {
  3808. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3809. 0:
  3810. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3811. if(idxPeriod > 0)
  3812. {
  3813. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3814. {
  3815. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3816. }
  3817. }
  3818. }
  3819. }
  3820. }
  3821. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3822. {
  3823. if(maxProfile.ChargingSchedule.Duration != -1)
  3824. {
  3825. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3826. 0:
  3827. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3828. }
  3829. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3830. {
  3831. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3832. {
  3833. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3834. 0:
  3835. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3836. if(idxPeriod > 0)
  3837. {
  3838. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3839. {
  3840. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3841. }
  3842. }
  3843. }
  3844. }
  3845. }
  3846. else
  3847. {
  3848. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3849. {
  3850. if(maxProfile.ChargingSchedule.Duration != -1)
  3851. {
  3852. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3853. 0:
  3854. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3855. }
  3856. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3857. {
  3858. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3859. {
  3860. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3861. 0:
  3862. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3863. if(idxPeriod > 0)
  3864. {
  3865. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3866. {
  3867. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3868. }
  3869. }
  3870. }
  3871. }
  3872. }
  3873. else
  3874. {
  3875. if(maxProfile.ChargingSchedule.Duration != -1)
  3876. {
  3877. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3878. 0:
  3879. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3880. }
  3881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3882. {
  3883. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3884. {
  3885. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3886. 0:
  3887. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3888. if(idxPeriod > 0)
  3889. {
  3890. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3891. {
  3892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3893. }
  3894. }
  3895. }
  3896. }
  3897. }
  3898. }
  3899. /*
  3900. DEBUG_INFO("MaxProfile after align.\n");
  3901. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3902. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3903. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3904. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3905. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3906. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3907. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3908. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3909. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3910. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3911. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3912. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3913. {
  3914. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3915. {
  3916. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3917. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3918. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3919. }
  3920. }
  3921. DEBUG_INFO("------------------------------------\n");*/
  3922. }
  3923. /*
  3924. * Merge to composite schedule
  3925. */
  3926. //DEBUG_INFO("====================================\n");
  3927. // Find each profile period quantity
  3928. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3929. {
  3930. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3931. limitMax = idx+1;
  3932. }
  3933. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3934. {
  3935. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3936. limitDef = idx+1;
  3937. }
  3938. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3939. {
  3940. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3941. limitTx = idx+1;
  3942. }
  3943. // TxProfile found, composite schedule based on it
  3944. if(txProfile.ChargingProfileId != -1)
  3945. {
  3946. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3947. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3948. {
  3949. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3950. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3951. (txProfile.ChargingSchedule.Duration > 0))
  3952. {
  3953. if(maxProfile.ChargingProfileId != -1)
  3954. {
  3955. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3956. {
  3957. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3958. {
  3959. if((maxProfile.ChargingSchedule.Duration > 0))
  3960. {
  3961. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3962. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3963. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3964. }
  3965. else
  3966. {
  3967. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3968. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3969. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3970. }
  3971. }
  3972. if(idxMaxPeriod == (limitMax-1))
  3973. {
  3974. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3975. {
  3976. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3977. {
  3978. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3979. compositePeriodIdx++;
  3980. }
  3981. else
  3982. {
  3983. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3984. }
  3985. }
  3986. }
  3987. }
  3988. }
  3989. else
  3990. {
  3991. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3992. {
  3993. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3994. compositePeriodIdx++;
  3995. }
  3996. else
  3997. {
  3998. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3999. }
  4000. }
  4001. }
  4002. if(idxTxPeriod == (limitTx-1))
  4003. {
  4004. if(defaultTxProfile.ChargingProfileId != -1)
  4005. {
  4006. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  4007. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4008. {
  4009. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  4010. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  4011. (defaultTxProfile.ChargingSchedule.Duration>0))
  4012. {
  4013. if(maxProfile.ChargingProfileId != -1)
  4014. {
  4015. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4016. {
  4017. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4018. {
  4019. if((maxProfile.ChargingSchedule.Duration > 0))
  4020. {
  4021. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4022. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4023. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  4024. }
  4025. else
  4026. {
  4027. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4028. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4029. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4030. }
  4031. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4032. {
  4033. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4034. {
  4035. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4036. compositePeriodIdx++;
  4037. }
  4038. else
  4039. {
  4040. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4041. }
  4042. }
  4043. // Delete duplicate period
  4044. if(compositePeriodIdx > 1)
  4045. {
  4046. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4047. {
  4048. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4049. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4050. compositePeriodIdx -= 1;
  4051. }
  4052. }
  4053. }
  4054. else
  4055. {
  4056. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4057. {
  4058. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4059. compositePeriodIdx++;
  4060. }
  4061. else
  4062. {
  4063. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4064. }
  4065. break;
  4066. }
  4067. }
  4068. }
  4069. else
  4070. {
  4071. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4072. {
  4073. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4074. compositePeriodIdx++;
  4075. }
  4076. else
  4077. {
  4078. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4079. }
  4080. }
  4081. }
  4082. }
  4083. }
  4084. }
  4085. }
  4086. }
  4087. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4088. else if(defaultTxProfile.ChargingProfileId != -1)
  4089. {
  4090. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  4091. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4092. {
  4093. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  4094. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  4095. (defaultTxProfile.ChargingSchedule.Duration > 0))
  4096. {
  4097. if(maxProfile.ChargingProfileId != -1)
  4098. {
  4099. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4100. {
  4101. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4102. {
  4103. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4104. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4105. if((maxProfile.ChargingSchedule.Duration > 0))
  4106. {
  4107. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  4108. }
  4109. else
  4110. {
  4111. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4112. }
  4113. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4114. {
  4115. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4116. {
  4117. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4118. compositePeriodIdx++;
  4119. }
  4120. else
  4121. {
  4122. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4123. }
  4124. }
  4125. // Delete duplicate period
  4126. if(compositePeriodIdx > 1)
  4127. {
  4128. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4129. {
  4130. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4131. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4132. compositePeriodIdx -= 1;
  4133. }
  4134. }
  4135. }
  4136. else
  4137. {
  4138. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4139. {
  4140. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4141. compositePeriodIdx++;
  4142. }
  4143. else
  4144. {
  4145. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4146. }
  4147. break;
  4148. }
  4149. }
  4150. }
  4151. else
  4152. {
  4153. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4154. {
  4155. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4156. compositePeriodIdx++;
  4157. }
  4158. else
  4159. {
  4160. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4161. }
  4162. }
  4163. }
  4164. }
  4165. }
  4166. // Fill other period by MaxProfile
  4167. if(maxProfile.ChargingProfileId != -1)
  4168. {
  4169. if(compositePeriodIdx==0)
  4170. {
  4171. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4172. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  4173. {
  4174. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4175. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4176. (maxProfile.ChargingSchedule.Duration > 0))
  4177. {
  4178. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4179. {
  4180. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4181. compositePeriodIdx++;
  4182. }
  4183. else
  4184. {
  4185. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4186. }
  4187. }
  4188. }
  4189. }
  4190. else
  4191. {
  4192. int lastCompositePeriodIdx = compositePeriodIdx;
  4193. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4194. {
  4195. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4196. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4197. (maxProfile.ChargingSchedule.Duration > 0))
  4198. {
  4199. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  4200. {
  4201. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit) &&
  4202. (compositeProfile.ChargingSchedule.Duration >= durationReq))
  4203. {
  4204. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4205. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4206. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  4207. }
  4208. else
  4209. {
  4210. if(maxProfile.ChargingSchedule.Duration > compositeProfile.ChargingSchedule.Duration)
  4211. {
  4212. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod <= compositeProfile.ChargingSchedule.Duration)
  4213. tmpPeriod.StartPeriod = compositeProfile.ChargingSchedule.Duration;
  4214. else
  4215. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4216. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4217. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  4218. }
  4219. }
  4220. }
  4221. if(tmpPeriod.Limit != -1)
  4222. {
  4223. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  4224. {
  4225. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  4226. {
  4227. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4228. compositePeriodIdx++;
  4229. }
  4230. else
  4231. {
  4232. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4233. }
  4234. }
  4235. // Delete duplicate period
  4236. if(compositePeriodIdx > 1)
  4237. {
  4238. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4239. {
  4240. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4241. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4242. compositePeriodIdx -= 1;
  4243. }
  4244. }
  4245. }
  4246. }
  4247. }
  4248. if((maxProfile.ChargingSchedule.Duration > durationReq) && (maxProfile.ChargingSchedule.Duration > compositeProfile.ChargingSchedule.Duration))
  4249. {
  4250. compositeProfile.ChargingSchedule.Duration = durationReq;
  4251. }
  4252. else if(maxProfile.ChargingSchedule.Duration > compositeProfile.ChargingSchedule.Duration)
  4253. {
  4254. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4255. }
  4256. }
  4257. }
  4258. if(compositeProfile.ChargingSchedule.Duration < durationReq)
  4259. {
  4260. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4261. {
  4262. if((idxPeriod >= 0) && (compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1))
  4263. {
  4264. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = compositeProfile.ChargingSchedule.Duration;
  4265. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  4266. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].NumberPhases;
  4267. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  4268. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4269. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4270. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4271. DEBUG_INFO("------------------------------------------------\n");
  4272. break;
  4273. }
  4274. }
  4275. }
  4276. compositeProfile.ChargingSchedule.Duration = durationReq;
  4277. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4278. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4279. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  4280. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  4281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4282. {
  4283. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4284. {
  4285. compositeProfile.ChargingProfileId = 1;
  4286. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4287. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4288. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4289. }
  4290. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  4291. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  4292. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  4293. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  4294. }
  4295. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4296. if(line)
  4297. free(line);
  4298. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  4299. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  4300. }
  4301. //==========================================
  4302. // Init all share memory
  4303. //==========================================
  4304. int InitShareMemory()
  4305. {
  4306. int result = PASS;
  4307. int MeterSMId;
  4308. //creat ShmSysConfigAndInfo
  4309. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4310. {
  4311. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4312. result = FAIL;
  4313. }
  4314. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4315. {
  4316. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4317. result = FAIL;
  4318. }
  4319. else
  4320. {}
  4321. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4322. {
  4323. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4324. result = FAIL;
  4325. }
  4326. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4327. {
  4328. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4329. result = FAIL;
  4330. }
  4331. else
  4332. {}
  4333. //creat ShmPsuData
  4334. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4335. {
  4336. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4337. result = FAIL;
  4338. }
  4339. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4340. {
  4341. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4342. result = FAIL;
  4343. }
  4344. else
  4345. {}
  4346. //creat ShmOCPP16Data
  4347. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  4348. {
  4349. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  4350. result = FAIL;
  4351. }
  4352. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4353. {
  4354. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  4355. result = FAIL;
  4356. }
  4357. else
  4358. {}
  4359. /****************************** For Initial Settings************************************************/
  4360. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  4361. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  4362. // allocate Configuration memory address
  4363. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  4364. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  4365. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  4366. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  4367. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  4368. //offline MeterValue Interval
  4369. TempMeterValueInterval = 0;
  4370. return result;
  4371. }
  4372. int ProcessShareMemory()
  4373. {
  4374. int result = PASS;
  4375. if(InitShareMemory() == FAIL)
  4376. {
  4377. DEBUG_ERROR("InitShareMemory NG\n");
  4378. if(ShmStatusCodeData!=NULL)
  4379. {
  4380. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4381. }
  4382. result = FAIL;
  4383. }
  4384. // Model name parsing
  4385. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  4386. {
  4387. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  4388. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  4389. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  4390. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  4391. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  4392. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  4393. ) // 'D' means DC
  4394. {
  4395. // DO series
  4396. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4397. {
  4398. gunTotalNumber += 1;
  4399. gunType[gun_index] = GUN_TYPE_DO;
  4400. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4401. {
  4402. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4403. {
  4404. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4405. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4406. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4407. }
  4408. }
  4409. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4410. {
  4411. case Gun_Type_Chademo:
  4412. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4413. break;
  4414. case Gun_Type_CCS_2:
  4415. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4416. break;
  4417. case Gun_Type_GB:
  4418. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4419. break;
  4420. case Gun_Type_AC:
  4421. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4422. break;
  4423. default:
  4424. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4425. break;
  4426. }
  4427. }
  4428. }
  4429. else
  4430. {
  4431. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4432. {
  4433. gunTotalNumber += 1;
  4434. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4435. {
  4436. case Gun_Type_Chademo:
  4437. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4438. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4439. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4440. {
  4441. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4442. {
  4443. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4444. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4445. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4446. }
  4447. }
  4448. break;
  4449. case Gun_Type_CCS_2:
  4450. gunType[gun_index] = GUN_TYPE_CCS;
  4451. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4452. for (int index = 0; index < CCS_QUANTITY; index++)
  4453. {
  4454. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4455. {
  4456. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4457. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4458. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4459. }
  4460. }
  4461. break;
  4462. case Gun_Type_GB:
  4463. gunType[gun_index] = GUN_TYPE_GBT;
  4464. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4465. for (int index = 0; index < GB_QUANTITY; index++)
  4466. {
  4467. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4468. {
  4469. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4470. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4471. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4472. }
  4473. }
  4474. break;
  4475. case Gun_Type_AC:
  4476. gunType[gun_index] = GUN_TYPE_AC;
  4477. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4478. for (int index = 0; index < AC_QUANTITY; index++)
  4479. {
  4480. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4481. {
  4482. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4483. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4484. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4485. }
  4486. }
  4487. break;
  4488. default:
  4489. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4490. break;
  4491. }
  4492. }
  4493. }
  4494. }
  4495. else
  4496. {
  4497. DEBUG_ERROR("Model name parsing fail.\n");
  4498. result = FAIL;
  4499. }
  4500. if(result != PASS)sleep(5);
  4501. return result;
  4502. }
  4503. void checkRemoteStart(uint8_t connectorIdInt)
  4504. {
  4505. uint8_t tempIndex;
  4506. int result = PASS;
  4507. char cmdBuf[512];
  4508. //check Transaction active
  4509. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4510. {
  4511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4512. {
  4513. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4514. }
  4515. else
  4516. {
  4517. tempIndex = connectorIdInt -1;
  4518. }
  4519. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4520. {
  4521. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4522. {
  4523. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4524. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4525. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4526. {
  4527. //Reserved
  4528. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4529. }
  4530. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4531. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4532. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4533. {
  4534. //Reserved
  4535. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4536. result = FAIL;
  4537. goto end;
  4538. }
  4539. else
  4540. {
  4541. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4542. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4543. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4544. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4545. {
  4546. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4547. result = FAIL;
  4548. goto end;
  4549. }
  4550. }//END FOR ELSE
  4551. }
  4552. }// END FOR CHAdeMO_QUANTITY
  4553. }
  4554. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4555. {
  4556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4557. {
  4558. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4559. }
  4560. else
  4561. {
  4562. tempIndex = connectorIdInt -1;
  4563. }
  4564. for (int index = 0; index < CCS_QUANTITY; index++)
  4565. {
  4566. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4567. {
  4568. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4569. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4570. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4571. {
  4572. //Reserved
  4573. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4574. }
  4575. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4576. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4577. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4578. {
  4579. //Reserved
  4580. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4581. result = FAIL;
  4582. goto end;
  4583. }
  4584. else
  4585. {
  4586. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4587. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4588. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4589. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4590. {
  4591. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4592. result = FAIL;
  4593. goto end;
  4594. }
  4595. }// END FOR ELSE
  4596. }
  4597. }// END FOR CCS_QUANTITY
  4598. }
  4599. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4600. {
  4601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4602. {
  4603. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4604. }
  4605. else
  4606. {
  4607. tempIndex = connectorIdInt -1;
  4608. }
  4609. for (int index = 0; index < GB_QUANTITY; index++)
  4610. {
  4611. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4612. {
  4613. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4614. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4615. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4616. {
  4617. //Reserved
  4618. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4619. }
  4620. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4621. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4622. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4623. {
  4624. //Reserved
  4625. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4626. result = FAIL;
  4627. goto end;
  4628. }
  4629. else
  4630. {
  4631. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4632. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4633. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4634. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4635. {
  4636. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4637. result = FAIL;
  4638. goto end;
  4639. }
  4640. }// END FOR ELSE
  4641. }
  4642. } // END FOR GB_QUANTITY
  4643. }
  4644. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4645. {
  4646. tempIndex = connectorIdInt -1;
  4647. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4648. {
  4649. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4650. {
  4651. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4652. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4653. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4654. {
  4655. //Reserved
  4656. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4657. }
  4658. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4659. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4660. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4661. {
  4662. //Reserved
  4663. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4664. result = FAIL;
  4665. goto end;
  4666. }
  4667. else
  4668. {
  4669. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4670. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4671. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4672. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4673. {
  4674. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4675. result = FAIL;
  4676. goto end;
  4677. }
  4678. }// END FOR ELSE
  4679. }
  4680. } // END FOR GB_QUANTITY
  4681. }
  4682. else
  4683. {
  4684. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4685. {
  4686. tempIndex = 2;
  4687. }
  4688. else
  4689. {
  4690. tempIndex = connectorIdInt -1;
  4691. }
  4692. for (int index = 0; index < AC_QUANTITY; index++)
  4693. {
  4694. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4695. {
  4696. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4697. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4698. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4699. {
  4700. //Reserved
  4701. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4702. }
  4703. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4704. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4705. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4706. {
  4707. //Reserved
  4708. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4709. result = FAIL;
  4710. goto end;
  4711. }
  4712. else
  4713. {
  4714. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4715. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4716. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4717. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4718. {
  4719. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4720. result = FAIL;
  4721. goto end;
  4722. }
  4723. }//END FOR ELSE
  4724. }
  4725. }// END FOR AC_QUANTITY
  4726. }
  4727. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4728. {
  4729. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4730. {
  4731. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4732. {
  4733. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4734. system(cmdBuf);
  4735. }
  4736. }
  4737. else
  4738. {
  4739. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4740. result = FAIL;
  4741. }
  4742. }
  4743. end:
  4744. if(result == PASS)
  4745. {
  4746. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4747. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4748. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4749. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4750. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4751. }
  4752. }
  4753. int isConnector0Unavailable()
  4754. {
  4755. uint8_t result = YES;
  4756. uint8_t tempIndex;
  4757. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4758. {
  4759. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4760. {
  4761. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4762. {
  4763. tempIndex = ((gun_index==2) ? 1: 0);
  4764. }
  4765. else
  4766. {
  4767. tempIndex = gun_index;
  4768. }
  4769. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4770. {
  4771. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4772. {
  4773. 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))
  4774. {
  4775. result = NO;
  4776. }
  4777. }
  4778. }
  4779. }
  4780. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4781. {
  4782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4783. {
  4784. tempIndex = ((gun_index==2) ? 1: 0);
  4785. }
  4786. else
  4787. {
  4788. tempIndex = gun_index;
  4789. }
  4790. for (int index = 0; index < CCS_QUANTITY; index++)
  4791. {
  4792. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4793. {
  4794. 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))
  4795. {
  4796. result = NO;
  4797. }
  4798. }
  4799. }
  4800. }
  4801. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4802. {
  4803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4804. {
  4805. tempIndex = ((gun_index==2) ? 1: 0);
  4806. }
  4807. else
  4808. {
  4809. tempIndex = gun_index;
  4810. }
  4811. for (int index = 0; index < GB_QUANTITY; index++)
  4812. {
  4813. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4814. {
  4815. 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))
  4816. {
  4817. result = NO;
  4818. }
  4819. }
  4820. }
  4821. }
  4822. else if(gunType[gun_index] == GUN_TYPE_DO)
  4823. {
  4824. tempIndex = gun_index;
  4825. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4826. {
  4827. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4828. {
  4829. 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))
  4830. {
  4831. result = NO;
  4832. }
  4833. }
  4834. }
  4835. }
  4836. else
  4837. {
  4838. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4839. {
  4840. tempIndex = 2;
  4841. }
  4842. else
  4843. {
  4844. tempIndex = gun_index;
  4845. }
  4846. for (int index = 0; index < AC_QUANTITY; index++)
  4847. {
  4848. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4849. {
  4850. 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))
  4851. {
  4852. result = NO;
  4853. }
  4854. }
  4855. }// END
  4856. }
  4857. }
  4858. return result;
  4859. }
  4860. void CheckSystemValue(void)
  4861. {
  4862. char filenmae[100]={0};
  4863. char str[100]={0};
  4864. int tempIndex = 0;
  4865. //===============================
  4866. // send Heartbeat
  4867. //===============================
  4868. if((server_sign == TRUE) && (HeartBeatWaitTime > 0) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4869. {
  4870. //parameter for test
  4871. if(HeartBeatWithNOResponse < 1)
  4872. sendHeartbeatRequest(0);
  4873. //===========================
  4874. // Reset Waiting Time
  4875. //===========================
  4876. HeartBeatWithNOResponse += 1;
  4877. }
  4878. //===============================
  4879. // Tcci credit deduct report
  4880. //===============================
  4881. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4882. {
  4883. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4884. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4885. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4886. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4887. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4888. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4889. }
  4890. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4891. {
  4892. OCPP_query_deduct_info();
  4893. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4894. }
  4895. if(ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq)
  4896. {
  4897. OCPP_insert_occupancyDeduct_info((char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN, (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo,
  4898. ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult, ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount,
  4899. (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo);
  4900. ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = FALSE;
  4901. }
  4902. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryOccupancyDeduct) > 5)
  4903. {
  4904. OCPP_query_occupancyDeduct_info();
  4905. refreshStartTimer(&clientTime.TcciQueryOccupancyDeduct);
  4906. }
  4907. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4908. {
  4909. // ClockAlign MeterValue
  4910. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4911. {
  4912. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4913. {
  4914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4915. {
  4916. tempIndex = ((gun_index==2) ? 1: 0);
  4917. }
  4918. else
  4919. {
  4920. tempIndex = gun_index;
  4921. }
  4922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4923. {
  4924. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4925. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4926. {
  4927. reqClockAlignMeter[gun_index] = 1;
  4928. }
  4929. }// End for CHAdeMO
  4930. }
  4931. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4932. {
  4933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4934. {
  4935. tempIndex = ((gun_index==2) ? 1: 0);
  4936. }
  4937. else
  4938. {
  4939. tempIndex = gun_index;
  4940. }
  4941. for (int index = 0; index < CCS_QUANTITY; index++)
  4942. {
  4943. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4944. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4945. {
  4946. reqClockAlignMeter[gun_index] = 1;
  4947. }
  4948. } // End for CCS
  4949. }
  4950. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4951. {
  4952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4953. {
  4954. tempIndex = ((gun_index==2) ? 1: 0);
  4955. }
  4956. else
  4957. {
  4958. tempIndex = gun_index;
  4959. }
  4960. for (int index = 0; index < GB_QUANTITY; index++)
  4961. {
  4962. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4963. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4964. {
  4965. reqClockAlignMeter[gun_index] = 1;
  4966. }
  4967. }// End for GB
  4968. }
  4969. else if(gunType[gun_index] == GUN_TYPE_DO)
  4970. {
  4971. tempIndex = gun_index;
  4972. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4973. {
  4974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4975. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4976. {
  4977. reqClockAlignMeter[gun_index] = 1;
  4978. }
  4979. }
  4980. }
  4981. else
  4982. {
  4983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4984. {
  4985. tempIndex = 2;
  4986. }
  4987. else
  4988. {
  4989. tempIndex = gun_index;
  4990. }
  4991. for (int index = 0; index < AC_QUANTITY; index++)
  4992. {
  4993. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4994. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4995. {
  4996. reqClockAlignMeter[gun_index] = 1;
  4997. }
  4998. }//End for AC
  4999. }
  5000. }
  5001. }
  5002. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  5003. {
  5004. //==========================================
  5005. // Check remote start without connector id
  5006. //==========================================
  5007. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  5008. {
  5009. int connectorIdInt = -1;
  5010. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  5011. {
  5012. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  5013. {
  5014. connectorIdInt = (gun_index+1);
  5015. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  5016. checkRemoteStart(connectorIdInt);
  5017. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  5018. break;
  5019. }
  5020. }
  5021. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  5022. {
  5023. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5024. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  5025. }
  5026. }
  5027. //==========================================
  5028. // csu trigger DataTransferReq
  5029. //==========================================
  5030. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  5031. {
  5032. sendDataTransferRequest(gun_index);
  5033. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  5034. }
  5035. //==========================================
  5036. // CSU Trigger Authorize Request
  5037. //==========================================
  5038. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  5039. {
  5040. sendAuthorizeRequest(0);
  5041. authorizeRetryTimes = authorizeRetryTimes + 1;
  5042. if(authorizeRetryTimes < 3)
  5043. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5044. }
  5045. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  5046. {
  5047. authorizeRetryTimes = 0;
  5048. SetOcppConnStatus(FALSE);
  5049. server_sign = FALSE;
  5050. }
  5051. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  5052. {
  5053. sendAuthorizeRequest(0);
  5054. }
  5055. //==========================================
  5056. // Charger start transaction
  5057. //==========================================
  5058. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  5059. {
  5060. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  5061. meterValueBufferClear(gun_index);
  5062. sendStartTransactionRequest(gun_index);
  5063. refreshStartTimer(&clientTime.StartTransaction);
  5064. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5065. storeTempStopTransaction(gun_index);
  5066. }
  5067. //==========================================
  5068. // Charger stop transaction
  5069. //==========================================
  5070. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  5071. {
  5072. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5073. sendStopTransactionRequest(gun_index);
  5074. OCPP_updatePeriodEnergy(gun_index);
  5075. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  5076. refreshStartTimer(&clientTime.StopTransaction);
  5077. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  5078. }
  5079. //==========================================
  5080. // Charger OCMF message
  5081. //==========================================
  5082. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  5083. {
  5084. sendOcmfByDataTransferRequest(gun_index);
  5085. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  5086. }
  5087. //==========================================
  5088. // Charger status report
  5089. //==========================================
  5090. //--- Check Mode Change ---//
  5091. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5092. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5093. {
  5094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5095. {
  5096. tempIndex = ((gun_index==2) ? 1: 0);
  5097. }
  5098. else
  5099. {
  5100. tempIndex = gun_index;
  5101. }
  5102. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5103. {
  5104. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5105. {
  5106. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5107. {
  5108. // Sent unplug message for California pricing logic
  5109. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  5110. {
  5111. uint8_t ts[36];
  5112. getNowDatetime(ts);
  5113. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5114. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5115. if(strcmp((char*)dmsVersion, "2.0")==0)
  5116. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5117. else
  5118. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5119. sendUnplugByDataTransferRequest(gun_index);
  5120. interLock.isSentUnplug[gun_index] = 1;
  5121. }
  5122. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5123. {
  5124. interLock.isSentUnplug[gun_index] = 0;
  5125. }
  5126. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5127. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5128. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5129. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5130. {
  5131. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5132. if((access(filenmae,F_OK))!=-1)
  5133. {
  5134. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5135. sprintf(str,"rm -f %s",filenmae);
  5136. system(str);
  5137. }
  5138. }
  5139. }
  5140. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5141. #if 1 // for TempStopTransaction
  5142. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5143. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5144. {
  5145. checkTempStopTransaction(gun_index);
  5146. }
  5147. #endif
  5148. }
  5149. }
  5150. }
  5151. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5152. {
  5153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5154. {
  5155. tempIndex = ((gun_index==2) ? 1: 0);
  5156. }
  5157. else
  5158. {
  5159. tempIndex = gun_index;
  5160. }
  5161. for (int index = 0; index < CCS_QUANTITY; index++)
  5162. {
  5163. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5164. {
  5165. if((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]*/ )
  5166. {
  5167. // Sent unplug message for California pricing logic
  5168. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  5169. {
  5170. uint8_t ts[36];
  5171. getNowDatetime(ts);
  5172. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5173. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5174. if(strcmp((char*)dmsVersion, "2.0")==0)
  5175. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5176. else
  5177. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5178. sendUnplugByDataTransferRequest(gun_index);
  5179. interLock.isSentUnplug[gun_index] = 1;
  5180. }
  5181. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5182. {
  5183. interLock.isSentUnplug[gun_index] = 0;
  5184. }
  5185. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  5186. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  5187. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5188. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5189. {
  5190. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5191. if((access(filenmae,F_OK))!=-1)
  5192. {
  5193. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5194. sprintf(str,"rm -f %s",filenmae);
  5195. system(str);
  5196. }
  5197. }
  5198. }
  5199. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5200. #if 1 // for TempStopTransaction
  5201. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5202. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5203. {
  5204. checkTempStopTransaction(gun_index);
  5205. }
  5206. #endif
  5207. }
  5208. }
  5209. }
  5210. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5211. {
  5212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5213. {
  5214. tempIndex = ((gun_index==2) ? 1: 0);
  5215. }
  5216. else
  5217. {
  5218. tempIndex = gun_index;
  5219. }
  5220. for (int index = 0; index < GB_QUANTITY; index++)
  5221. {
  5222. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5223. {
  5224. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5225. {
  5226. // Sent unplug message for California pricing logic
  5227. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  5228. {
  5229. uint8_t ts[36];
  5230. getNowDatetime(ts);
  5231. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5232. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5233. if(strcmp((char*)dmsVersion, "2.0")==0)
  5234. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5235. else
  5236. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5237. sendUnplugByDataTransferRequest(gun_index);
  5238. interLock.isSentUnplug[gun_index] = 1;
  5239. }
  5240. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5241. {
  5242. interLock.isSentUnplug[gun_index] = 0;
  5243. }
  5244. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5245. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5246. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5247. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5248. {
  5249. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5250. if((access(filenmae,F_OK))!=-1)
  5251. {
  5252. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5253. sprintf(str,"rm -f %s",filenmae);
  5254. system(str);
  5255. }
  5256. }
  5257. }
  5258. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5259. #if 1 // for TempStopTransaction
  5260. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5261. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5262. {
  5263. checkTempStopTransaction(gun_index);
  5264. }
  5265. #endif
  5266. }
  5267. }
  5268. }
  5269. else if(gunType[gun_index] == GUN_TYPE_DO)
  5270. {
  5271. tempIndex = gun_index;
  5272. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5273. {
  5274. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5275. {
  5276. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5277. {
  5278. // Sent unplug message for California pricing logic
  5279. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  5280. {
  5281. uint8_t ts[36];
  5282. getNowDatetime(ts);
  5283. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5284. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5285. if(strcmp((char*)dmsVersion, "2.0")==0)
  5286. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5287. else
  5288. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5289. sendUnplugByDataTransferRequest(gun_index);
  5290. interLock.isSentUnplug[gun_index] = 1;
  5291. }
  5292. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  5293. {
  5294. interLock.isSentUnplug[gun_index] = 0;
  5295. }
  5296. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5297. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5298. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5299. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  5300. {
  5301. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5302. if((access(filenmae,F_OK))!=-1)
  5303. {
  5304. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5305. sprintf(str,"rm -f %s",filenmae);
  5306. system(str);
  5307. }
  5308. }
  5309. }
  5310. 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);
  5311. #if 1 // for TempStopTransaction
  5312. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5313. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5314. {
  5315. checkTempStopTransaction(gun_index);
  5316. }
  5317. #endif
  5318. }
  5319. }
  5320. }
  5321. else
  5322. {
  5323. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5324. {
  5325. tempIndex = 2;
  5326. }
  5327. else
  5328. {
  5329. tempIndex = gun_index;
  5330. }
  5331. for (int index = 0; index < AC_QUANTITY; index++)
  5332. {
  5333. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5334. {
  5335. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5336. {
  5337. // Sent unplug message for California pricing logic
  5338. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  5339. {
  5340. uint8_t ts[36];
  5341. getNowDatetime(ts);
  5342. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5343. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5344. if(strcmp((char*)dmsVersion, "2.0")==0)
  5345. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5346. else
  5347. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5348. sendUnplugByDataTransferRequest(gun_index);
  5349. interLock.isSentUnplug[gun_index] = 1;
  5350. }
  5351. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5352. {
  5353. interLock.isSentUnplug[gun_index] = 0;
  5354. }
  5355. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5356. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5357. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5358. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5359. {
  5360. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5361. if((access(filenmae,F_OK))!=-1)
  5362. {
  5363. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5364. sprintf(str,"rm -f %s",filenmae);
  5365. system(str);
  5366. }
  5367. }
  5368. }
  5369. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5370. #if 1 // for TempStopTransaction
  5371. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5372. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5373. {
  5374. checkTempStopTransaction(gun_index);
  5375. }
  5376. #endif
  5377. }
  5378. }// END
  5379. }
  5380. if(isWebsocketSendable && (server_sign == TRUE) && (isConnector0Unavailable() != Connector0PreviousSystemStatus))
  5381. {
  5382. sendConnector0StatusNotificationRequest();
  5383. Connector0PreviousSystemStatus = isConnector0Unavailable();
  5384. }
  5385. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  5386. (
  5387. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  5388. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  5389. )
  5390. )
  5391. {
  5392. sendStatusNotificationRequest(gun_index);
  5393. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  5394. }
  5395. //==============================================
  5396. // TCCI related DataTransfer messages
  5397. //==============================================
  5398. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  5399. {
  5400. reportReaderStatus(gun_index);
  5401. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5402. }
  5403. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq == 1))
  5404. {
  5405. occupancyFeeAct(gun_index);
  5406. }
  5407. //==============================================
  5408. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5409. //==============================================
  5410. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5411. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData))))
  5412. {
  5413. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5414. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5415. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5416. }
  5417. //==============================================
  5418. // Meter report
  5419. //==============================================
  5420. // Trigger MeterValue
  5421. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5422. {
  5423. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5424. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5425. }
  5426. // Clock-aligned Meter value
  5427. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5428. {
  5429. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5430. reqClockAlignMeter[gun_index] = 0;
  5431. }
  5432. // Sample period MeterValue
  5433. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  5434. {
  5435. //check Transaction active
  5436. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5437. {
  5438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5439. {
  5440. tempIndex = ((gun_index==2) ? 1: 0);
  5441. }
  5442. else
  5443. {
  5444. tempIndex = gun_index;
  5445. }
  5446. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5447. {
  5448. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5449. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5450. {
  5451. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5452. {
  5453. reqSampleMeter[gun_index] = 1;
  5454. }
  5455. }
  5456. }// End for CHAdeMO
  5457. }
  5458. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5459. {
  5460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5461. {
  5462. tempIndex = ((gun_index==2) ? 1: 0);
  5463. }
  5464. else
  5465. {
  5466. tempIndex = gun_index;
  5467. }
  5468. for (int index = 0; index < CCS_QUANTITY; index++)
  5469. {
  5470. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5471. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5472. {
  5473. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5474. {
  5475. reqSampleMeter[gun_index] = 1;
  5476. }
  5477. }
  5478. } // End for CCS
  5479. }
  5480. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5481. {
  5482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5483. {
  5484. tempIndex = ((gun_index==2) ? 1: 0);
  5485. }
  5486. else
  5487. {
  5488. tempIndex = gun_index;
  5489. }
  5490. for (int index = 0; index < GB_QUANTITY; index++)
  5491. {
  5492. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5493. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5494. {
  5495. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5496. {
  5497. reqSampleMeter[gun_index] = 1;
  5498. }
  5499. }
  5500. }// End for GB
  5501. }
  5502. else if(gunType[gun_index] == GUN_TYPE_DO)
  5503. {
  5504. tempIndex = gun_index;
  5505. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5506. {
  5507. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5508. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5509. {
  5510. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5511. {
  5512. reqSampleMeter[gun_index] = 1;
  5513. }
  5514. }
  5515. }
  5516. }
  5517. else
  5518. {
  5519. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5520. {
  5521. tempIndex = 2;
  5522. }
  5523. else
  5524. {
  5525. tempIndex = gun_index;
  5526. }
  5527. for (int index = 0; index < AC_QUANTITY; index++)
  5528. {
  5529. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5530. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5531. {
  5532. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5533. {
  5534. reqSampleMeter[gun_index] = 1;
  5535. }
  5536. }
  5537. }//End for AC
  5538. }
  5539. if(reqSampleMeter[gun_index] == 1)
  5540. {
  5541. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5542. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5543. storeTempStopTransaction(gun_index);
  5544. reqSampleMeter[gun_index] = 0;
  5545. }
  5546. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5547. }
  5548. //==============================================
  5549. // Check Connector reserved
  5550. //==============================================
  5551. //===============================
  5552. // Check if Reserve is expired
  5553. //===============================
  5554. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5555. {
  5556. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5557. {
  5558. DEBUG_INFO("reserve expired.\n");
  5559. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5560. }
  5561. }//END OF Check if Reserve is expired
  5562. //==========================================
  5563. // csu trigger FirmwareStatusNotificationReq
  5564. //==========================================
  5565. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5566. {
  5567. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5568. }
  5569. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5570. {
  5571. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5572. }
  5573. //==========================================
  5574. // csu trigger DiagnosticsStatusNotificationReq
  5575. //==========================================
  5576. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5577. {
  5578. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5579. }
  5580. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5581. {
  5582. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5583. }
  5584. //==========================================
  5585. // csu trigger CancelReservationConf
  5586. //==========================================
  5587. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5588. {
  5589. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5590. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5591. }
  5592. //==========================================
  5593. // csu trigger ChangeAvailabilityConf
  5594. //==========================================
  5595. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5596. {
  5597. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5598. }
  5599. //==========================================
  5600. // csu trigger UnlockConnectorConf
  5601. //==========================================
  5602. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5603. {
  5604. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5605. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5606. }
  5607. //==========================================
  5608. // csu trigger ReserveNowConf
  5609. //==========================================
  5610. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5611. {
  5612. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5613. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5614. }
  5615. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5616. {
  5617. sendSignCertificateRequest();
  5618. }
  5619. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5620. {
  5621. sendSecurityEventNotificationRequest();
  5622. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5623. }
  5624. // Support 15118
  5625. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5626. {
  5627. json_object *data = json_object_new_object();
  5628. // Read csr file content
  5629. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5630. FILE *fp=fopen(CSR_V2G,"r");
  5631. char *line = NULL;
  5632. size_t len = 0;
  5633. while(getline(&line, &len, fp) != -1)
  5634. {
  5635. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5636. {
  5637. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5638. }
  5639. }
  5640. fclose(fp);
  5641. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5642. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5643. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5644. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5645. json_object_put(data);
  5646. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5647. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5648. }
  5649. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5650. {
  5651. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5652. int parseCertResult = FAIL;
  5653. json_object *data = json_object_new_object();
  5654. json_object *idToken = json_object_new_object();
  5655. json_object *iso15118CertificateHashData = json_object_new_array();
  5656. // Read CERTIFICATE_PnCAuth file content
  5657. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5658. {
  5659. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5660. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5661. char *line = NULL;
  5662. size_t len = 0;
  5663. while(getline(&line, &len, fp) != -1)
  5664. {
  5665. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5666. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5667. }
  5668. fclose(fp);
  5669. }
  5670. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5671. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5672. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5673. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5674. json_object_object_add(data, "idToken", idToken);
  5675. char parseData[512] = {0};
  5676. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5677. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5678. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5679. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5680. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5681. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5682. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5683. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5684. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5685. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5686. for(int idx=0; idx < 4; idx++)
  5687. {
  5688. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5689. {
  5690. json_object *OCSPRequestDataType = json_object_new_object();
  5691. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5692. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5693. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5694. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5695. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5696. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5697. parseCertResult = PASS;
  5698. }
  5699. }
  5700. if(parseCertResult == PASS)
  5701. {
  5702. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5703. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5704. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5705. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5706. json_object_put(data);
  5707. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5708. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5709. }
  5710. else
  5711. {
  5712. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5713. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5714. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5715. }
  5716. }
  5717. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5718. {
  5719. json_object *data = json_object_new_object();
  5720. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5721. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5722. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5723. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5724. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5725. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5726. json_object_put(data);
  5727. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5728. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5729. }
  5730. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5731. {
  5732. json_object *data = json_object_new_object();
  5733. json_object *OCSPRequestDataType = json_object_new_object();
  5734. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5735. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5736. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5737. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5738. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5739. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5740. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5741. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5742. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5743. json_object_put(data);
  5744. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5745. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5746. }
  5747. }
  5748. }
  5749. //==========================================
  5750. // send request routine
  5751. //==========================================
  5752. int sendAuthorizeRequest(int gun_index)
  5753. {
  5754. mtrace();
  5755. int result = FAIL;
  5756. char message[100]={0};
  5757. char guid[37];
  5758. char tempdata[65]={0};
  5759. DEBUG_INFO("sendAuthorizeRequest...\n");
  5760. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5761. //Local Authorize
  5762. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5763. {
  5764. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5765. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5766. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5767. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5768. result = PASS;
  5769. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5770. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5771. authorizeRetryTimes = 0;
  5772. return result;
  5773. }
  5774. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  5775. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5776. {
  5777. // Query from cache
  5778. DEBUG_INFO("Authorize from cache.\n");
  5779. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5780. // Query from list
  5781. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5782. {
  5783. DEBUG_INFO("Authorize from list.\n");
  5784. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5785. }
  5786. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5787. {
  5788. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5789. {
  5790. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5791. }
  5792. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5793. {
  5794. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5795. }
  5796. if(!GetOcppConnStatus())
  5797. {
  5798. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5799. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5800. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5801. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5802. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5803. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5804. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5805. authorizeRetryTimes = 0;
  5806. return result;
  5807. }
  5808. }
  5809. else
  5810. {
  5811. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5812. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5813. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5814. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5815. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5816. else
  5817. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5818. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5819. result = PASS;
  5820. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5821. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5822. authorizeRetryTimes = 0;
  5823. return result;
  5824. }
  5825. }
  5826. //initialize struct Authorize
  5827. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5828. //get data from shared memory
  5829. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5830. random_uuid(guid);
  5831. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5832. LWS_Send(message);
  5833. sprintf(tempdata, "Authorize,%d", gun_index);
  5834. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5835. {
  5836. result = PASS;
  5837. DEBUG_INFO("Authorize mapItem pass\n");
  5838. }
  5839. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5840. return result;
  5841. }
  5842. int sendBootNotificationRequest(void)
  5843. {
  5844. mtrace();
  5845. int result = FAIL;
  5846. char message[500]={0}, payload[700]={0};
  5847. char guid[37]={0};
  5848. char tempdata[65]={0};
  5849. // Fill BootNotification fields
  5850. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5851. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5852. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5853. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5854. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5855. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5856. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5857. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5858. ShmOCPP16Data->ChargeBoxId
  5859. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5860. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5861. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5862. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5863. ,ShmOCPP16Data->BootNotification.CpIccid
  5864. ,ShmOCPP16Data->BootNotification.CpImsi);
  5865. random_uuid(guid);
  5866. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5867. LWS_Send(message);
  5868. sprintf(tempdata, "BootNotification,0");
  5869. 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*/)
  5870. {
  5871. result = PASS;
  5872. }
  5873. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5874. strcpy(queuedata,message);
  5875. return result;
  5876. }
  5877. int sendDataTransferRequest(int gun_index)
  5878. {
  5879. mtrace();
  5880. char message[10240]={0};
  5881. char guid[37]={0};
  5882. char tempdata[65]={0};
  5883. int result = FAIL;
  5884. json_object *DataTransfer = json_object_new_object();
  5885. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5886. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5887. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5888. random_uuid(guid);
  5889. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5890. guid,
  5891. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5892. json_object_put(DataTransfer);
  5893. LWS_Send(message);
  5894. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5895. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5896. {
  5897. result = PASS;
  5898. DEBUG_INFO("DataTransfer mapItem pass\n");
  5899. }
  5900. return result;
  5901. }
  5902. int sendUnplugByDataTransferRequest(int gun_index)
  5903. {
  5904. mtrace();
  5905. char message[10752]={0};
  5906. char guid[37]={0};
  5907. char tempdata[65]={0};
  5908. int result = FAIL;
  5909. random_uuid(guid);
  5910. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5911. (gun_index+1),
  5912. MESSAGE_TYPE_CALL,
  5913. guid,
  5914. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5915. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5916. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5917. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5918. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5919. {
  5920. result = PASS;
  5921. DEBUG_INFO("DataTransfer mapItem pass\n");
  5922. }
  5923. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5924. return result;
  5925. }
  5926. int sendOcmfByDataTransferRequest(int gun_index)
  5927. {
  5928. mtrace();
  5929. json_object *DataTransfer = json_object_new_object();
  5930. json_object *data = json_object_new_object();
  5931. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5932. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5933. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5934. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5935. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5936. json_object_object_add(DataTransfer, "data", data);
  5937. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5938. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5939. char message[3000]={0};
  5940. char guid[37]={0};
  5941. char tempdata[65]={0};
  5942. int result = FAIL;
  5943. random_uuid(guid);
  5944. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5945. (gun_index+1),
  5946. MESSAGE_TYPE_CALL,
  5947. guid,
  5948. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5949. json_object_put(DataTransfer);
  5950. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5951. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5952. {
  5953. result = PASS;
  5954. DEBUG_INFO("DataTransfer mapItem pass\n");
  5955. }
  5956. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5957. return result;
  5958. }
  5959. int sendDiagnosticsStatusNotificationRequest(char *status)
  5960. {
  5961. mtrace();
  5962. int result = FAIL;
  5963. char message[110]={0};
  5964. char guid[37]={0};
  5965. char tempdata[65]={0};
  5966. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5967. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5968. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5969. random_uuid(guid);
  5970. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5971. LWS_SendNow(message);
  5972. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5973. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5974. {
  5975. result = PASS;
  5976. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5977. }
  5978. //#ifdef SystemLogMessage
  5979. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5980. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5981. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5982. //#endif
  5983. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5984. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5985. //record status
  5986. if(strcmp(status,"Idle")==0)
  5987. {
  5988. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5989. }
  5990. else if(strcmp(status,"Uploaded")==0)
  5991. {
  5992. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5993. }
  5994. else if(strcmp(status,"UploadFailed")==0)
  5995. {
  5996. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5997. }
  5998. else if(strcmp(status,"Uploading")==0)
  5999. {
  6000. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  6001. }
  6002. return result;
  6003. }
  6004. int sendFirmwareStatusNotificationRequest(char *status)
  6005. {
  6006. mtrace();
  6007. int result = FAIL;
  6008. char message[110]={0};
  6009. char guid[37]={0};
  6010. char tempdata[65]={0};
  6011. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  6012. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  6013. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  6014. random_uuid(guid);
  6015. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  6016. LWS_SendNow(message);
  6017. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6018. 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*/)
  6019. {
  6020. result = PASS;
  6021. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  6022. }
  6023. //#ifdef SystemLogMessage
  6024. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  6025. //DEBUG_INFO("Message: %s\n", SendBuffer);
  6026. //#endif
  6027. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  6028. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  6029. //record status
  6030. if(strcmp(status,"Downloaded")==0)
  6031. {
  6032. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  6033. }
  6034. else if(strcmp(status,"DownloadFailed")==0)
  6035. {
  6036. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  6037. }
  6038. else if(strcmp(status,"Downloading")==0)
  6039. {
  6040. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  6041. }
  6042. else if(strcmp(status,"Idle")==0)
  6043. {
  6044. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  6045. }
  6046. else if(strcmp(status,"InstallationFailed")==0)
  6047. {
  6048. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  6049. }
  6050. else if(strcmp(status,"Installing")==0)
  6051. {
  6052. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  6053. }
  6054. else if(strcmp(status,"Installed")==0)
  6055. {
  6056. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  6057. }
  6058. return result;
  6059. }
  6060. int sendHeartbeatRequest(int gun_index)
  6061. {
  6062. mtrace();
  6063. int result = FAIL;
  6064. char message[80]={0};
  6065. char guid[37]={0};
  6066. char tempdata[65]={0};
  6067. random_uuid(guid);
  6068. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  6069. , MESSAGE_TYPE_CALL
  6070. , guid );
  6071. LWS_Send(message);
  6072. sprintf(tempdata, "Heartbeat,%d", 0);
  6073. 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*/)
  6074. {
  6075. result = PASS;
  6076. }
  6077. return result;
  6078. }
  6079. int sendStartTransactionRequest(int gun_index)
  6080. {
  6081. mtrace();
  6082. int result = FAIL;
  6083. char message[250]={0};
  6084. char guid[37]={0};
  6085. struct timeval tmnow;
  6086. struct tm *tm;
  6087. char buf[28];//, usec_buf[6];
  6088. char tempdata[65]={0};
  6089. int tempIndex = 0;
  6090. DEBUG_INFO("sendStartTransactionRequest...\n");
  6091. gettimeofday(&tmnow, NULL);
  6092. time_t t;
  6093. t = time(NULL);
  6094. /*UTC time and date*/
  6095. tm = gmtime(&t);
  6096. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6097. #if 0 // remove temporally
  6098. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6099. strcat(buf,".");
  6100. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6101. strcat(buf,usec_buf);
  6102. #endif
  6103. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  6104. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  6105. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6106. // clear StartTransaction Response
  6107. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  6108. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  6109. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  6110. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  6111. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6112. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6113. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6114. {
  6115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6116. {
  6117. tempIndex = ((gun_index==2) ? 1: 0);
  6118. }
  6119. else
  6120. {
  6121. tempIndex = gun_index;
  6122. }
  6123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6124. {
  6125. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6126. {
  6127. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6128. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  6129. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6130. }
  6131. }
  6132. }
  6133. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6134. {
  6135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6136. {
  6137. tempIndex = ((gun_index==2) ? 1: 0);
  6138. }
  6139. else
  6140. {
  6141. tempIndex = gun_index;
  6142. }
  6143. for (int index = 0; index < CCS_QUANTITY; index++)
  6144. {
  6145. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6146. {
  6147. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6148. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  6149. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6150. }
  6151. }
  6152. }
  6153. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6154. {
  6155. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6156. {
  6157. tempIndex = ((gun_index==2) ? 1: 0);
  6158. }
  6159. else
  6160. {
  6161. tempIndex = gun_index;
  6162. }
  6163. for (int index = 0; index < GB_QUANTITY; index++)
  6164. {
  6165. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6166. {
  6167. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6168. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  6169. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6170. }
  6171. }
  6172. }
  6173. else if(gunType[gun_index] == GUN_TYPE_DO)
  6174. {
  6175. tempIndex = gun_index;
  6176. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6177. {
  6178. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6179. {
  6180. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6181. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  6182. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6183. }
  6184. }
  6185. }
  6186. else
  6187. {
  6188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6189. {
  6190. tempIndex = 2;
  6191. }
  6192. else
  6193. {
  6194. tempIndex = gun_index;
  6195. }
  6196. for (int index = 0; index < AC_QUANTITY; index++)
  6197. {
  6198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6199. {
  6200. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6201. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  6202. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6203. }
  6204. }
  6205. }
  6206. random_uuid(guid);
  6207. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  6208. {
  6209. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  6210. , gun_index +1
  6211. , MESSAGE_TYPE_CALL
  6212. , guid
  6213. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6214. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6215. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6216. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6217. }
  6218. else
  6219. {
  6220. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  6221. , gun_index +1
  6222. , MESSAGE_TYPE_CALL
  6223. , guid
  6224. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6225. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6226. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6227. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  6228. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6229. }
  6230. #if 1
  6231. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  6232. 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*/)
  6233. {
  6234. result = PASS;
  6235. }
  6236. #endif
  6237. strcpy(queuedata, message);
  6238. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6239. OCPP_insert_transaction_msg(YES, queuedata);
  6240. return result;
  6241. }
  6242. int sendConnector0StatusNotificationRequest()
  6243. {
  6244. mtrace();
  6245. int result = FAIL;
  6246. char message[600]={0};
  6247. char guid[37];
  6248. struct timeval tmnow;
  6249. struct tm *tm;
  6250. char buf[28];//, usec_buf[6];
  6251. char tempdata[65]={0};
  6252. DEBUG_INFO("sendConnector0StatusNotificationRequest...\n");
  6253. gettimeofday(&tmnow, NULL);
  6254. time_t t;
  6255. t = time(NULL);
  6256. /*UTC time and date*/
  6257. tm = gmtime(&t);
  6258. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6259. random_uuid(guid);
  6260. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":0,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6261. , MESSAGE_TYPE_CALL
  6262. , guid
  6263. , "NoError"
  6264. , ""
  6265. , (isConnector0Unavailable()==YES?"Unavailable":"Available")
  6266. , buf
  6267. , ShmSysConfigAndInfo->SysConfig.chargePointVendor
  6268. , "");
  6269. LWS_Send(message);
  6270. sprintf(tempdata, "StatusNotification,%d", 99);
  6271. 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*/)
  6272. {
  6273. //DEBUG_ERROR("statusNotification mapitem pass");
  6274. result = PASS;
  6275. }
  6276. return result;
  6277. }
  6278. int sendStatusNotificationRequest(int gun_index)
  6279. {
  6280. mtrace();
  6281. int result = FAIL;
  6282. char message[600]={0};
  6283. char guid[37];
  6284. int currentStatus = 0;
  6285. struct timeval tmnow;
  6286. struct tm *tm;
  6287. char buf[28];//, usec_buf[6];
  6288. char tempdata[65]={0};
  6289. int tempIndex = 0;
  6290. uint8_t isStateChanged = TRUE;
  6291. uint8_t isContentIllegal = TRUE;
  6292. DEBUG_INFO("sendStatusNotificationRequest...\n");
  6293. gettimeofday(&tmnow, NULL);
  6294. time_t t;
  6295. t = time(NULL);
  6296. /*UTC time and date*/
  6297. tm = gmtime(&t);
  6298. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6299. #if 0 // remove temporally
  6300. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6301. strcat(buf,".");
  6302. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6303. strcat(buf,usec_buf);
  6304. #endif
  6305. //printf("%s",buf);
  6306. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  6307. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  6308. // it's option
  6309. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  6310. /*
  6311. enum _SYSTEM_STATUS
  6312. {
  6313. S_BOOTING = 0,
  6314. S_IDLE, = 1
  6315. S_AUTHORIZING, =2
  6316. S_REASSIGN_CHECK, =3
  6317. S_REASSIGN, =4
  6318. S_PRECHARGE, =5
  6319. S_PREPARING_FOR_EV, =6
  6320. S_PREPARING_FOR_EVSE, =7
  6321. S_CHARGING, =8
  6322. S_TERMINATING, =9
  6323. S_COMPLETE, =10
  6324. S_ALARM, =11
  6325. S_FAULT =12
  6326. }
  6327. */
  6328. //check Transaction active
  6329. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6330. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6331. {
  6332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6333. {
  6334. tempIndex = ((gun_index==2) ? 1: 0);
  6335. }
  6336. else
  6337. {
  6338. tempIndex = gun_index;
  6339. }
  6340. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6341. {
  6342. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6343. {
  6344. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6345. {
  6346. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6347. {
  6348. currentStatus = Preparing; //OCPP Status: Preparing
  6349. }
  6350. else
  6351. {
  6352. currentStatus = Available; //OCPP Status: Available
  6353. }
  6354. }
  6355. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6356. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6357. ) //S_PRECHARGE
  6358. {
  6359. currentStatus = Preparing; //OCPP Status: Preparing
  6360. }
  6361. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6362. {
  6363. currentStatus = Charging; //OCPP Status: Charging
  6364. }
  6365. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6366. {
  6367. currentStatus = Finishing; //OCPP Status: Finishing
  6368. }
  6369. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6370. {
  6371. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6372. }
  6373. 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
  6374. {
  6375. currentStatus = Unavailable; //OCPP Status: Unavailable
  6376. }
  6377. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6378. {
  6379. currentStatus = Faulted; //OCPP Status: Faulted
  6380. }
  6381. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6382. {
  6383. currentStatus = Reserved; //OCPP Status: Reserved
  6384. }
  6385. } //end of the same index
  6386. }//end of for CHAdeMO_QUANTITY
  6387. }
  6388. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6389. {
  6390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6391. {
  6392. tempIndex = ((gun_index==2) ? 1: 0);
  6393. }
  6394. else
  6395. {
  6396. tempIndex = gun_index;
  6397. }
  6398. for (int index = 0; index < CCS_QUANTITY; index++)
  6399. {
  6400. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6401. {
  6402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6403. {
  6404. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  6405. {
  6406. currentStatus = Preparing; //OCPP Status: Preparing
  6407. }
  6408. else
  6409. {
  6410. currentStatus = Available; //OCPP Status: Available
  6411. }
  6412. }
  6413. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6414. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6415. ) //S_PRECHARGE
  6416. {
  6417. currentStatus = Preparing; //OCPP Status: Preparing
  6418. }
  6419. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6420. {
  6421. currentStatus = Charging; //OCPP Status: Charging
  6422. }
  6423. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6424. {
  6425. currentStatus = Finishing; //OCPP Status: Finishing
  6426. }
  6427. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6428. {
  6429. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6430. }
  6431. 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
  6432. {
  6433. currentStatus = Unavailable; //OCPP Status : Unavailable
  6434. }
  6435. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6436. {
  6437. currentStatus = Faulted; //OCPP Status: Faulted
  6438. }
  6439. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6440. {
  6441. currentStatus = Reserved; //OCPP Status: Reserved
  6442. }
  6443. } //end of the same index
  6444. } // end of for CCS_QUANTITY
  6445. }
  6446. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6447. {
  6448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6449. {
  6450. tempIndex = ((gun_index==2) ? 1: 0);
  6451. }
  6452. else
  6453. {
  6454. tempIndex = gun_index;
  6455. }
  6456. for (int index = 0; index < GB_QUANTITY; index++)
  6457. {
  6458. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6459. {
  6460. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6461. {
  6462. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6463. {
  6464. currentStatus = Preparing; //OCPP Status: Preparing
  6465. }
  6466. else
  6467. {
  6468. currentStatus = Available; //OCPP Status: Available
  6469. }
  6470. }
  6471. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6472. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6473. ) //S_PRECHARGE
  6474. {
  6475. currentStatus = Preparing; //OCPP Status: Preparing
  6476. }
  6477. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6478. {
  6479. currentStatus = Charging; //OCPP Status: Charging
  6480. }
  6481. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6482. {
  6483. currentStatus = Finishing; //OCPP Status: Finishing
  6484. }
  6485. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6486. {
  6487. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6488. }
  6489. 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
  6490. {
  6491. currentStatus = Unavailable; //OCPP Status: Unavailable
  6492. }
  6493. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6494. {
  6495. currentStatus = Faulted; //OCPP Status: Faulted
  6496. }
  6497. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6498. {
  6499. currentStatus = Reserved; //OCPP Status: Reserved
  6500. }
  6501. } //end of the same index
  6502. } // end of for GB_QUANTITY
  6503. }
  6504. else if(gunType[gun_index] == GUN_TYPE_DO)
  6505. {
  6506. tempIndex = gun_index;
  6507. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6508. {
  6509. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6510. {
  6511. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6512. {
  6513. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6514. {
  6515. currentStatus = Preparing; //OCPP Status: Preparing
  6516. }
  6517. else
  6518. {
  6519. currentStatus = Available; //OCPP Status: Available
  6520. }
  6521. }
  6522. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6523. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6524. ) //S_PRECHARGE
  6525. {
  6526. currentStatus = Preparing; //OCPP Status: Preparing
  6527. }
  6528. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6529. {
  6530. currentStatus = Charging; //OCPP Status: Charging
  6531. }
  6532. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6533. {
  6534. currentStatus = Finishing; //OCPP Status: Finishing
  6535. }
  6536. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6537. {
  6538. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6539. }
  6540. 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
  6541. {
  6542. currentStatus = Unavailable; //OCPP Status: Unavailable
  6543. }
  6544. 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
  6545. {
  6546. currentStatus = Faulted; //OCPP Status: Faulted
  6547. }
  6548. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6549. {
  6550. currentStatus = Reserved; //OCPP Status: Reserved
  6551. }
  6552. } //end of the same index
  6553. }
  6554. }
  6555. else
  6556. {
  6557. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6558. {
  6559. tempIndex = 2;
  6560. }
  6561. else
  6562. {
  6563. tempIndex = gun_index;
  6564. }
  6565. for (int index = 0; index < AC_QUANTITY; index++)
  6566. {
  6567. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6568. {
  6569. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6570. {
  6571. 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))
  6572. {
  6573. currentStatus = Preparing; //OCPP Status: Preparing
  6574. }
  6575. else
  6576. {
  6577. currentStatus = Available; //OCPP Status: Available
  6578. }
  6579. }
  6580. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6581. {
  6582. currentStatus = Preparing; //OCPP Status: Preparing
  6583. }
  6584. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6585. {
  6586. currentStatus = Charging; //OCPP Status: Charging
  6587. }
  6588. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6589. {
  6590. currentStatus = Finishing; //OCPP Status: Finishing
  6591. }
  6592. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6593. {
  6594. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6595. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6596. else
  6597. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6598. }
  6599. 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
  6600. {
  6601. currentStatus = Unavailable; //OCPP Status: Unavailable
  6602. }
  6603. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6604. {
  6605. currentStatus = Faulted; //OCPP Status: Faulted
  6606. }
  6607. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6608. {
  6609. currentStatus = Reserved; //OCPP Status: Reserved
  6610. }
  6611. }//end of the same index
  6612. }//end of for AC_QUANTITY
  6613. }
  6614. //it's option
  6615. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6616. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6617. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6618. {
  6619. isStateChanged = FALSE;
  6620. }
  6621. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6622. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6623. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6624. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6625. isContentIllegal = TRUE;
  6626. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6627. {
  6628. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6629. {
  6630. isContentIllegal = FALSE;
  6631. break;
  6632. }
  6633. }
  6634. if(isContentIllegal)
  6635. {
  6636. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6637. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6638. }
  6639. random_uuid(guid);
  6640. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6641. , MESSAGE_TYPE_CALL
  6642. , guid
  6643. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6644. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6645. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6646. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6647. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6648. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6649. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6650. if((server_sign == TRUE) && isStateChanged)
  6651. {
  6652. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6653. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6654. LWS_Send(message);
  6655. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6656. 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*/)
  6657. {
  6658. //DEBUG_ERROR("statusNotification mapitem pass");
  6659. result = PASS;
  6660. }
  6661. }
  6662. else
  6663. {
  6664. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6665. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6666. result = PASS;
  6667. }
  6668. return result;
  6669. }
  6670. int sendStopTransactionRequest(int gun_index)
  6671. {
  6672. mtrace();
  6673. int result = FAIL;
  6674. //char message[1500]={0};
  6675. char guid[37]={0};
  6676. char tempdata[65]={0};
  6677. int tempIndex = 0;
  6678. char TempStopTransaction[256];
  6679. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6680. DEBUG_INFO("sendStopTransactionRequest \n");
  6681. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6682. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6683. //=========================== Stop Transaction Time ===============================================
  6684. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  6685. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6686. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6687. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6688. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6689. {
  6690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6691. {
  6692. tempIndex = ((gun_index==2) ? 1: 0);
  6693. }
  6694. else
  6695. {
  6696. tempIndex = gun_index;
  6697. }
  6698. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6699. {
  6700. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6701. {
  6702. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6703. }
  6704. }// END OF CHAdeMO_QUANTITY
  6705. }
  6706. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6707. {
  6708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6709. {
  6710. tempIndex = ((gun_index==2) ? 1: 0);
  6711. }
  6712. else
  6713. {
  6714. tempIndex = gun_index;
  6715. }
  6716. for (int index = 0; index < CCS_QUANTITY; index++)
  6717. {
  6718. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6719. {
  6720. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6721. }
  6722. }// END OF CCS_QUANTITY
  6723. }
  6724. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6725. {
  6726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6727. {
  6728. tempIndex = ((gun_index==2) ? 1: 0);
  6729. }
  6730. else
  6731. {
  6732. tempIndex = gun_index;
  6733. }
  6734. for (int index = 0; index < GB_QUANTITY; index++)
  6735. {
  6736. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6737. {
  6738. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6739. }
  6740. }// END OF GB_QUANTITY
  6741. }
  6742. else if(gunType[gun_index] == GUN_TYPE_DO)
  6743. {
  6744. tempIndex = gun_index;
  6745. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6746. {
  6747. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6748. {
  6749. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6750. }
  6751. }// END OF GB_QUANTITY
  6752. }
  6753. else
  6754. {
  6755. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6756. {
  6757. tempIndex = 2;
  6758. }
  6759. else
  6760. {
  6761. tempIndex = gun_index;
  6762. }
  6763. for (int index = 0; index < AC_QUANTITY; index++)
  6764. {
  6765. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6766. {
  6767. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6768. }
  6769. }// END OF AC_QUANTITY
  6770. }
  6771. //================================================ Message create ====================================================
  6772. json_object *StopTransaction = json_object_new_object();
  6773. json_object *transactionDatas = json_object_new_array();
  6774. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6775. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6776. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6777. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6778. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6779. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6780. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6781. meterValueBufferQuery(gun_index, transactionDatas);
  6782. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6783. random_uuid(guid);
  6784. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6785. ,MESSAGE_TYPE_CALL
  6786. ,guid
  6787. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6788. json_object_put(StopTransaction);
  6789. #if 1 // for TempStopTransaction
  6790. //Delete TempStopTransaction
  6791. if((access(TempStopTransaction,F_OK))!=-1)
  6792. {
  6793. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6794. }
  6795. #endif
  6796. #if 1
  6797. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6798. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6799. {
  6800. result = PASS;
  6801. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6802. }
  6803. #endif
  6804. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6805. OCPP_insert_transaction_msg(NO, queuedata);
  6806. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6807. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6808. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6809. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6810. {
  6811. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6812. }
  6813. //for test
  6814. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6815. return result;
  6816. }
  6817. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6818. {
  6819. mtrace();
  6820. int result = FAIL;
  6821. char guid[37]={0};
  6822. char tempdata[65]={0};
  6823. int tempIndex = 0;
  6824. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6825. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6826. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6827. //set value
  6828. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6829. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6830. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6831. -1);
  6832. random_uuid(guid);
  6833. //UTC Date time
  6834. struct timeval tmnow;
  6835. struct tm *tm;
  6836. char buf[28];//, usec_buf[6];
  6837. gettimeofday(&tmnow, NULL);
  6838. time_t t;
  6839. t = time(NULL);
  6840. /*UTC time and date*/
  6841. tm = gmtime(&t);
  6842. if(dataType == ReadingContext_Sample_Clock)
  6843. {
  6844. struct tm *tmTarget;
  6845. struct timeb tbTarget;
  6846. tbTarget.time = mktime(tm);
  6847. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6848. tmTarget = gmtime(&tbTarget.time);
  6849. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6850. }
  6851. else
  6852. {
  6853. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6854. }
  6855. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6856. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6857. //********************************(1)Current.Import L1************************************************/
  6858. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6859. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6860. (dataType == ReadingContext_Trigger))
  6861. {
  6862. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6863. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6864. {
  6865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6866. {
  6867. tempIndex = ((gun_index==2) ? 1: 0);
  6868. }
  6869. else
  6870. {
  6871. tempIndex = gun_index;
  6872. }
  6873. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6874. {
  6875. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6876. {
  6877. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6878. }
  6879. }
  6880. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6881. }
  6882. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6883. {
  6884. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6885. {
  6886. tempIndex = ((gun_index==2) ? 1: 0);
  6887. }
  6888. else
  6889. {
  6890. tempIndex = gun_index;
  6891. }
  6892. for (int index = 0; index < CCS_QUANTITY; index++)
  6893. {
  6894. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6895. {
  6896. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6897. }
  6898. }
  6899. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6900. }
  6901. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6902. {
  6903. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6904. {
  6905. tempIndex = ((gun_index==2) ? 1: 0);
  6906. }
  6907. else
  6908. {
  6909. tempIndex = gun_index;
  6910. }
  6911. for (int index = 0; index < GB_QUANTITY; index++)
  6912. {
  6913. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6914. {
  6915. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6916. }
  6917. }
  6918. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6919. }
  6920. else if(gunType[gun_index] == GUN_TYPE_DO)
  6921. {
  6922. tempIndex = gun_index;
  6923. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6924. {
  6925. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6926. {
  6927. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6928. }
  6929. }
  6930. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6931. }
  6932. else
  6933. {
  6934. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6935. {
  6936. tempIndex = 2;
  6937. }
  6938. else
  6939. {
  6940. tempIndex = gun_index;
  6941. }
  6942. for (int index = 0; index < AC_QUANTITY; index++)
  6943. {
  6944. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6945. {
  6946. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6947. }
  6948. }
  6949. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6950. }
  6951. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6952. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6953. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6954. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6955. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6956. }
  6957. //********************************(2)Energy.Active.Import.Register ************************************************/
  6958. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6959. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6960. (dataType == ReadingContext_Trigger))
  6961. {
  6962. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6963. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6964. {
  6965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6966. {
  6967. tempIndex = ((gun_index==2) ? 1: 0);
  6968. }
  6969. else
  6970. {
  6971. tempIndex = gun_index;
  6972. }
  6973. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6974. {
  6975. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6976. {
  6977. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6978. }
  6979. }
  6980. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6981. }
  6982. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6983. {
  6984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6985. {
  6986. tempIndex = ((gun_index==2) ? 1: 0);
  6987. }
  6988. else
  6989. {
  6990. tempIndex = gun_index;
  6991. }
  6992. for (int index = 0; index < CCS_QUANTITY; index++)
  6993. {
  6994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6995. {
  6996. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6997. }
  6998. }
  6999. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7000. }
  7001. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7002. {
  7003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7004. {
  7005. tempIndex = ((gun_index==2) ? 1: 0);
  7006. }
  7007. else
  7008. {
  7009. tempIndex = gun_index;
  7010. }
  7011. for (int index = 0; index < GB_QUANTITY; index++)
  7012. {
  7013. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7014. {
  7015. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  7016. }
  7017. }
  7018. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7019. }
  7020. else if(gunType[gun_index] == GUN_TYPE_DO)
  7021. {
  7022. tempIndex = gun_index;
  7023. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7024. {
  7025. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7026. {
  7027. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  7028. }
  7029. }
  7030. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7031. }
  7032. else
  7033. {
  7034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7035. {
  7036. tempIndex = 2;
  7037. }
  7038. else
  7039. {
  7040. tempIndex = gun_index;
  7041. }
  7042. for (int index = 0; index < AC_QUANTITY; index++)
  7043. {
  7044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7045. {
  7046. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7047. }
  7048. }
  7049. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7050. }
  7051. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7052. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7053. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7054. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7055. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7056. }
  7057. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7058. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7059. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7060. (dataType == ReadingContext_Trigger))
  7061. {
  7062. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7063. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7064. {
  7065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7066. {
  7067. tempIndex = ((gun_index==2) ? 1: 0);
  7068. }
  7069. else
  7070. {
  7071. tempIndex = gun_index;
  7072. }
  7073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7074. {
  7075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7076. {
  7077. if(dataType == ReadingContext_Sample_Clock)
  7078. {
  7079. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7080. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7081. }
  7082. else if(dataType == ReadingContext_Sample_Periodic)
  7083. {
  7084. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7085. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7086. }
  7087. else
  7088. {
  7089. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7090. }
  7091. }
  7092. } // END OF FOR CHAdeMO_QUANTITY
  7093. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7094. }
  7095. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7096. {
  7097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7098. {
  7099. tempIndex = ((gun_index==2) ? 1: 0);
  7100. }
  7101. else
  7102. {
  7103. tempIndex = gun_index;
  7104. }
  7105. for (int index = 0; index < CCS_QUANTITY; index++)
  7106. {
  7107. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7108. {
  7109. if(dataType == ReadingContext_Sample_Clock)
  7110. {
  7111. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7112. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7113. }
  7114. else if(dataType == ReadingContext_Sample_Periodic)
  7115. {
  7116. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7117. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7118. }
  7119. else
  7120. {
  7121. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7122. }
  7123. }
  7124. } // END OF CCS_QUANTITY
  7125. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7126. }
  7127. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7128. {
  7129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7130. {
  7131. tempIndex = ((gun_index==2) ? 1: 0);
  7132. }
  7133. else
  7134. {
  7135. tempIndex = gun_index;
  7136. }
  7137. for (int index = 0; index < GB_QUANTITY; index++)
  7138. {
  7139. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7140. {
  7141. if(dataType == ReadingContext_Sample_Clock)
  7142. {
  7143. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7144. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7145. }
  7146. else if(dataType == ReadingContext_Sample_Periodic)
  7147. {
  7148. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7149. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7150. }
  7151. else
  7152. {
  7153. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7154. }
  7155. }
  7156. } // END OF GB_QUANTITY
  7157. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7158. }
  7159. else if(gunType[gun_index] == GUN_TYPE_DO)
  7160. {
  7161. tempIndex = gun_index;
  7162. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7163. {
  7164. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7165. {
  7166. if(dataType == ReadingContext_Sample_Clock)
  7167. {
  7168. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7169. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7170. }
  7171. else if(dataType == ReadingContext_Sample_Periodic)
  7172. {
  7173. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7174. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7175. }
  7176. else
  7177. {
  7178. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7179. }
  7180. }
  7181. }
  7182. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7183. }
  7184. else
  7185. {
  7186. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7187. {
  7188. tempIndex = 2;
  7189. }
  7190. else
  7191. {
  7192. tempIndex = gun_index;
  7193. }
  7194. for (int index = 0; index < AC_QUANTITY; index++)
  7195. {
  7196. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7197. {
  7198. if(dataType == ReadingContext_Sample_Clock)
  7199. {
  7200. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7201. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7202. }
  7203. else if(dataType == ReadingContext_Sample_Periodic)
  7204. {
  7205. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7206. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7207. }
  7208. else
  7209. {
  7210. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7211. }
  7212. }
  7213. }
  7214. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7215. }
  7216. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7217. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7218. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7220. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7221. }
  7222. //********************************(4)Power.Active.Import************************************************/
  7223. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7224. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7225. (dataType == ReadingContext_Trigger))
  7226. {
  7227. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7228. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7229. {
  7230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7231. {
  7232. tempIndex = ((gun_index==2) ? 1: 0);
  7233. }
  7234. else
  7235. {
  7236. tempIndex = gun_index;
  7237. }
  7238. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7239. {
  7240. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7241. {
  7242. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7243. }
  7244. } // END OF FOR
  7245. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7246. }
  7247. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7248. {
  7249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7250. {
  7251. tempIndex = ((gun_index==2) ? 1: 0);
  7252. }
  7253. else
  7254. {
  7255. tempIndex = gun_index;
  7256. }
  7257. for (int index = 0; index < CCS_QUANTITY; index++)
  7258. {
  7259. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7260. {
  7261. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7262. }
  7263. }
  7264. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7265. }
  7266. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7267. {
  7268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7269. {
  7270. tempIndex = ((gun_index==2) ? 1: 0);
  7271. }
  7272. else
  7273. {
  7274. tempIndex = gun_index;
  7275. }
  7276. for (int index = 0; index < GB_QUANTITY; index++)
  7277. {
  7278. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7279. {
  7280. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7281. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7282. }
  7283. }
  7284. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7285. }
  7286. else if(gunType[gun_index] == GUN_TYPE_DO)
  7287. {
  7288. tempIndex = gun_index;
  7289. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7290. {
  7291. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7292. {
  7293. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7294. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7295. }
  7296. }
  7297. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7298. }
  7299. else
  7300. {
  7301. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7302. {
  7303. tempIndex = 2;
  7304. }
  7305. else
  7306. {
  7307. tempIndex = gun_index;
  7308. }
  7309. for (int index = 0; index < AC_QUANTITY; index++)
  7310. {
  7311. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7312. {
  7313. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7314. }
  7315. }
  7316. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7317. }
  7318. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7319. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7320. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7322. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7323. }
  7324. //***********************************************(5)VOLTAGE L1******************************************************/
  7325. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7326. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7327. (dataType == ReadingContext_Trigger))
  7328. {
  7329. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7330. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7331. {
  7332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7333. {
  7334. tempIndex = ((gun_index==2) ? 1: 0);
  7335. }
  7336. else
  7337. {
  7338. tempIndex = gun_index;
  7339. }
  7340. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7341. {
  7342. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7343. {
  7344. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7345. }
  7346. }
  7347. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7348. }
  7349. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7350. {
  7351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7352. {
  7353. tempIndex = ((gun_index==2) ? 1: 0);
  7354. }
  7355. else
  7356. {
  7357. tempIndex = gun_index;
  7358. }
  7359. for (int index = 0; index < CCS_QUANTITY; index++)
  7360. {
  7361. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7362. {
  7363. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7364. }
  7365. }
  7366. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7367. }
  7368. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7369. {
  7370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7371. {
  7372. tempIndex = ((gun_index==2) ? 1: 0);
  7373. }
  7374. else
  7375. {
  7376. tempIndex = gun_index;
  7377. }
  7378. for (int index = 0; index < GB_QUANTITY; index++)
  7379. {
  7380. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7381. {
  7382. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7383. }
  7384. }
  7385. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7386. }
  7387. else if(gunType[gun_index] == GUN_TYPE_DO)
  7388. {
  7389. tempIndex = gun_index;
  7390. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7391. {
  7392. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7393. {
  7394. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7395. }
  7396. }
  7397. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7398. }
  7399. else
  7400. {
  7401. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7402. {
  7403. tempIndex = 2;
  7404. }
  7405. else
  7406. {
  7407. tempIndex = gun_index;
  7408. }
  7409. for (int index = 0; index < AC_QUANTITY; index++)
  7410. {
  7411. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7412. {
  7413. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7414. }
  7415. }
  7416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7417. }
  7418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7422. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7423. }
  7424. //***********************************************(6)SOC******************************************************/
  7425. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7426. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7427. (dataType == ReadingContext_Trigger))
  7428. {
  7429. 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))
  7430. {
  7431. //idx_sample=5;
  7432. //sampledValue = NULL;
  7433. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7434. {
  7435. tempIndex = ((gun_index==2) ? 1: 0);
  7436. }
  7437. else
  7438. {
  7439. tempIndex = gun_index;
  7440. }
  7441. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7442. {
  7443. //tempIndex = ((gun_index==2) ? 1: 0);
  7444. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7445. {
  7446. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7447. {
  7448. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7449. }
  7450. }
  7451. }
  7452. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7453. {
  7454. //tempIndex = ((gun_index==2) ? 1: 0);
  7455. for (int index = 0; index < CCS_QUANTITY; index++)
  7456. {
  7457. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7458. {
  7459. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7460. }
  7461. }
  7462. }
  7463. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7464. {
  7465. //tempIndex = ((gun_index==2) ? 1: 0);
  7466. for (int index = 0; index < GB_QUANTITY; index++)
  7467. {
  7468. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7469. {
  7470. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7471. }
  7472. }
  7473. }
  7474. else if(gunType[gun_index] == GUN_TYPE_DO)
  7475. {
  7476. //tempIndex = ((gun_index==2) ? 1: 0);
  7477. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7478. {
  7479. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7480. {
  7481. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7482. }
  7483. }
  7484. }
  7485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7488. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7491. }
  7492. }
  7493. //********************************(7)Current.Import L2************************************************/
  7494. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7495. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7496. (dataType == ReadingContext_Trigger))
  7497. {
  7498. // Only for AC 3 phase
  7499. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7500. {
  7501. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7502. {
  7503. tempIndex = 2;
  7504. }
  7505. else
  7506. {
  7507. tempIndex = gun_index;
  7508. }
  7509. for (int index = 0; index < AC_QUANTITY; index++)
  7510. {
  7511. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7512. {
  7513. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7514. }
  7515. }
  7516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7517. }
  7518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7523. }
  7524. //********************************(8)Current.Import L3************************************************/
  7525. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7526. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7527. (dataType == ReadingContext_Trigger))
  7528. {
  7529. // Only for AC 3 phase
  7530. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7531. {
  7532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7533. {
  7534. tempIndex = 2;
  7535. }
  7536. else
  7537. {
  7538. tempIndex = gun_index;
  7539. }
  7540. for (int index = 0; index < AC_QUANTITY; index++)
  7541. {
  7542. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7543. {
  7544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7545. }
  7546. }
  7547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7548. }
  7549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7554. }
  7555. //***********************************************(9)VOLTAGE L2******************************************************/
  7556. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7557. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7558. (dataType == ReadingContext_Trigger))
  7559. {
  7560. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7561. {
  7562. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7563. {
  7564. tempIndex = 2;
  7565. }
  7566. else
  7567. {
  7568. tempIndex = gun_index;
  7569. }
  7570. for (int index = 0; index < AC_QUANTITY; index++)
  7571. {
  7572. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7573. {
  7574. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7575. }
  7576. }
  7577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7578. }
  7579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7584. }
  7585. //***********************************************(10)VOLTAGE L3******************************************************/
  7586. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7587. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7588. (dataType == ReadingContext_Trigger))
  7589. {
  7590. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7591. {
  7592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7593. {
  7594. tempIndex = 2;
  7595. }
  7596. else
  7597. {
  7598. tempIndex = gun_index;
  7599. }
  7600. for (int index = 0; index < AC_QUANTITY; index++)
  7601. {
  7602. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7603. {
  7604. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7605. }
  7606. }
  7607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7608. }
  7609. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7614. }
  7615. //***********************************************(11)Current.Offered******************************************************/
  7616. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7617. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7618. (dataType == ReadingContext_Trigger))
  7619. {
  7620. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7621. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7622. {
  7623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7624. {
  7625. tempIndex = ((gun_index==2) ? 1: 0);
  7626. }
  7627. else
  7628. {
  7629. tempIndex = gun_index;
  7630. }
  7631. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7632. {
  7633. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7634. {
  7635. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7636. }
  7637. } // END OF FOR CHAdeMO_QUANTITY
  7638. }
  7639. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7640. {
  7641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7642. {
  7643. tempIndex = ((gun_index==2) ? 1: 0);
  7644. }
  7645. else
  7646. {
  7647. tempIndex = gun_index;
  7648. }
  7649. for (int index = 0; index < CCS_QUANTITY; index++)
  7650. {
  7651. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7652. {
  7653. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7654. }
  7655. } // END OF CCS_QUANTITY
  7656. }
  7657. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7658. {
  7659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7660. {
  7661. tempIndex = ((gun_index==2) ? 1: 0);
  7662. }
  7663. else
  7664. {
  7665. tempIndex = gun_index;
  7666. }
  7667. for (int index = 0; index < GB_QUANTITY; index++)
  7668. {
  7669. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7670. {
  7671. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7672. }
  7673. } // END OF GB_QUANTITY
  7674. }
  7675. else if(gunType[gun_index] == GUN_TYPE_DO)
  7676. {
  7677. tempIndex = gun_index;
  7678. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7679. {
  7680. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7681. {
  7682. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7683. }
  7684. }
  7685. }
  7686. else
  7687. {
  7688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7689. {
  7690. tempIndex = 2;
  7691. }
  7692. else
  7693. {
  7694. tempIndex = gun_index;
  7695. }
  7696. for (int index = 0; index < AC_QUANTITY; index++)
  7697. {
  7698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7699. {
  7700. uint16_t currentOffer;
  7701. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7702. {
  7703. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7704. }
  7705. else
  7706. {
  7707. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7708. }
  7709. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7710. }
  7711. }
  7712. }
  7713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7715. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7716. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7718. }
  7719. //***********************************************(12)Power.Offered******************************************************/
  7720. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7721. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7722. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7723. {
  7724. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7725. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7726. {
  7727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7728. {
  7729. tempIndex = ((gun_index==2) ? 1: 0);
  7730. }
  7731. else
  7732. {
  7733. tempIndex = gun_index;
  7734. }
  7735. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7736. {
  7737. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7738. {
  7739. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7740. }
  7741. } // END OF FOR CHAdeMO_QUANTITY
  7742. }
  7743. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7744. {
  7745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7746. {
  7747. tempIndex = ((gun_index==2) ? 1: 0);
  7748. }
  7749. else
  7750. {
  7751. tempIndex = gun_index;
  7752. }
  7753. for (int index = 0; index < CCS_QUANTITY; index++)
  7754. {
  7755. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7756. {
  7757. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7758. }
  7759. } // END OF CCS_QUANTITY
  7760. }
  7761. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7762. {
  7763. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7764. {
  7765. tempIndex = ((gun_index==2) ? 1: 0);
  7766. }
  7767. else
  7768. {
  7769. tempIndex = gun_index;
  7770. }
  7771. for (int index = 0; index < GB_QUANTITY; index++)
  7772. {
  7773. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7774. {
  7775. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7776. }
  7777. } // END OF GB_QUANTITY
  7778. }
  7779. else if(gunType[gun_index] == GUN_TYPE_DO)
  7780. {
  7781. tempIndex = gun_index;
  7782. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7783. {
  7784. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7785. {
  7786. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7787. }
  7788. }
  7789. }
  7790. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7795. }
  7796. // Message create ====================================================================================================
  7797. if(TRUE)
  7798. {
  7799. json_object *MeterValueReq = json_object_new_object();
  7800. json_object *MeterValues = json_object_new_array();
  7801. json_object *sampledValues = json_object_new_array();
  7802. json_object *sampledValuesBuffer = json_object_new_array();
  7803. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7804. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7805. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7806. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7807. {
  7808. json_object *MeterValue = json_object_new_object();
  7809. json_object *MeterValueBuffer = json_object_new_object();
  7810. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7811. {
  7812. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7813. {
  7814. json_object *sampledValue = json_object_new_object();
  7815. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7816. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7817. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7818. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7819. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7820. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7821. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7822. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7823. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7824. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7825. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7826. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7827. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7828. json_object_array_add(sampledValues, sampledValue);
  7829. // For StopTxn data
  7830. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, (char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand ) != NULL) && (strlen((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData) > 0)) ||
  7831. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, (char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) != NULL) && (strlen((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData) > 0)))
  7832. {
  7833. json_object *sampledValue = json_object_new_object();
  7834. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7835. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7836. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7837. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7838. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7839. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7840. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7841. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7842. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7843. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7844. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7845. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7846. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7847. json_object_array_add(sampledValuesBuffer, sampledValue);
  7848. }
  7849. }
  7850. }
  7851. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7852. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7853. json_object_array_add(MeterValues, MeterValue);
  7854. // For StopTxn data
  7855. if((dataType != ReadingContext_Trigger) &&
  7856. (json_object_array_length(sampledValuesBuffer) > 0))
  7857. {
  7858. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7859. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  7860. if(meterValueBufferDataQuantity(gun_index, dataType) < 200)
  7861. meterValueBufferInsert(gun_index, dataType, ShmOCPP16Data->MeterValues[gun_index].TransactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  7862. else
  7863. meterValueBufferReplace(200, gun_index, dataType, ShmOCPP16Data->MeterValues[gun_index].TransactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  7864. json_object_put(MeterValueBuffer);
  7865. }
  7866. else
  7867. {
  7868. json_object_put(sampledValuesBuffer);
  7869. json_object_put(MeterValueBuffer);
  7870. }
  7871. }
  7872. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7873. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7874. ,gun_index + 1
  7875. ,MESSAGE_TYPE_CALL
  7876. ,guid
  7877. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7878. json_object_put(MeterValueReq);
  7879. }
  7880. // Put request guid to hash map
  7881. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7882. 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*/)
  7883. {
  7884. result = PASS;
  7885. //DEBUG_INFO("MeterValues mapitem pass\n");
  7886. }
  7887. if((dataType != ReadingContext_Trigger) &&
  7888. (dataType != ReadingContext_Sample_Clock) &&
  7889. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7890. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7891. else
  7892. {
  7893. if(FirstHeartBeat)
  7894. LWS_Send(queuedata +2);
  7895. }
  7896. return result;
  7897. }
  7898. int sendLogStatusNotificationRequest(char *status)
  7899. {
  7900. mtrace();
  7901. int result = PASS;
  7902. char message[4096]={0};
  7903. char guid[37]={0};
  7904. char tempdata[128]={0};
  7905. json_object *LogStatusNotification = json_object_new_object();
  7906. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7907. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7908. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7909. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7910. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7911. random_uuid(guid);
  7912. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7913. json_object_put(LogStatusNotification);
  7914. LWS_Send(message);
  7915. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7916. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7917. {
  7918. result = PASS;
  7919. }
  7920. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7921. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7922. return result;
  7923. }
  7924. int sendSecurityEventNotificationRequest()
  7925. {
  7926. mtrace();
  7927. int result = PASS;
  7928. char message[4096]={0};
  7929. char guid[37]={0};
  7930. char tempdata[128]={0};
  7931. json_object *SecurityEventNotification = json_object_new_object();
  7932. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7933. //Stop Transaction Time
  7934. struct timeval tmnow;
  7935. struct tm *tm;
  7936. gettimeofday(&tmnow, NULL);
  7937. time_t t;
  7938. t = time(NULL);
  7939. /*UTC time and date*/
  7940. tm = gmtime(&t);
  7941. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7942. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7943. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7944. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7945. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7946. random_uuid(guid);
  7947. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7948. json_object_put(SecurityEventNotification);
  7949. LWS_Send(message);
  7950. sprintf(tempdata, "SecurityEventNotification,0");
  7951. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7952. {
  7953. result = PASS;
  7954. }
  7955. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7956. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7957. return result;
  7958. }
  7959. int sendSignCertificateRequest()
  7960. {
  7961. mtrace();
  7962. int result = PASS;
  7963. char message[4096]={0};
  7964. char guid[37]={0};
  7965. char tempdata[128]={0};
  7966. json_object *SignCertificate = json_object_new_object();
  7967. DEBUG_INFO("sendSignCertificateRequest...\n");
  7968. // Read csr file content
  7969. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7970. FILE *fp=fopen(CSR_CP,"r");
  7971. char *line = NULL;
  7972. size_t len = 0;
  7973. while(getline(&line, &len, fp) != -1)
  7974. {
  7975. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7976. {
  7977. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7978. }
  7979. }
  7980. fclose(fp);
  7981. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7982. random_uuid(guid);
  7983. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7984. json_object_put(SignCertificate);
  7985. LWS_Send(message);
  7986. sprintf(tempdata, "SignCertificate,0");
  7987. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7988. {
  7989. result = PASS;
  7990. }
  7991. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7992. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7993. return result;
  7994. }
  7995. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7996. {
  7997. mtrace();
  7998. int result = PASS;
  7999. char message[4096]={0};
  8000. char guid[37]={0};
  8001. char tempdata[128]={0};
  8002. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  8003. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  8004. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  8005. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  8006. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  8007. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  8008. random_uuid(guid);
  8009. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8010. json_object_put(SignedFirmwareStatusNotification);
  8011. LWS_Send(message);
  8012. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  8013. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8014. {
  8015. result = PASS;
  8016. }
  8017. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  8018. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  8019. return result;
  8020. }
  8021. //==========================================
  8022. // send confirm routine
  8023. //==========================================
  8024. int sendCancelReservationConfirmation(char *uuid,char *payload)
  8025. {
  8026. mtrace();
  8027. int result = FAIL;
  8028. char message[100]={0};
  8029. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8030. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8031. LWS_Send(message);
  8032. result = TRUE;
  8033. return result;
  8034. }
  8035. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  8036. {
  8037. mtrace();
  8038. int result = FAIL;
  8039. char message[100]={0};
  8040. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8041. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8042. LWS_Send(message);
  8043. result = TRUE;
  8044. return result;
  8045. }
  8046. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8047. {
  8048. mtrace();
  8049. int result = FAIL;
  8050. char message[100]={0};
  8051. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8052. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8053. LWS_Send(message);
  8054. result = TRUE;
  8055. return result;
  8056. }
  8057. int sendClearCacheConfirmation(char *uuid,char *payload)
  8058. {
  8059. mtrace();
  8060. int result = FAIL;
  8061. char message[500]={0};
  8062. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8063. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8064. LWS_Send(message);
  8065. return result;
  8066. }
  8067. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8068. {
  8069. mtrace();
  8070. int result = FAIL;
  8071. char message[500]={0};
  8072. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8073. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8074. LWS_Send(message);
  8075. return result;
  8076. }
  8077. int sendDataTransferConfirmation(char *uuid,char *payload)
  8078. {
  8079. mtrace();
  8080. char statusStr[20]={0};
  8081. char dataStr[10]={0};
  8082. char sstr[20]={0};
  8083. int c = 0;
  8084. char *loc;
  8085. int result = FAIL;
  8086. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8087. /**********************status**************************/
  8088. loc = strstr(payload, "status");
  8089. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8090. c = 0;
  8091. while (loc[3+strlen("status")+c] != '\"')
  8092. {
  8093. sstr[c] = loc[3+strlen("status")+c];
  8094. c++;
  8095. }
  8096. sstr[c] = '\0';
  8097. strcpy(statusStr, sstr);
  8098. /**********************data**************************/
  8099. loc = strstr(payload, "data");
  8100. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8101. c = 0;
  8102. while (loc[3+strlen("data")+c] != '\"')
  8103. {
  8104. sstr[c] = loc[3+strlen("data")+c];
  8105. c++;
  8106. }
  8107. sstr[c] = '\0';
  8108. strcpy(dataStr, sstr);
  8109. return result;
  8110. }
  8111. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8112. {
  8113. mtrace();
  8114. int result = FAIL;
  8115. char message[1000]={0};
  8116. int CompositeScheduleIndex = 0;
  8117. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8118. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8119. if(nPeriod == 0)
  8120. {
  8121. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8122. {
  8123. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8124. ,MESSAGE_TYPE_CALLRESULT
  8125. ,uuid
  8126. ,payload
  8127. ,connectorIdInt);
  8128. }
  8129. else
  8130. {
  8131. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8132. ,MESSAGE_TYPE_CALLRESULT
  8133. ,uuid
  8134. ,payload
  8135. ,connectorIdInt
  8136. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8137. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8138. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8139. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8140. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8141. }
  8142. }
  8143. else
  8144. {
  8145. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8146. ,MESSAGE_TYPE_CALLRESULT
  8147. ,uuid
  8148. ,payload
  8149. ,connectorIdInt
  8150. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8151. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8152. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8153. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8154. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8155. {
  8156. if (idx_sample == 0)
  8157. {
  8158. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8159. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8160. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8161. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8162. }
  8163. else
  8164. {
  8165. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8166. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8167. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8168. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8169. }
  8170. }
  8171. sprintf(message + strlen(message), "]}}]");
  8172. }
  8173. LWS_Send(message);
  8174. result = TRUE;
  8175. return result;
  8176. }
  8177. int sendGetConfigurationConfirmation(char *uuid)
  8178. {
  8179. mtrace();
  8180. int result = FAIL;
  8181. int MaxKeySupported = 0;
  8182. int sentConfigurationNumber= 0;
  8183. int sentunConfigurationNumber= 0;
  8184. char message[1024*10]={0};
  8185. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8186. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8187. //configuration key
  8188. json_object *GetConfiguration = json_object_new_object();
  8189. json_object *configurationKey = json_object_new_array();
  8190. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8191. {
  8192. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8193. {
  8194. json_object *keyValue = json_object_new_object();
  8195. json_object_object_add(keyValue, "key", json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key));
  8196. json_object_object_add(keyValue, "readonly", atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1?json_object_new_boolean(1):json_object_new_boolean(0));
  8197. json_object_object_add(keyValue, "value", json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value));
  8198. json_object_array_add(configurationKey, keyValue);
  8199. sentConfigurationNumber = sentConfigurationNumber + 1;
  8200. }
  8201. }
  8202. json_object *unknownKey = json_object_new_array();
  8203. if(UnknownKeynum != 0)
  8204. {
  8205. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8206. {
  8207. DEBUG_INFO("unknown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8208. json_object_array_add(unknownKey, json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item));
  8209. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8210. }
  8211. }
  8212. if((sentConfigurationNumber>0) && (sentunConfigurationNumber>0))
  8213. {
  8214. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  8215. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  8216. }
  8217. else if(sentConfigurationNumber>0)
  8218. {
  8219. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  8220. json_object_put(unknownKey);
  8221. }
  8222. else
  8223. {
  8224. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  8225. json_object_put(configurationKey);
  8226. }
  8227. sprintf(message,"[%d,\"%s\",%s]"
  8228. ,MESSAGE_TYPE_CALLRESULT
  8229. ,uuid
  8230. ,json_object_to_json_string_ext(GetConfiguration, JSON_C_TO_STRING_PLAIN));
  8231. json_object_put(GetConfiguration);
  8232. LWS_Send(message);
  8233. return result;
  8234. }
  8235. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8236. {
  8237. mtrace();
  8238. int result = FAIL;
  8239. char message[400]={0};
  8240. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8241. if(strcmp(payload,"")==0)
  8242. {
  8243. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8244. }
  8245. else
  8246. {
  8247. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8248. }
  8249. LWS_Send(message);
  8250. result = TRUE;
  8251. return result;
  8252. }
  8253. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8254. {
  8255. mtrace();
  8256. int result = FAIL;
  8257. char message[80]={0};
  8258. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8259. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8260. LWS_Send(message);
  8261. result = TRUE;
  8262. return result;
  8263. }
  8264. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8265. {
  8266. mtrace();
  8267. int result = FAIL;
  8268. char message[80]={0};
  8269. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8270. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8271. LWS_Send(message);
  8272. result = TRUE;
  8273. return result;
  8274. }
  8275. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8276. {
  8277. mtrace();
  8278. int result = FAIL;
  8279. char message[80]={0};
  8280. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8281. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8282. LWS_Send(message);
  8283. result = TRUE;
  8284. return result;
  8285. }
  8286. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8287. {
  8288. mtrace();
  8289. int result = FAIL;
  8290. char message[80]={0};
  8291. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8292. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8293. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8294. LWS_Send(message);
  8295. result = TRUE;
  8296. return result;
  8297. }
  8298. int sendResetConfirmation(char *uuid,char *payload)
  8299. {
  8300. mtrace();
  8301. int result = FAIL;
  8302. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8303. char message[80]={0};
  8304. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8305. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8306. LWS_Send(message);
  8307. result = TRUE;
  8308. return result;
  8309. }
  8310. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8311. {
  8312. mtrace();
  8313. int result = FAIL;
  8314. char message[500]={0};
  8315. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8316. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8317. LWS_Send(message);
  8318. result = TRUE;
  8319. return result;
  8320. }
  8321. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8322. {
  8323. mtrace();
  8324. int result = FAIL;
  8325. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8326. char message[80]={0};
  8327. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8328. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8329. LWS_Send(message);
  8330. result = TRUE;
  8331. return result;
  8332. }
  8333. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8334. {
  8335. mtrace();
  8336. int result = FAIL;
  8337. char message[80]={0};
  8338. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8339. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8340. LWS_Send(message);
  8341. result = TRUE;
  8342. return result;
  8343. }
  8344. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8345. {
  8346. mtrace();
  8347. int result = FAIL;
  8348. char message[80]={0};
  8349. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8350. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8351. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8352. LWS_Send(message);
  8353. result = TRUE;
  8354. return result;
  8355. }
  8356. int sendUpdateFirmwareConfirmation(char *uuid)
  8357. {
  8358. mtrace();
  8359. int result = FAIL;
  8360. char message[60]={0};
  8361. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8362. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8363. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8364. LWS_Send(message);
  8365. result = TRUE;
  8366. return result;
  8367. }
  8368. int sendCertificateSignedConfirmation(char *uuid)
  8369. {
  8370. mtrace();
  8371. int result = PASS;
  8372. char message[4096]={0};
  8373. json_object *CertificateSigned = json_object_new_object();
  8374. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8375. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8376. sprintf(message,"[%d,\"%s\",%s]"
  8377. ,MESSAGE_TYPE_CALLRESULT
  8378. ,uuid
  8379. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8380. json_object_put(CertificateSigned);
  8381. LWS_Send(message);
  8382. return result;
  8383. }
  8384. int sendDeleteCertificateConfirmation(char *uuid)
  8385. {
  8386. mtrace();
  8387. int result = PASS;
  8388. char message[4096]={0};
  8389. json_object *DeleteCertificate = json_object_new_object();
  8390. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8391. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8392. sprintf(message,"[%d,\"%s\",%s]"
  8393. ,MESSAGE_TYPE_CALLRESULT
  8394. ,uuid
  8395. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8396. json_object_put(DeleteCertificate);
  8397. LWS_Send(message);
  8398. return result;
  8399. }
  8400. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8401. {
  8402. mtrace();
  8403. int result = PASS;
  8404. char message[4096]={0};
  8405. json_object *ExtendedTriggerMessage = json_object_new_object();
  8406. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8407. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8408. sprintf(message,"[%d,\"%s\",%s]"
  8409. ,MESSAGE_TYPE_CALLRESULT
  8410. ,uuid
  8411. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8412. json_object_put(ExtendedTriggerMessage);
  8413. LWS_Send(message);
  8414. return result;
  8415. }
  8416. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8417. {
  8418. mtrace();
  8419. int result = PASS;
  8420. char message[4096]={0};
  8421. json_object *GetInstalledCertificateIds = json_object_new_object();
  8422. json_object *certificateHashDataDatas = json_object_new_array();
  8423. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8424. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8425. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8426. {
  8427. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8428. {
  8429. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8430. {
  8431. json_object *certificateHashData = json_object_new_object();
  8432. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8433. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8434. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8435. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8436. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8437. }
  8438. }
  8439. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8440. }
  8441. else
  8442. {
  8443. json_object_put(certificateHashDataDatas);
  8444. }
  8445. sprintf(message,"[%d,\"%s\",%s]"
  8446. ,MESSAGE_TYPE_CALLRESULT
  8447. ,uuid
  8448. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8449. json_object_put(GetInstalledCertificateIds);
  8450. LWS_Send(message);
  8451. return result;
  8452. }
  8453. int sendGetLogConfirmation(char *uuid)
  8454. {
  8455. mtrace();
  8456. int result = PASS;
  8457. char message[4096]={0};
  8458. json_object *GetLog = json_object_new_object();
  8459. DEBUG_INFO("sendGetLogConfirmation...\n");
  8460. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8461. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8462. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8463. sprintf(message,"[%d,\"%s\",%s]"
  8464. ,MESSAGE_TYPE_CALLRESULT
  8465. ,uuid
  8466. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8467. json_object_put(GetLog);
  8468. LWS_Send(message);
  8469. return result;
  8470. }
  8471. int sendInstallCertificateConfirmation(char *uuid)
  8472. {
  8473. mtrace();
  8474. int result = PASS;
  8475. char message[4096]={0};
  8476. json_object *InstallCertificate = json_object_new_object();
  8477. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8478. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8479. sprintf(message,"[%d,\"%s\",%s]"
  8480. ,MESSAGE_TYPE_CALLRESULT
  8481. ,uuid
  8482. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8483. json_object_put(InstallCertificate);
  8484. LWS_Send(message);
  8485. return result;
  8486. }
  8487. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8488. {
  8489. mtrace();
  8490. int result = PASS;
  8491. char message[4096]={0};
  8492. json_object *SignedUpdateFirmware = json_object_new_object();
  8493. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8494. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8495. sprintf(message,"[%d,\"%s\",%s]"
  8496. ,MESSAGE_TYPE_CALLRESULT
  8497. ,uuid
  8498. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8499. json_object_put(SignedUpdateFirmware);
  8500. LWS_Send(message);
  8501. return result;
  8502. }
  8503. int sendUnknownConfirmation(char *uuid)
  8504. {
  8505. mtrace();
  8506. int result = PASS;
  8507. char message[256]={0};
  8508. DEBUG_INFO("sendUnknownConfirmation...\n");
  8509. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8510. LWS_Send(message);
  8511. return result;
  8512. }
  8513. //==========================================
  8514. // Handle server request routine Start
  8515. //==========================================
  8516. int handleCancelReservationRequest(char *uuid, char *payload)
  8517. {
  8518. mtrace();
  8519. int result = FAIL;
  8520. int gunNO = 0;
  8521. int reservationIdInt = -1;
  8522. char comfirmstr[20];
  8523. DEBUG_INFO("handleCancelReservationRequest...\n");
  8524. json_object *CancelReservation;
  8525. CancelReservation = json_tokener_parse(payload);
  8526. if(!is_error(CancelReservation))
  8527. {
  8528. // Required data
  8529. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8530. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8531. }
  8532. json_object_put(CancelReservation);
  8533. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8534. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8535. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8536. if(reservationIdInt != -1)
  8537. {
  8538. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8539. //check Transaction active
  8540. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8541. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8542. {
  8543. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8544. {
  8545. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8546. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8547. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8548. {
  8549. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8550. }
  8551. else
  8552. {
  8553. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8554. }
  8555. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8556. goto end;
  8557. }
  8558. }
  8559. for (int index = 0; index < CCS_QUANTITY; index++)
  8560. {
  8561. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8562. {
  8563. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8564. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8565. if(gunType[2] == GUN_TYPE_CCS)
  8566. {
  8567. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8568. }
  8569. else
  8570. {
  8571. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8572. }
  8573. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8574. goto end;
  8575. }
  8576. }
  8577. for (int index = 0; index < GB_QUANTITY; index++)
  8578. {
  8579. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8580. {
  8581. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8582. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8583. if(gunType[2] == GUN_TYPE_GBT)
  8584. {
  8585. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8586. }
  8587. else
  8588. {
  8589. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8590. }
  8591. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8592. goto end;
  8593. }
  8594. }
  8595. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8596. {
  8597. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8598. {
  8599. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8600. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8601. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8602. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8603. goto end;
  8604. }
  8605. }
  8606. for (int index = 0; index < AC_QUANTITY; index++)
  8607. {
  8608. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8609. {
  8610. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8611. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8612. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8613. {
  8614. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8615. }
  8616. else
  8617. {
  8618. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8619. }
  8620. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8621. goto end;
  8622. }
  8623. }
  8624. }
  8625. //The reservationId does NOT match the reservationId
  8626. sendCancelReservationConfirmation(uuid, comfirmstr);
  8627. end:
  8628. // Fill in ocpp packet uuid
  8629. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8630. return result;
  8631. }
  8632. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8633. {
  8634. mtrace();
  8635. int result = FAIL;
  8636. int gunIndex = -1;
  8637. char typeStr[16]={0};
  8638. char comfirmstr[20];
  8639. int specificId = FALSE;
  8640. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8641. json_object *ChangeAvailability;
  8642. ChangeAvailability = json_tokener_parse(payload);
  8643. if(!is_error(ChangeAvailability))
  8644. {
  8645. // Required data
  8646. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8647. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8648. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8649. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8650. }
  8651. json_object_put(ChangeAvailability);
  8652. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8653. {
  8654. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8655. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8656. }
  8657. else if(gunIndex == 0)
  8658. {
  8659. for(int i=0; i < gunTotalNumber; i++)
  8660. {
  8661. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8662. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8663. }
  8664. }
  8665. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8666. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8667. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8668. {
  8669. specificId = TRUE;
  8670. }
  8671. if(specificId == FALSE)
  8672. goto end;
  8673. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8674. {
  8675. //----------------------gunIndex is 0 ------------------------------------------------//
  8676. if(gunIndex == 0)
  8677. {
  8678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8679. {
  8680. for(int i=0; i < gunTotalNumber; i++)
  8681. {
  8682. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8683. {
  8684. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8685. {
  8686. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8687. {
  8688. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8689. goto end;
  8690. }
  8691. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8692. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8693. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8694. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8695. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8696. {
  8697. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8698. goto end;
  8699. }
  8700. }
  8701. }//END FOR CHAdeMO_QUANTITY
  8702. for (int index = 0; index < CCS_QUANTITY; index++)
  8703. {
  8704. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8705. {
  8706. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8707. {
  8708. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8709. goto end;
  8710. }
  8711. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8712. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8713. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8714. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8715. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8716. {
  8717. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8718. goto end;
  8719. }
  8720. }
  8721. }//END FOR CCS_QUANTITY
  8722. for (int index = 0; index < GB_QUANTITY; index++)
  8723. {
  8724. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8725. {
  8726. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8727. {
  8728. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8729. goto end;
  8730. }
  8731. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8732. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8733. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8734. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8735. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8736. {
  8737. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8738. goto end;
  8739. }
  8740. }
  8741. }// END FOR GB_QUANTITY
  8742. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8743. {
  8744. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8745. {
  8746. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8747. {
  8748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8749. goto end;
  8750. }
  8751. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8752. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8753. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8754. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8755. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8756. {
  8757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8758. goto end;
  8759. }
  8760. }
  8761. }// END FOR GENERAL_GUN_QUANTITY
  8762. for (int index = 0; index < AC_QUANTITY; index++)
  8763. {
  8764. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8765. {
  8766. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8767. {
  8768. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8769. goto end;
  8770. }
  8771. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8772. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8773. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8774. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8775. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8776. {
  8777. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8778. goto end;
  8779. }
  8780. }
  8781. }//END FOR AC_QUANTITY
  8782. }// END FOR gunTotalNumber
  8783. }
  8784. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8785. {
  8786. for(int i=0; i < gunTotalNumber; i++)
  8787. {
  8788. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8789. {
  8790. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8791. goto end;
  8792. }
  8793. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8794. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8795. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8796. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8797. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8798. {
  8799. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8800. goto end;
  8801. }
  8802. }
  8803. }
  8804. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8805. goto end;
  8806. }
  8807. //----------------------gunIndex is not 0 ------------------------------------------------//
  8808. //check Transaction active
  8809. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8810. {
  8811. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8812. {
  8813. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8814. {
  8815. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8816. goto end;
  8817. }
  8818. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8819. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8820. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8821. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8822. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8823. {
  8824. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8825. goto end;
  8826. }
  8827. else
  8828. {
  8829. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8830. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8831. goto end;
  8832. }
  8833. }
  8834. }//END FOR CHAdeMO_QUANTITY
  8835. for (int index = 0; index < CCS_QUANTITY; index++)
  8836. {
  8837. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8838. {
  8839. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8840. {
  8841. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8842. goto end;
  8843. }
  8844. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8845. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8846. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8847. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8848. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8849. {
  8850. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8851. goto end;
  8852. }
  8853. else
  8854. {
  8855. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8856. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8857. goto end;
  8858. }
  8859. }
  8860. }//END FOR CCS_QUANTITY
  8861. for (int index = 0; index < GB_QUANTITY; index++)
  8862. {
  8863. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8864. {
  8865. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8866. {
  8867. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8868. goto end;
  8869. }
  8870. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8871. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8872. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8873. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8874. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8875. {
  8876. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8877. goto end;
  8878. }
  8879. else
  8880. {
  8881. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8882. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8883. goto end;
  8884. }
  8885. }
  8886. }// END FOR GB_QUANTITY
  8887. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8888. {
  8889. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8890. {
  8891. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8892. {
  8893. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8894. goto end;
  8895. }
  8896. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8897. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8898. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8899. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8900. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8901. {
  8902. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8903. goto end;
  8904. }
  8905. else
  8906. {
  8907. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8908. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8909. goto end;
  8910. }
  8911. }
  8912. }// END FOR GENERAL_GUN_QUANTITY
  8913. for (int index = 0; index < AC_QUANTITY; index++)
  8914. {
  8915. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8916. {
  8917. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8918. {
  8919. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8920. goto end;
  8921. }
  8922. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8923. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8924. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8925. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8926. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8927. {
  8928. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8929. goto end;
  8930. }
  8931. else
  8932. {
  8933. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8934. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8935. goto end;
  8936. }
  8937. }
  8938. }//END FOR AC_QUANTITY
  8939. }//END FOR AvailabilityTypeStr[Inoperative]
  8940. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8941. {
  8942. //----------------------gunIndex is 0 ------------------------------------------------//
  8943. if(gunIndex == 0)
  8944. {
  8945. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8946. {
  8947. for(int i=0; i < gunTotalNumber; i++)
  8948. {
  8949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8950. {
  8951. 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
  8952. {
  8953. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8954. goto end;
  8955. }
  8956. }//END FOR CHAdeMO_QUANTITY
  8957. for (int index = 0; index < CCS_QUANTITY; index++)
  8958. {
  8959. 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
  8960. {
  8961. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8962. goto end;
  8963. }
  8964. }//END FOR CCS_QUANTITY
  8965. for (int index = 0; index < GB_QUANTITY; index++)
  8966. {
  8967. 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
  8968. {
  8969. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8970. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8971. goto end;
  8972. }
  8973. }// END FOR GB_QUANTITY
  8974. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8975. {
  8976. 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
  8977. {
  8978. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8979. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8980. goto end;
  8981. }
  8982. }// END FOR GENERAL_GUN_QUANTITY
  8983. for (int index = 0; index < AC_QUANTITY; index++)
  8984. {
  8985. 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
  8986. {
  8987. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8988. goto end;
  8989. }
  8990. }//END FOR CHAdeMO_QUANTITY
  8991. }// END FOR gunTotalNumber
  8992. }
  8993. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8994. {
  8995. for(int i=0; i < gunTotalNumber; i++)
  8996. {
  8997. for (int index = 0; index < AC_QUANTITY; index++)
  8998. {
  8999. 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
  9000. {
  9001. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9002. goto end;
  9003. }
  9004. }//END FOR CHAdeMO_QUANTITY
  9005. } // END FOR gunTotalNumber
  9006. }
  9007. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9008. goto end;
  9009. }
  9010. //----------------------gunIndex is not 0 ------------------------------------------------//
  9011. //check Transaction active
  9012. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9013. {
  9014. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9015. {
  9016. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9017. goto end;
  9018. }
  9019. }//END FOR CHAdeMO_QUANTITY
  9020. for (int index = 0; index < CCS_QUANTITY; index++)
  9021. {
  9022. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9023. {
  9024. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9025. goto end;
  9026. }
  9027. }//END FOR CCS_QUANTITY
  9028. for (int index = 0; index < GB_QUANTITY; index++)
  9029. {
  9030. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9031. {
  9032. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9033. goto end;
  9034. }
  9035. }// END FOR GB_QUANTITY
  9036. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9037. {
  9038. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9039. {
  9040. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9041. goto end;
  9042. }
  9043. }// END FOR GENERAL_GUN_QUANTITY
  9044. for (int index = 0; index < AC_QUANTITY; index++)
  9045. {
  9046. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9047. {
  9048. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9049. goto end;
  9050. }
  9051. }//END FOR AC_QUANTITY
  9052. }//END FOR AvailabilityTypeStr[Operative]
  9053. end:
  9054. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9055. {
  9056. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9057. }
  9058. else
  9059. {
  9060. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9061. }
  9062. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9063. {
  9064. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9065. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9066. }
  9067. else if(gunIndex == 0)
  9068. {
  9069. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9070. {
  9071. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9072. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9073. }
  9074. }
  9075. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9076. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9077. return result;
  9078. }
  9079. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9080. {
  9081. mtrace();
  9082. int valueInvalid = NO;
  9083. int result = FAIL;
  9084. char keystr[40]={0};
  9085. char valuestr[501]={0}; //value should be limited in 500 bytes
  9086. char comfirmstr[20]={0};
  9087. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9088. json_object *ChangeConfiguration;
  9089. ChangeConfiguration = json_tokener_parse(payload);
  9090. if(!is_error(ChangeConfiguration))
  9091. {
  9092. // Required data
  9093. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9094. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9095. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9096. {
  9097. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9098. }
  9099. else
  9100. {
  9101. valueInvalid = YES;
  9102. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9103. }
  9104. }
  9105. json_object_put(ChangeConfiguration);
  9106. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9107. {
  9108. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9109. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9110. }
  9111. else
  9112. {
  9113. int status = setKeyValue(keystr, valuestr);
  9114. switch(status)
  9115. {
  9116. case ConfigurationStatus_Accepted:
  9117. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9118. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9119. StoreConfigurationTable();
  9120. break;
  9121. case RebootRequired:
  9122. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9123. StoreConfigurationTable();
  9124. break;
  9125. case NotSupported:
  9126. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9127. break;
  9128. case ConfigurationStatus_Rejected:
  9129. default:
  9130. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9131. break;
  9132. }
  9133. }
  9134. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9135. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9136. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9137. {
  9138. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9139. SetOcppConnStatus(FALSE);
  9140. }
  9141. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9142. {
  9143. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9144. }
  9145. return result;
  9146. }
  9147. int handleClearCacheRequest(char *uuid, char *payload)
  9148. {
  9149. mtrace();
  9150. int result = FAIL;
  9151. char comfirmstr[20];
  9152. char rmFileCmd[100]={0};
  9153. struct stat stats;
  9154. DEBUG_INFO("handleClearCacheRequest...\n");
  9155. stat("/Storage/OCPP", &stats);
  9156. // Check for directory existence
  9157. if (S_ISDIR(stats.st_mode) == 1)
  9158. {}
  9159. else
  9160. {
  9161. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9162. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9163. system(rmFileCmd);
  9164. }
  9165. if(OCPP_cleanLocalCache())
  9166. {
  9167. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9168. }
  9169. else
  9170. {
  9171. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9172. }
  9173. sendClearCacheConfirmation(uuid, comfirmstr);
  9174. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9175. return result;
  9176. }
  9177. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9178. {
  9179. mtrace();
  9180. int result = FAIL;
  9181. int resultRename;
  9182. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9183. char chargingProfilePurposeStr[26]={0};
  9184. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9185. char tempchargingProfilePurposeStr[26]={0};
  9186. char str[100]={0};
  9187. char fname[200]={0};
  9188. char comfirmstr[20]={0};
  9189. char word[1600]={0};
  9190. int clearflag = FALSE;
  9191. int chargingProfileIdIsNULL = FALSE;
  9192. int connectorIsNULL = FALSE;
  9193. int chargingProfilePurposeIsNULL = FALSE;
  9194. int stackLevelIsNULL = FALSE;
  9195. //int GotoEnd = FALSE;
  9196. FILE *fptr1, *fptr2;
  9197. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9198. int n_chargingProfile=0;
  9199. int isEmptyFile = FALSE;
  9200. char sLineWord[1600]={0};
  9201. char chargingProfiles[10][100]={0};
  9202. int ChargeProfileCount = 0;
  9203. int ch;
  9204. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9205. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9206. json_object *ClearChargingProfile;
  9207. ClearChargingProfile = json_tokener_parse(payload);
  9208. if(!is_error(ClearChargingProfile))
  9209. {
  9210. // Optional data
  9211. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9212. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9213. else
  9214. chargingProfileIdIsNULL = TRUE;
  9215. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9216. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9217. else
  9218. connectorIsNULL = TRUE;
  9219. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9220. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9221. else
  9222. chargingProfilePurposeIsNULL = TRUE;
  9223. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9224. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9225. else
  9226. stackLevelIsNULL = TRUE;
  9227. }
  9228. json_object_put(ClearChargingProfile);
  9229. if(connectorIdInt > 0)
  9230. {
  9231. if(chargingProfilePurposeIsNULL == TRUE)
  9232. {
  9233. int m = 0;
  9234. memset(fname, 0, ARRAY_SIZE(fname));
  9235. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9236. if((access(fname,F_OK))!=-1)
  9237. {
  9238. strcpy(chargingProfiles[m], fname);
  9239. m = m + 1;
  9240. }
  9241. memset(fname, 0, ARRAY_SIZE(fname));
  9242. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9243. if((access(fname,F_OK))!=-1)
  9244. {
  9245. strcpy(chargingProfiles[m], fname);
  9246. m = m + 1;
  9247. }
  9248. ChargeProfileCount = m;
  9249. }
  9250. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9251. {
  9252. //strcpy(fname, TxDefaultProfile_1_JSON);
  9253. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9254. if((access(fname,F_OK))!=-1)
  9255. {
  9256. strcpy(chargingProfiles[0], fname);
  9257. ChargeProfileCount = 1;
  9258. }
  9259. }
  9260. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9261. {
  9262. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9263. if((access(fname,F_OK))!=-1)
  9264. {
  9265. strcpy(chargingProfiles[0], fname);
  9266. ChargeProfileCount = 1;
  9267. }
  9268. //strcpy(fname, TxProfile_1_JSON);
  9269. }
  9270. }
  9271. else // Check all Charging Profiles
  9272. {
  9273. int i = 0;
  9274. char fnametemp[200]={0};
  9275. ChargeProfileCount = 0;
  9276. //Check ChargePointMaxProfile.json exit
  9277. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9278. {
  9279. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9280. i = i + 1;
  9281. }
  9282. //Check TxDefaultProfile_0.json exit
  9283. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9284. {
  9285. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9286. i = i + 1;
  9287. }
  9288. //Check TxDefaultProfile_%d.json
  9289. for(int j=1; j <= gunTotalNumber; j++)
  9290. {
  9291. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9292. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9293. if((access(fnametemp,F_OK))!=-1)
  9294. {
  9295. strcpy(chargingProfiles[i], fnametemp);
  9296. i = i + 1;
  9297. }
  9298. }
  9299. //Check TxProfile_%d.json
  9300. for(int j=1; j <= gunTotalNumber; j++)
  9301. {
  9302. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9303. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9304. if((access(fnametemp,F_OK))!=-1)
  9305. {
  9306. strcpy(chargingProfiles[i], fnametemp);
  9307. i = i + 1;
  9308. }
  9309. }
  9310. ChargeProfileCount = i;
  9311. }// End connectorIsNULL is TRUE
  9312. if(ChargeProfileCount == 0)
  9313. {
  9314. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9315. goto end;
  9316. }
  9317. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9318. {
  9319. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9320. goto end;
  9321. }
  9322. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9323. {
  9324. memset(str, 0, ARRAY_SIZE(str));
  9325. // clear temp file
  9326. sprintf(str,"rm -f %s",temp);
  9327. system(str);
  9328. for(int k=0; k < ChargeProfileCount; k++)
  9329. {
  9330. memset(str, 0, ARRAY_SIZE(str));
  9331. //clear file in C
  9332. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9333. system(str);
  9334. }
  9335. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9336. goto end;
  9337. }
  9338. else if(connectorIsNULL == TRUE)
  9339. {
  9340. for(int k=0; k < ChargeProfileCount; k++)
  9341. {
  9342. fptr1 = fopen(chargingProfiles[k], "r");
  9343. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9344. //Check Charging Profile Count
  9345. while(fscanf(fptr1, "%s", word) != EOF)
  9346. {
  9347. //DEBUG_INFO("word=%s\n",word);
  9348. if(strstr(word, "chargingProfileId")!= NULL)
  9349. {
  9350. //DEBUG_INFO("test chargingProfileId \n");
  9351. n_chargingProfile = n_chargingProfile + 1;
  9352. //DEBUG_INFO("chargingProfileId Found\n");
  9353. }
  9354. }
  9355. rewind(fptr1);
  9356. //search Charging Profile Element
  9357. //int i= 0;
  9358. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9359. {
  9360. json_object *tmpProfilee;
  9361. tmpProfilee = json_tokener_parse(sLineWord);
  9362. if(!is_error(tmpProfilee))
  9363. {
  9364. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9365. {
  9366. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9367. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9368. }
  9369. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9370. {
  9371. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9372. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9373. }
  9374. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9375. {
  9376. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9377. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9378. }
  9379. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9380. {
  9381. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9382. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9383. }
  9384. }
  9385. json_object_put(tmpProfilee);
  9386. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9387. {
  9388. //------- not write to fptr2-------//
  9389. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9390. //clearflag = TRUE;
  9391. }
  9392. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9393. {
  9394. //------- not write to fptr2-------//
  9395. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9396. }
  9397. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9398. {
  9399. //------- not write to fptr2-------//
  9400. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9401. }
  9402. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9403. {
  9404. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9405. }
  9406. else
  9407. {
  9408. fprintf(fptr2, sLineWord);//writing data into file
  9409. }
  9410. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9411. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9412. if(clearflag == TRUE)
  9413. {
  9414. fclose(fptr1);
  9415. fclose(fptr2);
  9416. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9417. system(str);
  9418. // clear temp file
  9419. sprintf(str,"rm -f %s",temp);
  9420. system(str);
  9421. }
  9422. else
  9423. {
  9424. fclose(fptr1);
  9425. fclose(fptr2);
  9426. memset(str, 0, ARRAY_SIZE(str));
  9427. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9428. system(str);
  9429. resultRename = rename(temp, chargingProfiles[k]);
  9430. if(resultRename == 0)
  9431. {
  9432. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9433. }
  9434. else
  9435. {
  9436. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9437. }
  9438. if(comfirmstr[0]== 0)
  9439. {
  9440. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9441. }
  9442. //Check chargingProfile is empty file
  9443. /*------ Read the file ----------------*/
  9444. fptr1=fopen(chargingProfiles[k],"r");
  9445. ch=fgetc(fptr1);
  9446. rewind(fptr1);
  9447. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9448. if(ch!=EOF)
  9449. {
  9450. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9451. {
  9452. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9453. if(sLineWord[0]=='\0')
  9454. {
  9455. isEmptyFile = TRUE;
  9456. break;
  9457. }
  9458. else
  9459. {
  9460. isEmptyFile = FALSE;
  9461. break;
  9462. }
  9463. }
  9464. }
  9465. else
  9466. isEmptyFile = TRUE;
  9467. fclose(fptr1);
  9468. if(isEmptyFile == TRUE)
  9469. {
  9470. memset(str, 0, ARRAY_SIZE(str));
  9471. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9472. system(str);
  9473. }
  9474. }
  9475. }// End of while(int k=0; k < ChargePointCount; k++)
  9476. }
  9477. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9478. {
  9479. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9480. for(int k=0; k < ChargeProfileCount; k++)
  9481. {
  9482. fptr1 = fopen(chargingProfiles[k], "r");
  9483. fptr2 = fopen(temp, "w+");
  9484. //Check Charging Profile Count
  9485. while(fscanf(fptr1, "%s", word) != EOF)
  9486. {
  9487. //DEBUG_INFO("word=%s\n",word);
  9488. if(strstr(word, "chargingProfileId")!= NULL)
  9489. {
  9490. n_chargingProfile = n_chargingProfile + 1;
  9491. }
  9492. }
  9493. rewind(fptr1);
  9494. //search Charging Profile Element
  9495. //int i= 0;
  9496. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9497. {
  9498. json_object *tmpProfilee;
  9499. tmpProfilee = json_tokener_parse(sLineWord);
  9500. if(!is_error(tmpProfilee))
  9501. {
  9502. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9503. {
  9504. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9505. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9506. }
  9507. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9508. {
  9509. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9510. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9511. }
  9512. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9513. {
  9514. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9515. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9516. }
  9517. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9518. {
  9519. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9520. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9521. }
  9522. }
  9523. json_object_put(tmpProfilee);
  9524. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9525. {
  9526. //------- not write to fptr2-------//
  9527. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9528. //clearflag = TRUE;
  9529. }
  9530. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9531. {
  9532. //------- not write to fptr2-------//
  9533. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9534. }
  9535. else if(stackLevelIsNULL == TRUE)
  9536. {
  9537. //Clear Whole File
  9538. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9539. clearflag = TRUE;
  9540. break;
  9541. }
  9542. else
  9543. {
  9544. fprintf(fptr2, sLineWord);//writing data into file
  9545. }
  9546. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9547. }
  9548. if(clearflag == TRUE)
  9549. {
  9550. fclose(fptr1);
  9551. fclose(fptr2);
  9552. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9553. system(str);
  9554. // clear temp file
  9555. sprintf(str,"rm -f %s",temp);
  9556. system(str);
  9557. }
  9558. else
  9559. {
  9560. fclose(fptr1);
  9561. fclose(fptr2);
  9562. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9563. system(str);
  9564. resultRename = rename(temp, chargingProfiles[k]);
  9565. if(resultRename == 0)
  9566. {
  9567. DEBUG_INFO("File ChargingProfile renamed successfully");
  9568. }
  9569. else
  9570. {
  9571. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9572. }
  9573. if(comfirmstr[0]== 0)
  9574. {
  9575. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9576. }
  9577. //Check chargingProfile is empty file
  9578. /*------ Read the file ----------------*/
  9579. fptr1=fopen(chargingProfiles[k],"r");
  9580. ch=fgetc(fptr1);
  9581. rewind(fptr1);
  9582. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9583. if(ch!=EOF)
  9584. {
  9585. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9586. {
  9587. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9588. if(sLineWord[0]=='\0')
  9589. {
  9590. isEmptyFile = TRUE;
  9591. break;
  9592. }
  9593. else
  9594. {
  9595. isEmptyFile = FALSE;
  9596. break;
  9597. }
  9598. }
  9599. }
  9600. else
  9601. isEmptyFile = TRUE;
  9602. fclose(fptr1);
  9603. if(isEmptyFile == TRUE)
  9604. {
  9605. memset(str, 0, ARRAY_SIZE(str));
  9606. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9607. system(str);
  9608. }
  9609. /*------- End of reading ---------------*/
  9610. }
  9611. } // while(int k=0; k < ChargeProfileCount; k++)
  9612. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9613. end:
  9614. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9615. {
  9616. if(connectorIdInt == 0)
  9617. {
  9618. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9619. {
  9620. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9621. }
  9622. }
  9623. else
  9624. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9625. }
  9626. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9627. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9628. return result;
  9629. }
  9630. void createFirmwareVersionByDataTransfer(void)
  9631. {
  9632. json_object *FirmwareDataTransfer = json_object_new_object();
  9633. // AC & DC model
  9634. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9635. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9636. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9637. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9638. // DC model
  9639. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9640. {
  9641. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9642. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9643. (gunType[3] != GUN_TYPE_UNKNOWN))
  9644. {
  9645. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9646. }
  9647. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9648. {
  9649. // DS DM DW
  9650. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9651. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9652. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9653. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9654. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9655. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9656. }
  9657. else
  9658. {
  9659. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9660. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9661. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9662. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9663. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9664. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9665. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9666. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9667. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9668. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9669. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9670. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9671. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9672. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9673. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9674. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9675. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9676. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9677. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9678. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9679. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9680. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9681. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9682. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9683. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9684. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9685. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9686. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9687. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9688. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9689. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9690. }
  9691. }
  9692. // 4G model
  9693. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9694. {
  9695. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9696. }
  9697. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9698. json_object_put(FirmwareDataTransfer);
  9699. }
  9700. int handleDataTransferRequest(char *uuid, char *payload)
  9701. {
  9702. mtrace();
  9703. json_object *response = json_object_new_object();
  9704. int result = FAIL;
  9705. char tempvendorId[255]={0};
  9706. char tempmessageId[50]={0};
  9707. char tempdata[10240]={0};
  9708. char message[20480]={0};
  9709. DEBUG_INFO("handleDataTransferRequest...\n");
  9710. if((uuid != NULL) && (payload != NULL))
  9711. {
  9712. json_object *DataTransfer;
  9713. DataTransfer = json_tokener_parse(payload);
  9714. if(!is_error(DataTransfer))
  9715. {
  9716. // Required data
  9717. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9718. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9719. // Optional data
  9720. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9721. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9722. if(json_object_object_get(DataTransfer, "data") != NULL)
  9723. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9724. result = PASS;
  9725. }
  9726. json_object_put(DataTransfer);
  9727. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9728. {
  9729. // Send all moudle firmware version on EVSE
  9730. createFirmwareVersionByDataTransfer();
  9731. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9732. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9733. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9734. json_object_put(response);
  9735. }
  9736. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9737. {
  9738. system("/usr/bin/run_tmate_restart.sh &");
  9739. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9740. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9741. json_object_put(response);
  9742. }
  9743. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9744. {
  9745. json_object *data;
  9746. data = json_tokener_parse(tempdata);
  9747. if(!is_error(data))
  9748. {
  9749. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9750. {
  9751. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9752. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9753. if(json_object_object_get(data, "SOC") != NULL)
  9754. {
  9755. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9756. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9757. }
  9758. if(json_object_object_get(data, "Energy") != NULL)
  9759. {
  9760. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9761. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9762. }
  9763. if(json_object_object_get(data, "Duration") != NULL)
  9764. {
  9765. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9766. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9767. }
  9768. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9769. }
  9770. else
  9771. {
  9772. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9773. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9774. }
  9775. }
  9776. else
  9777. {
  9778. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9779. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9780. }
  9781. json_object_put(data);
  9782. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9783. json_object_put(response);
  9784. }
  9785. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9786. {
  9787. json_object *data;
  9788. data = json_tokener_parse(tempdata);
  9789. if(!is_error(data))
  9790. {
  9791. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9792. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9793. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9794. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9795. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9796. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9797. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9798. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9799. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9800. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9801. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9802. }
  9803. else
  9804. {
  9805. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9806. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9807. }
  9808. json_object_put(data);
  9809. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9810. json_object_put(response);
  9811. }
  9812. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9813. {
  9814. json_object *data;
  9815. data = json_tokener_parse(tempdata);
  9816. if(!is_error(data))
  9817. {
  9818. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9819. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9820. if(json_object_object_get(data, "idToken") != NULL)
  9821. {
  9822. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9823. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9824. }
  9825. else
  9826. {
  9827. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9828. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9829. }
  9830. if(json_object_object_get(data, "price") != NULL) //v1.0
  9831. {
  9832. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9833. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9834. }
  9835. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9836. {
  9837. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9838. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9839. }
  9840. else
  9841. {
  9842. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9843. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9844. }
  9845. }
  9846. else
  9847. {
  9848. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9849. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9850. }
  9851. json_object_put(data);
  9852. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9853. json_object_put(response);
  9854. }
  9855. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9856. {
  9857. json_object *data;
  9858. data = json_tokener_parse(tempdata);
  9859. if(!is_error(data))
  9860. {
  9861. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9862. if(json_object_object_get(data, "txId") != NULL)
  9863. {
  9864. // California pricing V1.0
  9865. DEBUG_INFO("California pricing V1.0\n");
  9866. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9867. sprintf((char*)dmsVersion, "1.0");
  9868. for(int idx = 0;idx<gunTotalNumber;idx++)
  9869. {
  9870. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9871. {
  9872. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9873. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9874. if(json_object_object_get(data, "description") != NULL)
  9875. {
  9876. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9877. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9878. }
  9879. else
  9880. {
  9881. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9882. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9883. }
  9884. }
  9885. }
  9886. }
  9887. else if(json_object_object_get(data, "transactionId") != NULL)
  9888. {
  9889. // California pricing V2.0
  9890. DEBUG_INFO("California pricing V2.0\n");
  9891. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9892. sprintf((char*)dmsVersion, "2.0");
  9893. for(int idx=0;idx<gunTotalNumber;idx++)
  9894. {
  9895. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9896. {
  9897. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9898. if(json_object_object_get(data, "timestamp") != NULL)
  9899. {
  9900. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9901. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9902. }
  9903. else
  9904. {
  9905. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9906. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9907. }
  9908. if(json_object_object_get(data, "meterValue") != NULL)
  9909. {
  9910. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9911. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9912. }
  9913. else
  9914. {
  9915. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9916. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9917. }
  9918. if(json_object_object_get(data, "cost") != NULL)
  9919. {
  9920. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9921. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9922. }
  9923. else
  9924. {
  9925. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9926. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9927. }
  9928. if(json_object_object_get(data, "state") != NULL)
  9929. {
  9930. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9931. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9932. }
  9933. else
  9934. {
  9935. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9936. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9937. }
  9938. if(json_object_object_get(data, "chargingPrice") != NULL)
  9939. {
  9940. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9941. {
  9942. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9943. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9944. }
  9945. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9946. {
  9947. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9948. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9949. }
  9950. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9951. {
  9952. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9953. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9954. }
  9955. }
  9956. else
  9957. {
  9958. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9959. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9960. }
  9961. if(json_object_object_get(data, "idlePrice") != NULL)
  9962. {
  9963. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9964. {
  9965. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9966. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9967. }
  9968. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9969. {
  9970. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9971. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9972. }
  9973. }
  9974. if(json_object_object_get(data, "nextPeriod") != NULL)
  9975. {
  9976. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9977. {
  9978. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9979. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9980. }
  9981. else
  9982. {
  9983. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9984. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9985. }
  9986. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9987. {
  9988. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9989. {
  9990. 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")));
  9991. ShmOCPP16Data->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"));
  9992. }
  9993. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9994. {
  9995. 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")));
  9996. ShmOCPP16Data->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"));
  9997. }
  9998. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9999. {
  10000. 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")));
  10001. ShmOCPP16Data->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"));
  10002. }
  10003. }
  10004. else
  10005. {
  10006. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10007. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10008. }
  10009. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10010. {
  10011. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10012. {
  10013. 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")));
  10014. ShmOCPP16Data->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"));
  10015. }
  10016. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10017. {
  10018. 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")));
  10019. ShmOCPP16Data->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"));
  10020. }
  10021. }
  10022. }
  10023. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10024. {
  10025. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10026. {
  10027. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10028. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10029. }
  10030. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10031. {
  10032. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10033. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10034. }
  10035. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10036. {
  10037. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10038. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10039. }
  10040. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10041. {
  10042. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10043. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10044. }
  10045. }
  10046. }
  10047. }
  10048. }
  10049. else
  10050. {
  10051. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10052. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10053. }
  10054. }
  10055. else
  10056. {
  10057. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10058. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10059. }
  10060. json_object_put(data);
  10061. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10062. json_object_put(response);
  10063. }
  10064. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10065. {
  10066. json_object *data;
  10067. data = json_tokener_parse(tempdata);
  10068. if(!is_error(data))
  10069. {
  10070. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10071. if(json_object_object_get(data, "txId") != NULL)
  10072. {
  10073. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10074. for(int idx = 0;idx<gunTotalNumber;idx++)
  10075. {
  10076. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10077. {
  10078. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10079. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10080. if(json_object_object_get(data, "description") != NULL)
  10081. {
  10082. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10083. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10084. }
  10085. else
  10086. {
  10087. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10088. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10089. }
  10090. }
  10091. }
  10092. }
  10093. else if(json_object_object_get(data, "transactionId") != NULL)
  10094. {
  10095. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10096. for(int idx = 0;idx<gunTotalNumber;idx++)
  10097. {
  10098. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10099. {
  10100. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10101. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10102. if(json_object_object_get(data, "cost") != NULL)
  10103. {
  10104. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10105. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10106. }
  10107. else
  10108. {
  10109. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10110. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10111. }
  10112. if(json_object_object_get(data, "priceText") != NULL)
  10113. {
  10114. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10115. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10116. }
  10117. else
  10118. {
  10119. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10120. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10121. }
  10122. if(json_object_object_get(data, "qrCodeText") != NULL)
  10123. {
  10124. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10125. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10126. }
  10127. }
  10128. }
  10129. }
  10130. else
  10131. {
  10132. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10133. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10134. }
  10135. }
  10136. else
  10137. {
  10138. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10139. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10140. }
  10141. json_object_put(data);
  10142. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10143. json_object_put(response);
  10144. }
  10145. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10146. {
  10147. json_object *data;
  10148. data = json_tokener_parse(tempdata);
  10149. if(!is_error(data))
  10150. {
  10151. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10152. if(json_object_object_get(data, "Content_Type") != NULL)
  10153. {
  10154. 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))
  10155. {
  10156. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10157. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10158. {
  10159. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10160. }
  10161. }
  10162. else
  10163. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10164. }
  10165. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10166. }
  10167. else
  10168. {
  10169. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10170. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10171. }
  10172. json_object_put(data);
  10173. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10174. json_object_put(response);
  10175. }
  10176. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10177. {
  10178. json_object *data;
  10179. data = json_tokener_parse(tempdata);
  10180. if(!is_error(data))
  10181. {
  10182. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10183. if(json_object_object_get(data, "ConnectorId") != NULL)
  10184. {
  10185. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10186. }
  10187. if(json_object_object_get(data, "SerialNo") != NULL)
  10188. {
  10189. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10190. }
  10191. if(json_object_object_get(data, "Page_Index") != NULL)
  10192. {
  10193. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10194. }
  10195. if(json_object_object_get(data, "Duration") != NULL)
  10196. {
  10197. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10198. }
  10199. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10200. }
  10201. else
  10202. {
  10203. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10204. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10205. }
  10206. json_object_put(data);
  10207. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10208. json_object_put(response);
  10209. }
  10210. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10211. {
  10212. json_object *data;
  10213. data = json_tokener_parse(tempdata);
  10214. if(!is_error(data))
  10215. {
  10216. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10217. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10218. {
  10219. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10220. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10221. else
  10222. {
  10223. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10224. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10225. }
  10226. }
  10227. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10228. {
  10229. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10230. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10231. else
  10232. {
  10233. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10234. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10235. }
  10236. }
  10237. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10238. {
  10239. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10240. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10241. else
  10242. {
  10243. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10244. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10245. }
  10246. }
  10247. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10248. {
  10249. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10250. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10251. else
  10252. {
  10253. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10254. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10255. }
  10256. }
  10257. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10258. {
  10259. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10260. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10261. else
  10262. {
  10263. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10264. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10265. }
  10266. }
  10267. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10268. {
  10269. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10270. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10271. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10272. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10273. else
  10274. {
  10275. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10276. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10277. }
  10278. }
  10279. if(json_object_object_get(data, "isAuthentication") != NULL)
  10280. {
  10281. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10282. {
  10283. case 0:
  10284. case 1:
  10285. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10286. break;
  10287. default:
  10288. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10289. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10290. break;
  10291. }
  10292. }
  10293. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10294. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10295. }
  10296. else
  10297. {
  10298. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10299. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10300. }
  10301. json_object_put(data);
  10302. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10303. json_object_put(response);
  10304. }
  10305. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10306. {
  10307. json_object *data;
  10308. data = json_tokener_parse(tempdata);
  10309. if(!is_error(data))
  10310. {
  10311. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10312. {
  10313. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10314. {
  10315. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10316. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10317. }
  10318. else
  10319. {
  10320. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10321. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10322. }
  10323. }
  10324. else
  10325. {
  10326. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10327. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10328. }
  10329. }
  10330. else
  10331. {
  10332. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10333. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10334. }
  10335. json_object_put(data);
  10336. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10337. json_object_put(response);
  10338. }
  10339. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10340. {
  10341. json_object *data;
  10342. data = json_tokener_parse(tempdata);
  10343. if(!is_error(data))
  10344. {
  10345. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10346. if(json_object_object_get(data, "stationName") != NULL)
  10347. {
  10348. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10349. }
  10350. else
  10351. {
  10352. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10353. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10354. }
  10355. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10356. {
  10357. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10358. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10359. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10360. }
  10361. }
  10362. else
  10363. {
  10364. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10365. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10366. }
  10367. json_object_put(data);
  10368. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10369. json_object_put(response);
  10370. }
  10371. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10372. {
  10373. json_object *data;
  10374. data = json_tokener_parse(tempdata);
  10375. if(!is_error(data))
  10376. {
  10377. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10378. if(json_object_object_get(data, "weatherId") != NULL)
  10379. {
  10380. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10381. }
  10382. else
  10383. {
  10384. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10385. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10386. }
  10387. if(json_object_object_get(data, "Temperature") != NULL)
  10388. {
  10389. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10390. }
  10391. else
  10392. {
  10393. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10394. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10395. }
  10396. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10397. {
  10398. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10399. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10400. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10401. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10402. );
  10403. }
  10404. }
  10405. else
  10406. {
  10407. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10408. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10409. }
  10410. json_object_put(data);
  10411. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10412. json_object_put(response);
  10413. }
  10414. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10415. {
  10416. json_object *data;
  10417. data = json_tokener_parse(tempdata);
  10418. if(!is_error(data))
  10419. {
  10420. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10421. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10422. {
  10423. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10424. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10425. }
  10426. else
  10427. {
  10428. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10429. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10430. }
  10431. }
  10432. else
  10433. {
  10434. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10435. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10436. }
  10437. json_object_put(data);
  10438. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10439. json_object_put(response);
  10440. }
  10441. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10442. {
  10443. json_object *data;
  10444. data = json_tokener_parse(tempdata);
  10445. if(!is_error(data))
  10446. {
  10447. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10448. {
  10449. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10450. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10451. if(gun_index < gunTotalNumber)
  10452. {
  10453. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10454. {
  10455. json_object *responsedata = json_object_new_object();
  10456. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10457. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10458. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10459. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10460. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10461. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10462. }
  10463. else
  10464. {
  10465. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10466. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10467. }
  10468. }
  10469. else
  10470. {
  10471. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10472. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10473. }
  10474. }
  10475. else
  10476. {
  10477. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10478. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10479. }
  10480. }
  10481. else
  10482. {
  10483. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10484. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10485. }
  10486. json_object_put(data);
  10487. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10488. json_object_put(response);
  10489. }
  10490. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10491. {
  10492. json_object *data;
  10493. data = json_tokener_parse(tempdata);
  10494. if(!is_error(data))
  10495. {
  10496. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10497. int gun_index = 0;
  10498. if(json_object_object_get(data, "ConnectorId") != NULL)
  10499. {
  10500. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10501. if(json_object_object_get(data, "occupancySN") != NULL)
  10502. {
  10503. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  10504. }
  10505. else
  10506. {
  10507. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10508. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  10509. }
  10510. if(json_object_object_get(data, "actionId") != NULL)
  10511. {
  10512. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  10513. }
  10514. else
  10515. {
  10516. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10517. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  10518. }
  10519. }
  10520. else
  10521. {
  10522. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10523. json_object_object_add(response, "data", json_object_new_string("ConnectorId data can not get."));
  10524. }
  10525. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10526. {
  10527. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  10528. }
  10529. }
  10530. else
  10531. {
  10532. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10533. json_object_object_add(response, "data", json_object_new_string("OccupancyFeeDisplay content got something wrong."));
  10534. }
  10535. json_object_put(data);
  10536. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10537. json_object_put(response);
  10538. }
  10539. else if(strstr(tempmessageId, "ID_SetOccupancyPrice") != NULL)
  10540. {
  10541. json_object *data;
  10542. data = json_tokener_parse(tempdata);
  10543. if(!is_error(data))
  10544. {
  10545. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10546. if(json_object_object_get(data, "price") != NULL)
  10547. {
  10548. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  10549. }
  10550. else
  10551. {
  10552. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10553. json_object_object_add(response, "data", json_object_new_string("price data can not get."));
  10554. }
  10555. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10556. {
  10557. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  10558. }
  10559. }
  10560. else
  10561. {
  10562. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10563. json_object_object_add(response, "data", json_object_new_string("SetOccupancyPrice content got something wrong."));
  10564. }
  10565. json_object_put(data);
  10566. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10567. json_object_put(response);
  10568. }
  10569. // Support ISO-15118 related message
  10570. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10571. {
  10572. char cmdBuf[1024]={0};
  10573. sprintf(cmdBuf, "openssl req -newkey rsa:2048 -out %s -nodes -keyout %s -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=%s/OU=IT/CN=%s\" &", CSR_V2G, PRIVATE_KEY_V2G, ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10574. system(cmdBuf);
  10575. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10576. json_object *responsedata = json_object_new_object();
  10577. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10578. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10579. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10580. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10581. json_object_put(response);
  10582. }
  10583. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10584. {
  10585. json_object *data;
  10586. data = json_tokener_parse(tempdata);
  10587. if(!is_error(data))
  10588. {
  10589. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10590. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10591. fclose(fp);
  10592. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10593. json_object *responsedata = json_object_new_object();
  10594. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10595. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10596. else
  10597. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10598. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10599. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10600. }
  10601. else
  10602. {
  10603. json_object *responsedata = json_object_new_object();
  10604. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10605. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10606. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10607. }
  10608. json_object_put(data);
  10609. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10610. json_object_put(response);
  10611. }
  10612. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10613. {
  10614. json_object *data;
  10615. data = json_tokener_parse(tempdata);
  10616. DEBUG_INFO("DeleteCertificate processing...\n");
  10617. if(!is_error(data))
  10618. {
  10619. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10620. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10621. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10622. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10623. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10624. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10625. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10626. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10627. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10628. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10629. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10630. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10631. char temp[256] = {0};
  10632. char compareData[256] = {0};
  10633. int isMatch = TRUE;
  10634. // Check certV2G
  10635. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10636. {
  10637. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10638. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10639. isMatch = FALSE;
  10640. if(isMatch == TRUE)
  10641. {
  10642. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10643. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10644. isMatch = FALSE;
  10645. }
  10646. if(isMatch == TRUE)
  10647. {
  10648. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10649. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10650. isMatch = FALSE;
  10651. }
  10652. if(isMatch == TRUE)
  10653. {
  10654. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10655. system(temp);
  10656. json_object *responsedata = json_object_new_object();
  10657. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10658. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10659. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10660. }
  10661. else
  10662. {
  10663. json_object *responsedata = json_object_new_object();
  10664. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10665. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10666. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10667. }
  10668. }
  10669. else
  10670. {
  10671. json_object *responsedata = json_object_new_object();
  10672. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10673. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10674. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10675. }
  10676. }
  10677. else
  10678. {
  10679. json_object *responsedata = json_object_new_object();
  10680. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10681. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10682. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10683. }
  10684. json_object_put(data);
  10685. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10686. json_object_put(response);
  10687. }
  10688. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10689. {
  10690. json_object *data;
  10691. data = json_tokener_parse(tempdata);
  10692. if(!is_error(data))
  10693. {
  10694. /*
  10695. * TODO:
  10696. * 1. Query certificate to response
  10697. */
  10698. json_object *responsedata = json_object_new_object();
  10699. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10700. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10701. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10702. }
  10703. else
  10704. {
  10705. json_object *responsedata = json_object_new_object();
  10706. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10707. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10708. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10709. }
  10710. json_object_put(data);
  10711. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10712. json_object_put(response);
  10713. }
  10714. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10715. {
  10716. json_object *data;
  10717. data = json_tokener_parse(tempdata);
  10718. if(!is_error(data))
  10719. {
  10720. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10721. if(json_object_object_get(data, "certificateType") != NULL)
  10722. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10723. if(json_object_object_get(data, "certificate") != NULL)
  10724. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10725. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10726. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10727. char temp[1024];
  10728. FILE *fp = fopen(tempCert, "w");
  10729. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10730. fclose(fp);
  10731. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10732. char strExpDate[30];
  10733. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10734. fp = popen(temp, "r");
  10735. if(fp)
  10736. {
  10737. while(fgets(temp, sizeof(temp), fp) != NULL)
  10738. {
  10739. if(strstr(temp, "notAfter=") != NULL)
  10740. {
  10741. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10742. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10743. break;
  10744. }
  10745. }
  10746. }
  10747. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10748. struct tm tmExpDate;
  10749. struct timeb tbExpDate;
  10750. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10751. tbExpDate.time = mktime(&tmExpDate);
  10752. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10753. {
  10754. DEBUG_INFO("The enddate is already expired...\n");
  10755. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10756. }
  10757. else
  10758. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10759. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10760. {
  10761. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10762. {
  10763. if(access(ROOTCA_V2G,F_OK) != -1)
  10764. {
  10765. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10766. rename(ROOTCA_V2G, "/Storage/rootCaV2g_fallback.pem");
  10767. rename(tempCert, ROOTCA_V2G);
  10768. }
  10769. else
  10770. {
  10771. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10772. rename(tempCert, ROOTCA_V2G);
  10773. }
  10774. json_object *responsedata = json_object_new_object();
  10775. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10776. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10777. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10778. }
  10779. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10780. {
  10781. if(access(ROOTCA_MO,F_OK) != -1)
  10782. {
  10783. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10784. rename(ROOTCA_MO, "/Storage/rootCaMo_fallback.pem");
  10785. rename(tempCert, ROOTCA_MO);
  10786. }
  10787. else
  10788. {
  10789. DEBUG_INFO("No existed MORootCertificate. Creating...\n");
  10790. rename(tempCert, ROOTCA_MO);
  10791. }
  10792. json_object *responsedata = json_object_new_object();
  10793. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10794. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10795. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10796. }
  10797. else
  10798. {
  10799. json_object *responsedata = json_object_new_object();
  10800. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10801. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10802. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10803. }
  10804. }
  10805. else
  10806. {
  10807. json_object *responsedata = json_object_new_object();
  10808. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10809. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10810. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10811. }
  10812. }
  10813. else
  10814. {
  10815. json_object *responsedata = json_object_new_object();
  10816. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10817. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10818. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10819. }
  10820. json_object_put(data);
  10821. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10822. json_object_put(response);
  10823. }
  10824. else
  10825. {
  10826. // Can not find valid message id
  10827. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10828. }
  10829. }
  10830. else
  10831. {
  10832. // Payload is null
  10833. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10834. }
  10835. LWS_Send(message);
  10836. return result;
  10837. }
  10838. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10839. {
  10840. mtrace();
  10841. int result = FAIL;
  10842. int connectorIdInt, durationInt;
  10843. char chargingRateUnitStr[4]={0};
  10844. char comfirmstr[20];
  10845. int confirmPeriods = 0;
  10846. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10847. json_object *GetCompositeSchedule;
  10848. GetCompositeSchedule = json_tokener_parse(payload);
  10849. if(!is_error(GetCompositeSchedule))
  10850. {
  10851. // Required data
  10852. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10853. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10854. else
  10855. connectorIdInt = -1;
  10856. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10857. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10858. else
  10859. durationInt = 86400;
  10860. // Optional data
  10861. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10862. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10863. }
  10864. json_object_put(GetCompositeSchedule);
  10865. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10866. if((connectorIdInt == 0) ||
  10867. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10868. {
  10869. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10870. struct StructChargingProfile tmpProfile[1];
  10871. if(strstr(chargingRateUnitStr, "W") != NULL)
  10872. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10873. else
  10874. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10875. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10876. {
  10877. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10878. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10879. }
  10880. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10881. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10882. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10883. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10884. {
  10885. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10886. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10887. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10888. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10889. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10890. {
  10891. confirmPeriods = idx;
  10892. break;
  10893. }
  10894. }
  10895. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10896. {
  10897. confirmPeriods += 1;
  10898. }
  10899. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10900. }
  10901. else
  10902. {
  10903. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10904. }
  10905. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10906. return result;
  10907. }
  10908. int handleGetConfigurationRequest(char *uuid, char *payload)
  10909. {
  10910. mtrace();
  10911. int result = FAIL;
  10912. int MaxKeySupported = 0;
  10913. int n_keys = 0;
  10914. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10915. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10916. json_object *GetConfiguration;
  10917. GetConfiguration = json_tokener_parse(payload);
  10918. if(!is_error(GetConfiguration))
  10919. {
  10920. // Optional data
  10921. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10922. {
  10923. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10924. {
  10925. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10926. n_keys = idx + 1;
  10927. }
  10928. }
  10929. }
  10930. json_object_put(GetConfiguration);
  10931. UnknownKeynum = 0;
  10932. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10933. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10934. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10935. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10936. if(n_keys != 0)
  10937. {
  10938. for(int i=0;i<n_keys;i++)
  10939. {
  10940. getKeyValue(requestKey[i]);
  10941. }
  10942. }
  10943. else
  10944. {
  10945. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10946. getKeyValue("");
  10947. }
  10948. processUnkownKey();
  10949. sendGetConfigurationConfirmation(uuid);
  10950. return result;
  10951. }
  10952. static char fnamePlusPath[100]={0};
  10953. static char fnamePWithNoPath[60]={0};
  10954. void checkUploadLog(void)
  10955. {
  10956. FILE *fp;
  10957. /* Open the command for reading. */
  10958. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10959. if (fp == NULL) {
  10960. DEBUG_WARN("Failed to run command\n" );
  10961. exit(1);
  10962. }
  10963. int ftppathlen = 0;
  10964. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10965. int i = 0;
  10966. /* Read the output a line at a time - output it. */
  10967. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10968. if(i==0)
  10969. {
  10970. ftppathlen = strlen(fnamePlusPath);
  10971. DEBUG_INFO("%s\n", fnamePlusPath);
  10972. fnamePlusPath[ftppathlen]='\0';
  10973. break;
  10974. }
  10975. i= i+1;
  10976. }
  10977. /* close */
  10978. pclose(fp);
  10979. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10980. {
  10981. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10982. {
  10983. fnamePlusPath[k]='\0';
  10984. }
  10985. }
  10986. i=1;
  10987. //char fname[60]={0};
  10988. while(i < ftppathlen)
  10989. {
  10990. int len=ftppathlen-i;
  10991. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10992. {
  10993. DEBUG_INFO("compare '/' all right\n");
  10994. break;
  10995. }
  10996. i=i+1;
  10997. }
  10998. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10999. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11000. fnamePWithNoPath[i+1] = '\0';
  11001. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11002. {
  11003. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11004. {
  11005. fnamePWithNoPath[j]='\0';
  11006. }
  11007. }
  11008. FILE* fp1 = fopen(fnamePlusPath, "r");
  11009. if (fp1)
  11010. {
  11011. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11012. // file exists
  11013. fclose(fp1);
  11014. }
  11015. else
  11016. {
  11017. // file doesn't exist
  11018. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11019. }
  11020. }
  11021. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11022. {
  11023. mtrace();
  11024. int result = FAIL;
  11025. time_t CurrentTime;
  11026. struct tm *tm;
  11027. pthread_t th_Status;
  11028. CurrentTime = time(NULL);
  11029. tm = localtime(&CurrentTime);
  11030. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11031. sprintf((char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  11032. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11033. if(!interLock.isGetDiagnosticGoing)
  11034. {
  11035. interLock.isGetDiagnosticGoing = 1;
  11036. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11037. sleep(1);
  11038. }
  11039. else
  11040. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11041. return result;
  11042. }
  11043. void* GetDiagnosticsProcess(void* data)
  11044. {
  11045. pthread_detach(pthread_self());
  11046. mtrace();
  11047. int retriesInt=0, retryIntervalInt=0;
  11048. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11049. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  11050. int port=0;
  11051. int isSuccess = FALSE;
  11052. char cmdBuf[2048];
  11053. struct tm *tmNow;
  11054. time_t CurrentTime;
  11055. struct tm tmStart;
  11056. struct tm tmStop;
  11057. CurrentTime = time(NULL);
  11058. tmNow=localtime(&CurrentTime);
  11059. uint16_t targetYear, targetMonth;
  11060. json_object *GetDiagnostics;
  11061. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11062. GetDiagnostics = json_tokener_parse(data);
  11063. if(!is_error(GetDiagnostics))
  11064. {
  11065. // Required data
  11066. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11067. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11068. // Optional data
  11069. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11070. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11071. else
  11072. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11073. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11074. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11075. else
  11076. retryIntervalInt = 30;
  11077. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11078. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11079. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11080. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11081. }
  11082. json_object_put(GetDiagnostics);
  11083. // Notify CSU to get log of dispensers.
  11084. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  11085. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  11086. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  11087. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  11088. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  11089. )
  11090. {
  11091. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StartTime,"%s",startTimestr);
  11092. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StopTime,"%s",stopTimestr);
  11093. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = TRUE;
  11094. struct timespec timerGetDiagnostics;
  11095. refreshStartTimer(&timerGetDiagnostics);
  11096. while(ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq != FALSE)
  11097. {
  11098. if(getDiffSecNow(timerGetDiagnostics)>=180)
  11099. {
  11100. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = FALSE;
  11101. DEBUG_INFO("Waiting log of dispenser timeout.");
  11102. }
  11103. }
  11104. }
  11105. // Pack log to compress file
  11106. 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) &&
  11107. (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))
  11108. {
  11109. // Pack system log
  11110. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11111. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11112. targetYear = tmStart.tm_year;
  11113. targetMonth = tmStart.tm_mon;
  11114. do
  11115. {
  11116. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11117. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11118. if(targetMonth+1>=13)
  11119. {
  11120. targetYear += 1;
  11121. targetMonth = 1;
  11122. }
  11123. else
  11124. {
  11125. targetMonth += 1;
  11126. }
  11127. }while((targetYear < (tmNow->tm_year+1900)) ||
  11128. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11129. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11130. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11131. sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
  11132. sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
  11133. sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
  11134. sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
  11135. system(cmdBuf);
  11136. // Pack charging & event log
  11137. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11138. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11139. targetYear = tmStart.tm_year;
  11140. targetMonth = tmStart.tm_mon;
  11141. do
  11142. {
  11143. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11144. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  11145. if(targetMonth+1>=13)
  11146. {
  11147. targetYear += 1;
  11148. targetMonth = 1;
  11149. }
  11150. else
  11151. {
  11152. targetMonth += 1;
  11153. }
  11154. }while((targetYear < (tmNow->tm_year+1900)) ||
  11155. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11156. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11157. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11158. system(cmdBuf);
  11159. // Combine log file
  11160. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11161. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11162. }
  11163. else
  11164. {
  11165. system("exec /root/logPackTools 'log' 6");
  11166. }
  11167. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11168. system(cmdBuf);
  11169. checkUploadLog();
  11170. //****************location*******************/
  11171. if(strcmp(locationstr,"")==0)
  11172. {
  11173. DEBUG_INFO("location is <Empty>!\n");
  11174. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11175. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11176. goto end;
  11177. }
  11178. memset(protocol, 0, ARRAY_SIZE(protocol));
  11179. memset(user, 0, ARRAY_SIZE(user) );
  11180. memset(password, 0, ARRAY_SIZE(password));
  11181. memset(host, 0, ARRAY_SIZE(host));
  11182. memset(path, 0, ARRAY_SIZE(path));
  11183. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11184. memset(host1, 0, ARRAY_SIZE(host1));
  11185. memset(path1, 0, ARRAY_SIZE(path1));
  11186. /*location: ftp://user:password@host:port/path*/
  11187. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11188. if((access(fnamePlusPath,F_OK))!=-1)
  11189. {
  11190. DEBUG_INFO("fnamePlusPath exist.\n");
  11191. }
  11192. else
  11193. {
  11194. DEBUG_INFO("fnamePlusPath not exist!\n");
  11195. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11196. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11197. goto end;
  11198. }
  11199. if(strchr(locationstr,'@')==NULL)
  11200. {
  11201. sscanf(locationstr,
  11202. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11203. protocol, host, &port, path);
  11204. strcpy(user,"anonymous");
  11205. strcpy(password,"");
  11206. }
  11207. else
  11208. {
  11209. //DEBUG_INFO("pch=%s\n", pch);
  11210. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11211. protocol, user, password, host, &port, path);
  11212. }
  11213. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11214. {
  11215. DEBUG_INFO("protocol is not ftp/http ! \n");
  11216. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11217. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11218. goto end;
  11219. }
  11220. if(strncmp(locationstr,"http", 4) == 0)
  11221. {
  11222. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11223. sprintf(ftppath,"/%s", path);
  11224. do
  11225. {
  11226. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11227. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11228. sleep(3);
  11229. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11230. if(!isSuccess)
  11231. {
  11232. DEBUG_INFO("Diagnostics fail.\n");
  11233. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11234. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11235. sleep(retryIntervalInt);
  11236. }
  11237. else
  11238. {
  11239. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11240. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11241. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11242. }
  11243. retriesInt--;
  11244. }while((isSuccess == 0)&&(retriesInt >= 0));
  11245. }
  11246. else
  11247. {
  11248. sscanf(host,"%[^/]%s",host1, path1);
  11249. if(strlen(path) > 0)
  11250. sprintf(ftppath,"/%s", path);
  11251. else
  11252. sprintf(ftppath,"/%s", path1);
  11253. int ftppathlen=strlen(ftppath);
  11254. int i=1;
  11255. char filenametemp[50];
  11256. while(i < ftppathlen)
  11257. {
  11258. int len=ftppathlen-i;
  11259. if(ftppath[len]== 47) // '/' ascll code: 47
  11260. {
  11261. DEBUG_INFO("find '/' all right\n");
  11262. break;
  11263. }
  11264. i=i+1;
  11265. }
  11266. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11267. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11268. filenametemp[i+1] = 0;
  11269. if(port == 0)
  11270. port = 21;
  11271. do
  11272. {
  11273. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11274. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11275. sleep(3);
  11276. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11277. if(!isSuccess)
  11278. {
  11279. DEBUG_INFO("Diagnostics fail.\n");
  11280. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11281. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11282. sleep(retryIntervalInt);
  11283. }
  11284. else
  11285. {
  11286. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11287. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11288. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11289. }
  11290. retriesInt--;
  11291. }while((!isSuccess)&&(retriesInt >= 0));
  11292. }
  11293. end:
  11294. system("rm -f /mnt/*");
  11295. system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
  11296. sleep(5);
  11297. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11298. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11299. interLock.isGetDiagnosticGoing = 0;
  11300. pthread_exit(NULL);
  11301. }
  11302. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11303. {
  11304. mtrace();
  11305. int result = FAIL;
  11306. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11307. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11308. {
  11309. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11310. locallistVersion = -1;
  11311. }
  11312. else
  11313. {
  11314. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11315. locallistVersion = 0;
  11316. OCPP_getListVerion();
  11317. }
  11318. //from db.OCPP_getListVerion
  11319. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11320. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11321. sendGetLocalListVersionConfirmation(uuid,"");
  11322. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11323. return result;
  11324. }
  11325. int handleRemoteStartRequest(char *uuid, char *payload)
  11326. {
  11327. mtrace();
  11328. int result = PASS;
  11329. int connectorIdInt=-1;
  11330. int tempIndex = 0;
  11331. char comfirmstr[20]={0};
  11332. char cmdBuf[512];
  11333. json_object *RemoteStartTransaction;
  11334. FILE *fp;
  11335. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11336. if(server_pending == TRUE)
  11337. {
  11338. result = FAIL;
  11339. }
  11340. RemoteStartTransaction = json_tokener_parse(payload);
  11341. if(!is_error(RemoteStartTransaction))
  11342. {
  11343. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11344. {
  11345. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11346. }
  11347. else
  11348. {
  11349. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11350. {
  11351. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11352. {
  11353. connectorIdInt = (gun_index+1);
  11354. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11355. break;
  11356. }
  11357. }
  11358. }
  11359. if(connectorIdInt == 0)
  11360. {
  11361. DEBUG_WARN("Connector id shall not equal 0.\n");
  11362. result = FAIL;
  11363. }
  11364. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11365. {
  11366. DEBUG_WARN("idTag should not be NULL.\n");
  11367. result = FAIL;
  11368. }
  11369. else if(connectorIdInt == -1)
  11370. {
  11371. DEBUG_INFO("Connector id does not specific.\n");
  11372. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11373. {
  11374. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11375. // Required data
  11376. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11377. // Optional data
  11378. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11379. {
  11380. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11381. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11382. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11383. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11384. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11385. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11386. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11387. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11388. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11389. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11390. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11391. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11392. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11393. {
  11394. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  11395. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11396. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  11397. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11398. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  11399. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11400. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  11401. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11402. {
  11403. 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++)
  11404. {
  11405. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  11406. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  11407. 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)
  11408. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  11409. }
  11410. }
  11411. }
  11412. }
  11413. else
  11414. {
  11415. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11416. }
  11417. }
  11418. }
  11419. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11420. {
  11421. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11422. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11423. // Required data
  11424. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11425. // Optional data
  11426. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11427. {
  11428. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11429. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11430. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11431. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11432. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11433. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11434. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11435. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11436. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11437. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11438. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11439. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11440. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11441. {
  11442. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  11443. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11444. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  11445. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11446. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  11447. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11448. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  11449. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11450. {
  11451. 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++)
  11452. {
  11453. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  11454. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  11455. 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)
  11456. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  11457. }
  11458. }
  11459. }
  11460. }
  11461. else
  11462. {
  11463. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11464. }
  11465. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') && (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W'))
  11466. {
  11467. DEBUG_INFO("Checking charging status for DW series...\n");
  11468. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11469. {
  11470. if(cpinitateMsg.bits[gun_index].isOnCharging ||
  11471. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL) ||
  11472. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing") != NULL))
  11473. {
  11474. DEBUG_INFO("Found gun-%d is in charging.\n", gun_index);
  11475. if(connectorIdInt != (gun_index+1))
  11476. {
  11477. DEBUG_WARN("DWseries--> Other connector is in charging.\n");
  11478. result = FAIL;
  11479. break;
  11480. }
  11481. }
  11482. }
  11483. }
  11484. }
  11485. else
  11486. {
  11487. DEBUG_WARN("Connector id is over maximun value.\n");
  11488. result = FAIL;
  11489. }
  11490. }
  11491. if(result == PASS)
  11492. {
  11493. if(connectorIdInt > 0)
  11494. {
  11495. DEBUG_INFO("Specified gun-%d type: %d\n", (connectorIdInt -1), gunType[connectorIdInt -1]);
  11496. //check Transaction active
  11497. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11498. {
  11499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11500. {
  11501. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11502. }
  11503. else
  11504. {
  11505. tempIndex = connectorIdInt -1;
  11506. }
  11507. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11508. {
  11509. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11510. {
  11511. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11512. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11513. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11514. {
  11515. //Reserved
  11516. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11517. }
  11518. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11519. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11520. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11521. {
  11522. //Reserved
  11523. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11524. {
  11525. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11526. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11527. goto end;
  11528. }
  11529. }
  11530. else
  11531. {
  11532. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11533. {
  11534. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11535. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11536. goto end;
  11537. }
  11538. }//END FOR ELSE
  11539. }
  11540. }// END FOR CHAdeMO_QUANTITY
  11541. }
  11542. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11543. {
  11544. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11545. {
  11546. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11547. }
  11548. else
  11549. {
  11550. tempIndex = connectorIdInt -1;
  11551. }
  11552. for (int index = 0; index < CCS_QUANTITY; index++)
  11553. {
  11554. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11555. {
  11556. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11557. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11558. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11559. {
  11560. //Reserved
  11561. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11562. }
  11563. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11564. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11565. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11566. {
  11567. //Reserved
  11568. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11569. {
  11570. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11571. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11572. goto end;
  11573. }
  11574. }
  11575. else
  11576. {
  11577. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11578. {
  11579. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11580. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11581. goto end;
  11582. }
  11583. }// END FOR ELSE
  11584. }
  11585. }// END FOR CCS_QUANTITY
  11586. }
  11587. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11588. {
  11589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11590. {
  11591. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11592. }
  11593. else
  11594. {
  11595. tempIndex = connectorIdInt -1;
  11596. }
  11597. for (int index = 0; index < GB_QUANTITY; index++)
  11598. {
  11599. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11600. {
  11601. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11602. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11603. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11604. {
  11605. //Reserved
  11606. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11607. }
  11608. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11609. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11610. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11611. {
  11612. //Reserved
  11613. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11614. {
  11615. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11616. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11617. goto end;
  11618. }
  11619. }
  11620. else
  11621. {
  11622. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11623. {
  11624. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11625. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11626. goto end;
  11627. }
  11628. }// END FOR ELSE
  11629. }
  11630. } // END FOR GB_QUANTITY
  11631. }
  11632. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11633. {
  11634. tempIndex = connectorIdInt -1;
  11635. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11636. {
  11637. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11638. {
  11639. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11640. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11641. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11642. {
  11643. //Reserved
  11644. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11645. }
  11646. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11647. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11648. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11649. {
  11650. //Reserved
  11651. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11652. {
  11653. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11654. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11655. goto end;
  11656. }
  11657. }
  11658. else
  11659. {
  11660. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11661. {
  11662. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11663. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11664. goto end;
  11665. }
  11666. }// END FOR ELSE
  11667. }
  11668. } // END FOR GB_QUANTITY
  11669. }
  11670. else
  11671. {
  11672. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11673. {
  11674. tempIndex = 2;
  11675. }
  11676. else
  11677. {
  11678. tempIndex = connectorIdInt -1;
  11679. }
  11680. for (int index = 0; index < AC_QUANTITY; index++)
  11681. {
  11682. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11683. {
  11684. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11685. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11686. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11687. {
  11688. //Reserved
  11689. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11690. }
  11691. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11692. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11693. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11694. {
  11695. //Reserved
  11696. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11697. {
  11698. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11699. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11700. goto end;
  11701. }
  11702. }
  11703. else
  11704. {
  11705. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11706. {
  11707. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11708. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11709. goto end;
  11710. }
  11711. }//END FOR ELSE
  11712. }
  11713. }// END FOR AC_QUANTITY
  11714. }
  11715. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11716. {
  11717. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11718. {
  11719. // Save profile to file
  11720. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11721. system(cmdBuf);
  11722. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11723. fp = fopen(cmdBuf, "w");
  11724. 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));
  11725. fclose(fp);
  11726. }
  11727. else
  11728. {
  11729. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11730. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11731. goto end;
  11732. }
  11733. }
  11734. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11735. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11736. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11737. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11738. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11739. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11740. }
  11741. else
  11742. {
  11743. uint8_t isHasIdleConnector = FALSE;
  11744. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11745. {
  11746. DEBUG_INFO("Check not specified gun-%d type: %d\n", gun_index, gunType[gun_index]);
  11747. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11748. {
  11749. isHasIdleConnector = TRUE;
  11750. break;
  11751. }
  11752. }
  11753. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11754. {
  11755. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11756. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11757. {
  11758. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11759. {
  11760. // Save profile to file
  11761. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11762. system(cmdBuf);
  11763. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11764. fp = fopen(cmdBuf, "w");
  11765. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11766. fclose(fp);
  11767. refreshStartTimer(&clientTime.RemoteStartWait);
  11768. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11769. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11770. }
  11771. else
  11772. {
  11773. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11774. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11775. }
  11776. }
  11777. else
  11778. {
  11779. refreshStartTimer(&clientTime.RemoteStartWait);
  11780. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11781. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11782. }
  11783. }
  11784. else
  11785. {
  11786. DEBUG_INFO("There is not any connector is idle.\n");
  11787. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11788. }
  11789. }
  11790. }
  11791. else
  11792. {
  11793. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11794. }
  11795. end:
  11796. json_object_put(RemoteStartTransaction);
  11797. sendRemoteStartConfirmation(uuid, comfirmstr);
  11798. return result;
  11799. }
  11800. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11801. {
  11802. mtrace();
  11803. int result = FAIL;
  11804. int match = FALSE;
  11805. int GunNO = 0;
  11806. int tempIndex = 0;
  11807. int transactionIdInt=0;
  11808. int transactionIdIsNULL= TRUE;
  11809. char comfirmstr[20];
  11810. json_object *RemoteStopTransaction;
  11811. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11812. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11813. if(server_pending == TRUE)
  11814. {
  11815. return 0;
  11816. }
  11817. RemoteStopTransaction = json_tokener_parse(payload);
  11818. if(!is_error(RemoteStopTransaction))
  11819. {
  11820. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11821. {
  11822. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11823. transactionIdIsNULL = FALSE;
  11824. }
  11825. }
  11826. json_object_put(RemoteStopTransaction);
  11827. if(transactionIdIsNULL == FALSE)
  11828. {
  11829. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11830. {
  11831. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11832. {
  11833. //check Transaction active
  11834. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11835. {
  11836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11837. {
  11838. tempIndex = ((gun_index==2) ? 1: 0);
  11839. }
  11840. else
  11841. {
  11842. tempIndex = gun_index;
  11843. }
  11844. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11845. {
  11846. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11847. {
  11848. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11849. {
  11850. match = TRUE;
  11851. GunNO = gun_index;
  11852. }
  11853. }
  11854. }// END FOR CHAdeMO_QUANTITY
  11855. }
  11856. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11857. {
  11858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11859. {
  11860. tempIndex = ((gun_index==2) ? 1: 0);
  11861. }
  11862. else
  11863. {
  11864. tempIndex = gun_index;
  11865. }
  11866. for (int index = 0; index < CCS_QUANTITY; index++)
  11867. {
  11868. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11869. {
  11870. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11871. {
  11872. match = TRUE;
  11873. GunNO = gun_index;
  11874. }
  11875. }
  11876. }// END FOR CCS_QUANTITY
  11877. }
  11878. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11879. {
  11880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11881. {
  11882. tempIndex = ((gun_index==2) ? 1: 0);
  11883. }
  11884. else
  11885. {
  11886. tempIndex = gun_index;
  11887. }
  11888. for (int index = 0; index < GB_QUANTITY; index++)
  11889. {
  11890. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11891. {
  11892. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11893. {
  11894. match = TRUE;
  11895. GunNO = gun_index;
  11896. }
  11897. }
  11898. }// END FOR GB_QUANTITY
  11899. }
  11900. else if(gunType[gun_index] == GUN_TYPE_DO)
  11901. {
  11902. tempIndex = gun_index;
  11903. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11904. {
  11905. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11906. {
  11907. 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
  11908. {
  11909. match = TRUE;
  11910. GunNO = gun_index;
  11911. }
  11912. }
  11913. }// END FOR GB_QUANTITY
  11914. }
  11915. else
  11916. {
  11917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11918. {
  11919. tempIndex = 2;
  11920. }
  11921. else
  11922. {
  11923. tempIndex = gun_index;
  11924. }
  11925. for (int index = 0; index < AC_QUANTITY; index++)
  11926. {
  11927. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11928. {
  11929. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11930. {
  11931. match = TRUE;
  11932. GunNO = gun_index;
  11933. }
  11934. }
  11935. }// END FOR CHAdeMO_QUANTITY
  11936. } // END FOR AC ELSE
  11937. }// CHECK IF ResponseTransactionId == transactionIdInt
  11938. }//END FOR
  11939. if( match == TRUE)
  11940. {
  11941. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11942. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11943. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11944. }
  11945. else
  11946. {
  11947. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11948. }
  11949. }
  11950. else
  11951. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11952. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11953. return result;
  11954. }
  11955. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11956. {
  11957. mtrace();
  11958. int result = FAIL;
  11959. int connectorIdInt=0, reservationIdInt=0;
  11960. int tempIndex = 0;
  11961. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11962. char comfirmstr[20]={0};
  11963. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11964. int c = 0;
  11965. char *loc;
  11966. //char *ptr;
  11967. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11968. strcpy(sstrtemp, stringtrimspace(payload));
  11969. //***(1)connectorId ****/
  11970. c=0;
  11971. loc = strstr(sstrtemp, "connectorId");
  11972. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11973. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11974. {
  11975. sstr[c] = loc[strlen("connectorId")+2+c];
  11976. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11977. c++;
  11978. }
  11979. sstr[c] = '\0';
  11980. connectorIdInt = atoi(sstr);
  11981. //***(2)expiryDate ****/
  11982. loc = strstr(sstrtemp, "expiryDate");
  11983. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11984. c = 0;
  11985. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11986. {
  11987. sstr[c] = loc[3+strlen("expiryDate")+c];
  11988. c++;
  11989. }
  11990. sstr[c] = '\0';
  11991. strcpy(expiryDatestr, sstr);
  11992. //***(3)idTag ****/
  11993. loc = strstr(sstrtemp, "idTag");
  11994. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11995. c = 0;
  11996. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11997. {
  11998. sstr[c] = loc[3+strlen("idTag")+c];
  11999. c++;
  12000. }
  12001. sstr[c] = '\0';
  12002. strcpy(idTagstr, sstr);
  12003. //***(4)parentIdTag ****/
  12004. loc = strstr(sstrtemp, "parentIdTag");
  12005. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12006. c = 0;
  12007. if(loc == NULL)
  12008. {
  12009. strcpy(parentIdTagstr, "");
  12010. }
  12011. else
  12012. {
  12013. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  12014. {
  12015. sstr[c] = loc[3+strlen("parentIdTag")+c];
  12016. c++;
  12017. }
  12018. sstr[c] = '\0';
  12019. strcpy(parentIdTagstr, sstr);
  12020. }
  12021. //***(5)reservationId ****/
  12022. c=0;
  12023. loc = strstr(sstrtemp, "reservationId");
  12024. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12025. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  12026. {
  12027. sstr[c] = loc[strlen("reservationId")+2+c];
  12028. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12029. c++;
  12030. }
  12031. sstr[c] = '\0';
  12032. reservationIdInt = atoi(sstr);
  12033. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12034. /*
  12035. enum SYSTEM_STATUS
  12036. {
  12037. SYS_MODE_BOOTING = 0,
  12038. SYS_MODE_IDLE = 1,
  12039. SYS_MODE_AUTHORIZING = 2,
  12040. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12041. SYS_MODE_REASSIGN = 4,
  12042. SYS_MODE_PREPARING = 5,
  12043. SYS_MODE_PREPARE_FOR_EV = 6,
  12044. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12045. SYS_MODE_CHARGING = 8,
  12046. SYS_MODE_TERMINATING = 9,
  12047. SYS_MODE_COMPLETE = 10,
  12048. SYS_MODE_ALARM = 11,
  12049. SYS_MODE_FAULT = 12,
  12050. SYS_MODE_RESERVATION = 13,
  12051. SYS_MODE_BOOKING = 14,
  12052. SYS_MODE_MAINTAIN = 15,
  12053. SYS_MODE_DEBUG = 16,
  12054. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12055. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12056. SYS_MODE_UPDATE = 19
  12057. };
  12058. */
  12059. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12060. {
  12061. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12062. goto end;
  12063. }
  12064. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12065. {
  12066. //check Transaction active
  12067. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12068. {
  12069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12070. {
  12071. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12072. }
  12073. else
  12074. {
  12075. tempIndex = connectorIdInt -1;
  12076. }
  12077. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12078. {
  12079. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12080. {
  12081. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12082. {
  12083. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12084. {
  12085. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12086. {
  12087. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12088. {
  12089. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12090. }
  12091. else
  12092. {
  12093. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12095. }
  12096. }
  12097. 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'))
  12098. {
  12099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12100. }
  12101. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12102. {
  12103. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12104. }
  12105. else
  12106. {
  12107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12108. }
  12109. }
  12110. 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
  12111. {
  12112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12113. }
  12114. }
  12115. else
  12116. {
  12117. //replace reservation
  12118. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12119. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12120. }
  12121. }
  12122. } // END FOR CHAdeMO_QUANTITY
  12123. }
  12124. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12125. {
  12126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12127. {
  12128. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12129. }
  12130. else
  12131. {
  12132. tempIndex = connectorIdInt -1;
  12133. }
  12134. for (int index = 0; index < CCS_QUANTITY; index++)
  12135. {
  12136. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12137. {
  12138. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12139. {
  12140. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12141. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12142. {
  12143. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12144. {
  12145. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12146. {
  12147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12148. }
  12149. else
  12150. {
  12151. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12152. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12153. }
  12154. }
  12155. 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'))
  12156. {
  12157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12158. }
  12159. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12160. {
  12161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12162. }
  12163. else
  12164. {
  12165. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12166. }
  12167. }
  12168. 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
  12169. {
  12170. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12171. }
  12172. }
  12173. else
  12174. {
  12175. //replace reservation
  12176. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12178. }
  12179. }
  12180. } // END FOR CCS_QUANTITY
  12181. }
  12182. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12183. {
  12184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12185. {
  12186. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12187. }
  12188. else
  12189. {
  12190. tempIndex = connectorIdInt -1;
  12191. }
  12192. for (int index = 0; index < GB_QUANTITY; index++)
  12193. {
  12194. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12195. {
  12196. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12197. {
  12198. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12199. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12200. {
  12201. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12202. {
  12203. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12204. {
  12205. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12206. }
  12207. else
  12208. {
  12209. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12211. }
  12212. }
  12213. 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'))
  12214. {
  12215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12216. }
  12217. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12218. {
  12219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12220. }
  12221. else
  12222. {
  12223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12224. }
  12225. }
  12226. 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
  12227. {
  12228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12229. }
  12230. }
  12231. else
  12232. {
  12233. //replace reservation
  12234. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12236. }
  12237. }
  12238. }// END FOR GB_QUANTITY
  12239. }
  12240. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12241. {
  12242. tempIndex = connectorIdInt -1;
  12243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12244. {
  12245. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12246. {
  12247. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12248. {
  12249. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12250. 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
  12251. {
  12252. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12253. {
  12254. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12255. {
  12256. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12257. }
  12258. else
  12259. {
  12260. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12261. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12262. }
  12263. }
  12264. 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'))
  12265. {
  12266. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12267. }
  12268. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12269. {
  12270. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12271. }
  12272. else
  12273. {
  12274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12275. }
  12276. }
  12277. 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
  12278. {
  12279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12280. }
  12281. }
  12282. else
  12283. {
  12284. //replace reservation
  12285. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12286. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12287. }
  12288. }
  12289. }// END FOR GB_QUANTITY
  12290. }
  12291. else
  12292. {
  12293. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12294. {
  12295. tempIndex = 2;
  12296. }
  12297. else
  12298. {
  12299. tempIndex = (connectorIdInt -1);
  12300. }
  12301. for (int index = 0; index < AC_QUANTITY; index++)
  12302. {
  12303. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12304. {
  12305. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12306. {
  12307. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12308. {
  12309. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12310. {
  12311. 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))
  12312. {
  12313. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12314. }
  12315. else
  12316. {
  12317. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12318. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12319. }
  12320. }
  12321. 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'))
  12322. {
  12323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12324. }
  12325. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12326. {
  12327. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12328. }
  12329. else
  12330. {
  12331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12332. }
  12333. }
  12334. 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
  12335. {
  12336. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12337. }
  12338. }
  12339. else
  12340. {
  12341. //replace reservation
  12342. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12343. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12344. }
  12345. }
  12346. } // END FOR AC_QUANTITY
  12347. }
  12348. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12349. }
  12350. else if(connectorIdInt == 0)
  12351. {
  12352. //check Transaction active
  12353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12354. {
  12355. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12356. {
  12357. 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'))
  12358. {
  12359. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12360. goto end;
  12361. }
  12362. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12363. {
  12364. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12365. goto end;
  12366. }
  12367. 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
  12368. {
  12369. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12370. goto end;
  12371. }
  12372. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12373. {
  12374. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12375. goto end;
  12376. }
  12377. }
  12378. }// END FOR CHAdeMO_QUANTITY
  12379. for (int index = 0; index < CCS_QUANTITY; index++)
  12380. {
  12381. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12382. {
  12383. 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'))
  12384. {
  12385. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12386. goto end;
  12387. }
  12388. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12389. {
  12390. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12391. goto end;
  12392. }
  12393. 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
  12394. {
  12395. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12396. goto end;
  12397. }
  12398. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12399. {
  12400. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12401. goto end;
  12402. }
  12403. }
  12404. } // END FOR CCS_QUANTITY
  12405. for (int index = 0; index < GB_QUANTITY; index++)
  12406. {
  12407. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12408. {
  12409. 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'))
  12410. {
  12411. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12412. goto end;
  12413. }
  12414. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12415. {
  12416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12417. goto end;
  12418. }
  12419. 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
  12420. {
  12421. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12422. goto end;
  12423. }
  12424. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12425. {
  12426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12427. goto end;
  12428. }
  12429. }
  12430. } // END FOR GB_QUANTITY
  12431. for (int index = 0; index < AC_QUANTITY; index++)
  12432. {
  12433. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12434. {
  12435. 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'))
  12436. {
  12437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12438. goto end;
  12439. }
  12440. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12441. {
  12442. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12443. goto end;
  12444. }
  12445. 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
  12446. {
  12447. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12448. goto end;
  12449. }
  12450. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12451. {
  12452. 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))
  12453. {
  12454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12455. goto end;
  12456. }
  12457. }
  12458. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12459. {
  12460. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12461. goto end;
  12462. }
  12463. }
  12464. }// END FOR AC_QUANTITY
  12465. //The connectorId is 0
  12466. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12468. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12469. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12470. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12471. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12472. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12473. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12474. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12475. result = TRUE;
  12476. return result;
  12477. }
  12478. else
  12479. {
  12480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12481. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12482. }
  12483. if(strcmp(comfirmstr,"Accepted") == 0)
  12484. {
  12485. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12486. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12487. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12488. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12489. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12490. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12491. result = TRUE;
  12492. return result;
  12493. }
  12494. end:
  12495. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12496. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12497. return result;
  12498. }
  12499. int handleResetRequest(char *uuid, char *payload)
  12500. {
  12501. mtrace();
  12502. int result = FAIL;
  12503. char sstr[10]={0},sstrtemp[30]={ 0 };
  12504. char typestr[10]={0};
  12505. char comfirmstr[20]={0};
  12506. int c = 0;
  12507. char *loc;
  12508. DEBUG_INFO("handleResetRequest...\n");
  12509. strcpy(sstrtemp, stringtrimspace(payload));
  12510. loc = strstr(sstrtemp, "type");
  12511. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12512. c = 0;
  12513. while (loc[3+strlen("type")+c] != '\"')
  12514. {
  12515. sstr[c] = loc[3+strlen("type")+c];
  12516. c++;
  12517. }
  12518. sstr[c] = '\0';
  12519. strcpy(typestr,sstr);
  12520. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12521. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12522. {
  12523. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12524. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12525. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12526. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12527. }
  12528. else
  12529. {
  12530. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12531. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12532. result = PASS;
  12533. }
  12534. sendResetConfirmation(uuid, comfirmstr);
  12535. return result;
  12536. }
  12537. int handleSendLocalListRequest(char *uuid, char *payload)
  12538. {
  12539. mtrace();
  12540. int result = FAIL;
  12541. char comfirmstr[20];
  12542. int checkState_Faulted = FALSE;
  12543. json_object *SendLocalList;
  12544. DEBUG_INFO("handleSendLocalListRequest...\n");
  12545. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12546. {
  12547. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12548. goto end;
  12549. }
  12550. //check Charge Point state
  12551. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12552. {
  12553. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12554. {
  12555. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12556. }
  12557. }
  12558. for (int index = 0; index < CCS_QUANTITY; index++)
  12559. {
  12560. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12561. {
  12562. checkState_Faulted = TRUE; //OCPP Status
  12563. }
  12564. }
  12565. for (int index = 0; index < GB_QUANTITY; index++)
  12566. {
  12567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12568. {
  12569. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12570. }
  12571. }
  12572. //check Charge Point state
  12573. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12574. {
  12575. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12576. {
  12577. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12578. }
  12579. }
  12580. //check Charge Point state
  12581. for (int index = 0; index < AC_QUANTITY; index++)
  12582. {
  12583. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12584. {
  12585. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12586. }
  12587. }
  12588. if(checkState_Faulted == TRUE)
  12589. {
  12590. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12591. goto end;
  12592. }
  12593. // Parsing payload
  12594. SendLocalList = json_tokener_parse(payload);
  12595. if(!is_error(SendLocalList))
  12596. {
  12597. // Required data
  12598. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12599. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12600. // Optional data
  12601. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12602. {
  12603. //Check UpdateType
  12604. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12605. {
  12606. //Local list full update
  12607. DEBUG_INFO("Local list full update.\n");
  12608. locallistVersion = 0;
  12609. OCPP_getListVerion();
  12610. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12611. {
  12612. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12613. goto end;
  12614. }
  12615. OCPP_cleanLocalList();
  12616. }
  12617. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12618. {
  12619. //Local list different update
  12620. DEBUG_INFO("Local list different update.\n");
  12621. locallistVersion = 0;
  12622. OCPP_getListVerion();
  12623. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12624. {
  12625. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12626. goto end;
  12627. }
  12628. }
  12629. else
  12630. {
  12631. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12632. goto end;
  12633. }
  12634. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12635. {
  12636. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12637. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12638. goto end;
  12639. }
  12640. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12641. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12642. {
  12643. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag"))));
  12644. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12645. {
  12646. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", stringtrimspace((char *)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"))));
  12647. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12648. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", stringtrimspace((char *)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"))));
  12649. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12650. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", stringtrimspace((char *)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"))));
  12651. }
  12652. // Add to db
  12653. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12654. {
  12655. //Local list full update
  12656. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12657. idx,
  12658. ShmOCPP16Data->SendLocalList.ListVersion,
  12659. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12660. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12661. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12662. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12663. // update list
  12664. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12665. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12666. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12667. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12668. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12669. }
  12670. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12671. {
  12672. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12673. idx,
  12674. ShmOCPP16Data->SendLocalList.ListVersion,
  12675. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12676. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12677. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12678. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12679. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12680. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12681. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12682. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12683. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12684. }
  12685. }
  12686. }
  12687. else
  12688. {
  12689. //Check UpdateType
  12690. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12691. {
  12692. //Local list full update
  12693. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12694. OCPP_cleanLocalList();
  12695. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12696. goto end;
  12697. }
  12698. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12699. {
  12700. //Local list different update
  12701. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12702. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12703. goto end;
  12704. }
  12705. }
  12706. result = PASS;
  12707. }
  12708. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12709. end:
  12710. json_object_put(SendLocalList);
  12711. sendSendLocalListConfirmation(uuid, comfirmstr);
  12712. return result;
  12713. }
  12714. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12715. {
  12716. mtrace();
  12717. int result = FAIL;
  12718. struct StructSetChargingProfile SetProfileReq = {0};
  12719. int tempchargingProfileIdInt;
  12720. int tempstackLevelInt;
  12721. int chargingSchedulePeriodCount = 0;
  12722. char comfirmstr[20]={0};
  12723. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12724. char rmFileCmd[128]={0};
  12725. int profileQuantity = 0;
  12726. int replaceableProfileCnt = 0;
  12727. json_object *SetChargingProfile;
  12728. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12729. SetChargingProfile = json_tokener_parse(payload);
  12730. if(!is_error(SetChargingProfile))
  12731. {
  12732. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12733. {
  12734. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12735. }
  12736. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12737. {
  12738. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12739. {
  12740. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12741. }
  12742. else
  12743. {
  12744. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12745. DEBUG_WARN("Cannot find chargingProfileId field.");
  12746. goto end;
  12747. }
  12748. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12749. {
  12750. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12751. }
  12752. else
  12753. {
  12754. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12755. DEBUG_WARN("Cannot find stackLevel field.");
  12756. goto end;
  12757. }
  12758. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12759. {
  12760. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12761. }
  12762. else
  12763. {
  12764. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12765. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12766. goto end;
  12767. }
  12768. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12769. {
  12770. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12771. }
  12772. else
  12773. {
  12774. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12775. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12776. goto end;
  12777. }
  12778. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12779. {
  12780. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12781. }
  12782. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12783. {
  12784. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12785. }
  12786. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12787. {
  12788. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12789. }
  12790. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12791. {
  12792. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12793. }
  12794. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12795. {
  12796. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12797. {
  12798. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  12799. }
  12800. else
  12801. {
  12802. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12803. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12804. goto end;
  12805. }
  12806. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12807. {
  12808. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12809. }
  12810. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12811. {
  12812. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12813. }
  12814. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12815. {
  12816. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  12817. }
  12818. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12819. {
  12820. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12821. if(chargingSchedulePeriodCount <= 10)
  12822. {
  12823. 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++)
  12824. {
  12825. 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)
  12826. {
  12827. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  12828. }
  12829. else
  12830. {
  12831. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12832. DEBUG_WARN("Cannot find startPeriod field.");
  12833. goto end;
  12834. }
  12835. 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)
  12836. {
  12837. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  12838. }
  12839. else
  12840. {
  12841. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12842. DEBUG_WARN("Cannot find limit field.");
  12843. goto end;
  12844. }
  12845. 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)
  12846. {
  12847. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  12848. }
  12849. }
  12850. }
  12851. }
  12852. else
  12853. {
  12854. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12855. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12856. goto end;
  12857. }
  12858. }
  12859. else
  12860. {
  12861. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12862. DEBUG_WARN("Cannot find chargingSchedule field.");
  12863. goto end;
  12864. }
  12865. }
  12866. }
  12867. // Profile periods quantity check
  12868. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12869. {
  12870. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12871. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12872. goto end;
  12873. }
  12874. // Check invalid limit
  12875. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12876. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12877. {
  12878. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12879. {
  12880. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12881. {
  12882. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  12883. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12884. {
  12885. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12886. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12887. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12888. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12889. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12890. goto end;
  12891. }
  12892. }
  12893. }
  12894. else
  12895. {
  12896. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12897. {
  12898. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower) ||
  12899. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  12900. {
  12901. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12902. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12903. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12904. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12905. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12906. goto end;
  12907. }
  12908. }
  12909. }
  12910. }
  12911. // Profile purpose info check
  12912. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12913. {
  12914. FILE *fp;
  12915. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12916. if(SetProfileReq.ConnectorId != 0)
  12917. {
  12918. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12919. DEBUG_WARN("Profile connector id is not 0.\n");
  12920. goto end;
  12921. }
  12922. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12923. if (!fp)
  12924. {
  12925. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12926. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12927. }
  12928. else
  12929. {
  12930. char *line = NULL;
  12931. size_t len = 0;
  12932. while(getline(&line, &len, fp) != -1)
  12933. {
  12934. json_object *obj = NULL;
  12935. obj = json_tokener_parse(line);
  12936. if(is_error(obj))
  12937. {
  12938. DEBUG_ERROR("Parse txProfile from file error.\n");
  12939. }
  12940. else
  12941. {
  12942. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12943. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12944. {
  12945. profileQuantity += 1;
  12946. }
  12947. else
  12948. replaceableProfileCnt += 1;
  12949. }
  12950. }
  12951. }
  12952. fclose(fp);
  12953. }
  12954. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12955. {
  12956. FILE *fp;
  12957. char filename[128]={0};
  12958. int tmpProfileQuantity;
  12959. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12960. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12961. {
  12962. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12963. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12964. goto end;
  12965. }
  12966. if(SetProfileReq.ConnectorId == 0)
  12967. {
  12968. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12969. {
  12970. tmpProfileQuantity = 0;
  12971. memset(filename, 0, ARRAY_SIZE(filename));
  12972. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12973. fp = fopen(filename, "r");
  12974. if (!fp)
  12975. {
  12976. DEBUG_INFO("%s does not create.\n", filename);
  12977. fp = fopen(filename, "w+");
  12978. }
  12979. else
  12980. {
  12981. char *line = NULL;
  12982. size_t len = 0;
  12983. while(getline(&line, &len, fp) != -1)
  12984. {
  12985. json_object *obj = NULL;
  12986. obj = json_tokener_parse(line);
  12987. if(is_error(obj))
  12988. {
  12989. DEBUG_ERROR("Parse txProfile from file error.\n");
  12990. }
  12991. else
  12992. {
  12993. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12994. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12995. {
  12996. tmpProfileQuantity += 1;
  12997. }
  12998. else
  12999. replaceableProfileCnt += 1;
  13000. }
  13001. }
  13002. }
  13003. fclose(fp);
  13004. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  13005. }
  13006. }
  13007. else
  13008. {
  13009. memset(filename, 0, ARRAY_SIZE(filename));
  13010. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13011. fp = fopen(filename, "r");
  13012. if (!fp)
  13013. {
  13014. DEBUG_INFO("%s does not create.\n", filename);
  13015. fp = fopen(filename, "w+");
  13016. }
  13017. else
  13018. {
  13019. char *line = NULL;
  13020. size_t len = 0;
  13021. while(getline(&line, &len, fp) != -1)
  13022. {
  13023. json_object *obj = NULL;
  13024. obj = json_tokener_parse(line);
  13025. if(is_error(obj))
  13026. {
  13027. DEBUG_ERROR("Parse txProfile from file error.\n");
  13028. }
  13029. else
  13030. {
  13031. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13032. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13033. {
  13034. profileQuantity += 1;
  13035. }
  13036. else
  13037. replaceableProfileCnt += 1;
  13038. }
  13039. }
  13040. }
  13041. fclose(fp);
  13042. }
  13043. }
  13044. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13045. {
  13046. int isMatchTransactiodId= FALSE;
  13047. FILE *fp;
  13048. char filename[128]={0};
  13049. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13050. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13051. if(SetProfileReq.ConnectorId == 0)
  13052. {
  13053. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13054. DEBUG_WARN("Profile connector id is 0.\n");
  13055. goto end;
  13056. }
  13057. int tempIndex = 0;
  13058. //check Transaction active
  13059. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13060. {
  13061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13062. {
  13063. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13064. }
  13065. else
  13066. {
  13067. tempIndex = SetProfileReq.ConnectorId -1;
  13068. }
  13069. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13070. {
  13071. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13072. {
  13073. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13074. {
  13075. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13076. {
  13077. isMatchTransactiodId = TRUE;
  13078. break;
  13079. }
  13080. }
  13081. }
  13082. }
  13083. }
  13084. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13085. {
  13086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13087. {
  13088. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13089. }
  13090. else
  13091. {
  13092. tempIndex = SetProfileReq.ConnectorId -1;
  13093. }
  13094. for (int index = 0; index < CCS_QUANTITY; index++)
  13095. {
  13096. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13097. {
  13098. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13099. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13100. {
  13101. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13102. {
  13103. isMatchTransactiodId = TRUE;
  13104. break;
  13105. }
  13106. }
  13107. }
  13108. }
  13109. }
  13110. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13111. {
  13112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13113. {
  13114. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13115. }
  13116. else
  13117. {
  13118. tempIndex = SetProfileReq.ConnectorId -1;
  13119. }
  13120. for (int index = 0; index < GB_QUANTITY; index++)
  13121. {
  13122. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13123. {
  13124. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13125. {
  13126. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13127. {
  13128. isMatchTransactiodId = TRUE;
  13129. break;
  13130. }
  13131. }
  13132. }
  13133. }
  13134. }
  13135. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13136. {
  13137. tempIndex = SetProfileReq.ConnectorId -1;
  13138. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13139. {
  13140. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13141. {
  13142. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13143. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13144. {
  13145. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13146. {
  13147. isMatchTransactiodId = TRUE;
  13148. break;
  13149. }
  13150. }
  13151. }
  13152. }
  13153. }
  13154. else
  13155. {
  13156. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13157. {
  13158. tempIndex = 2;
  13159. }
  13160. else
  13161. {
  13162. tempIndex = (SetProfileReq.ConnectorId -1);
  13163. }
  13164. for (int index = 0; index < AC_QUANTITY; index++)
  13165. {
  13166. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13167. {
  13168. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13169. {
  13170. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13171. {
  13172. isMatchTransactiodId = TRUE;
  13173. break;
  13174. }
  13175. }
  13176. }
  13177. }
  13178. }
  13179. //check Transaction active
  13180. if(isMatchTransactiodId == FALSE)
  13181. {
  13182. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13183. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13184. goto end;
  13185. }
  13186. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13187. {
  13188. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13189. DEBUG_WARN("Connector id is over max gun number.\n");
  13190. goto end;
  13191. }
  13192. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13193. fp = fopen(filename, "r");
  13194. if (!fp)
  13195. {
  13196. DEBUG_INFO("%s does not create.\n", filename);
  13197. fp = fopen(filename, "w+");
  13198. }
  13199. else
  13200. {
  13201. char *line = NULL;
  13202. size_t len = 0;
  13203. while(getline(&line, &len, fp) != -1)
  13204. {
  13205. json_object *obj = NULL;
  13206. obj = json_tokener_parse(line);
  13207. if(is_error(obj))
  13208. {
  13209. DEBUG_ERROR("Parse txProfile from file error.\n");
  13210. }
  13211. else
  13212. {
  13213. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13214. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13215. {
  13216. profileQuantity += 1;
  13217. }
  13218. else
  13219. replaceableProfileCnt += 1;
  13220. }
  13221. }
  13222. }
  13223. fclose(fp);
  13224. }
  13225. // Check ChargeProfileMaxStackLevel
  13226. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13227. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13228. {
  13229. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13230. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13231. goto end;
  13232. }
  13233. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13234. {
  13235. FILE *fp;
  13236. char dataLine[4096]={0};
  13237. char fnametemp[128]={0};
  13238. int tmpProfileQuantity;
  13239. //Check ChargePointMaxProfile.json exit
  13240. profileQuantity = 0;
  13241. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13242. {
  13243. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13244. //Check Charging Profile Count
  13245. tmpProfileQuantity = 0;
  13246. while(fscanf(fp, "%s", dataLine) != EOF)
  13247. {
  13248. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13249. {
  13250. profileQuantity += 1;
  13251. tmpProfileQuantity += 1;
  13252. }
  13253. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13254. }
  13255. fclose(fp);
  13256. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13257. }
  13258. //Check TxDefaultProfile_%d.json
  13259. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13260. {
  13261. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13262. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13263. if((access(fnametemp,F_OK))!=-1)
  13264. {
  13265. fp = fopen(fnametemp, "r");
  13266. //Check Charging Profile Count
  13267. tmpProfileQuantity = 0;
  13268. while(fscanf(fp, "%s", dataLine) != EOF)
  13269. {
  13270. //DEBUG_INFO("word=%s\n",word);
  13271. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13272. {
  13273. profileQuantity += 1;
  13274. tmpProfileQuantity += 1;
  13275. }
  13276. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13277. }
  13278. fclose(fp);
  13279. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13280. }
  13281. }
  13282. //Check TxProfile_%d.json
  13283. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13284. {
  13285. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13286. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13287. if((access(fnametemp,F_OK))!=-1)
  13288. {
  13289. fp = fopen(fnametemp, "r");
  13290. //Check Charging Profile Count
  13291. tmpProfileQuantity = 0;
  13292. while(fscanf(fp, "%s", dataLine) != EOF)
  13293. {
  13294. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13295. {
  13296. profileQuantity += 1;
  13297. tmpProfileQuantity += 1;
  13298. }
  13299. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13300. }
  13301. fclose(fp);
  13302. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13303. }
  13304. }
  13305. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13306. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13307. // To check total Profile quantity
  13308. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13309. {
  13310. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13311. {
  13312. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13313. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13314. goto end;
  13315. }
  13316. }
  13317. else
  13318. {
  13319. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13320. {
  13321. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13322. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13323. goto end;
  13324. }
  13325. }
  13326. }
  13327. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13328. //**********************************Write to File********************************************************/
  13329. {
  13330. FILE *infile;
  13331. FILE *outfile;
  13332. char dataLine[4096]={0};
  13333. char filename[128]={0};
  13334. int chkChar=0;
  13335. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13336. {
  13337. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13338. {
  13339. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13340. }
  13341. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13342. {
  13343. if(SetProfileReq.ConnectorId==0)
  13344. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13345. else
  13346. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13347. }
  13348. else
  13349. {
  13350. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13351. }
  13352. infile = fopen (filename, "r");
  13353. outfile = fopen (tempfile, "w");
  13354. chkChar = fgetc(infile);
  13355. rewind(infile);
  13356. if(chkChar == EOF)
  13357. {
  13358. // Profile is empty
  13359. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13360. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13361. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13362. fclose(infile);
  13363. fclose(outfile);
  13364. sprintf(rmFileCmd,"rm -f %s",filename);
  13365. system(rmFileCmd);
  13366. rename(tempfile, filename);
  13367. }
  13368. else
  13369. {
  13370. // Profile is not empty
  13371. int ChargingProfileAdded = FALSE;
  13372. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13373. {
  13374. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13375. json_object *tmpChargingProfile;
  13376. tmpChargingProfile = json_tokener_parse(dataLine);
  13377. if(!is_error(SetChargingProfile))
  13378. {
  13379. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13380. {
  13381. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13382. {
  13383. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13384. }
  13385. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13386. {
  13387. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13388. }
  13389. }
  13390. }
  13391. json_object_put(tmpChargingProfile);
  13392. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13393. {
  13394. if(ChargingProfileAdded == FALSE)
  13395. {
  13396. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13397. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13398. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13399. ChargingProfileAdded = TRUE;
  13400. }
  13401. }
  13402. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13403. {
  13404. if(ChargingProfileAdded == FALSE)
  13405. {
  13406. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13407. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13408. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13409. ChargingProfileAdded = TRUE;
  13410. }
  13411. }
  13412. else
  13413. {
  13414. fprintf(outfile,"%s\n",dataLine);
  13415. if(ChargingProfileAdded == FALSE)
  13416. {
  13417. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13418. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13419. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13420. ChargingProfileAdded = TRUE;
  13421. }
  13422. }
  13423. } // end of while loop
  13424. fclose(infile);
  13425. fclose(outfile);
  13426. sprintf(rmFileCmd,"rm -f %s",filename);
  13427. system(rmFileCmd);
  13428. rename(tempfile, filename);
  13429. }
  13430. }
  13431. sleep(1);
  13432. result = TRUE;
  13433. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13434. }
  13435. end:
  13436. json_object_put(SetChargingProfile);
  13437. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13438. {
  13439. if(SetProfileReq.ConnectorId == 0)
  13440. {
  13441. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13442. {
  13443. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13444. }
  13445. }
  13446. else
  13447. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13448. }
  13449. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13450. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13451. return result;
  13452. }
  13453. int handleTriggerMessageRequest(char *uuid, char *payload)
  13454. {
  13455. mtrace();
  13456. int result = FAIL;
  13457. int connectorIdIsNULL = FALSE;
  13458. int connectorIdInt =0;
  13459. char sstr[40]={0},sstrtemp[100]={ 0 };
  13460. char requestedMessagestr[40]={0};
  13461. char comfirmstr[20]={0};
  13462. int c = 0;
  13463. char *loc;
  13464. DEBUG_INFO("handleTriggerMessageRequest\n");
  13465. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13466. strcpy(sstrtemp, stringtrimspace(payload));
  13467. c = 0;
  13468. loc = strstr(sstrtemp, "requestedMessage");
  13469. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13470. {
  13471. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13472. c++;
  13473. }
  13474. sstr[c] = '\0';
  13475. strcpy(requestedMessagestr, sstr);
  13476. c = 0;
  13477. loc = strstr(sstrtemp, "connectorId");
  13478. if(loc == NULL)
  13479. {
  13480. connectorIdIsNULL = TRUE;
  13481. }
  13482. else
  13483. {
  13484. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13485. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13486. {
  13487. sstr[c] = loc[strlen("connectorId")+2+c];
  13488. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13489. c++;
  13490. }
  13491. sstr[c] = '\0';
  13492. connectorIdInt = atoi(sstr);
  13493. }
  13494. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13495. {
  13496. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13497. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13498. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13499. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13500. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13501. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13502. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13503. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13504. {
  13505. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13506. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13507. return TRUE;
  13508. }
  13509. else
  13510. {
  13511. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13512. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13513. }
  13514. }
  13515. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13516. {
  13517. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13518. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13519. return TRUE;
  13520. }
  13521. //==========================
  13522. // Trigger message
  13523. //==========================
  13524. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13525. {
  13526. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13527. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13528. {
  13529. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13530. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13531. }
  13532. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13533. }
  13534. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13535. {
  13536. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13537. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13538. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13539. }
  13540. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13541. {
  13542. //sendBootNotificationRequest();
  13543. server_sign = FALSE;
  13544. }
  13545. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13546. {
  13547. refreshStartTimer(&clientTime.Heartbeat);
  13548. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13549. }
  13550. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13551. {
  13552. if(connectorIdIsNULL == FALSE)
  13553. {
  13554. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13555. {
  13556. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13557. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13558. }
  13559. }
  13560. else
  13561. {
  13562. for(int idx=0;idx< gunTotalNumber;idx++)
  13563. {
  13564. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13565. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13566. }
  13567. }
  13568. }
  13569. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13570. {
  13571. if(connectorIdIsNULL == FALSE)
  13572. {
  13573. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13574. {
  13575. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13576. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13577. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13578. }
  13579. }
  13580. else
  13581. {
  13582. for(int idx=0;idx< gunTotalNumber;idx++)
  13583. {
  13584. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13585. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13586. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13587. }
  13588. }
  13589. }
  13590. return result;
  13591. }
  13592. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13593. {
  13594. mtrace();
  13595. int result = FAIL;
  13596. int connectorIdInt =0;
  13597. char comfirmstr[20]={0};
  13598. int tempIndex = 0;
  13599. json_object *UnlockConnector;
  13600. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13601. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13602. UnlockConnector = json_tokener_parse(payload);
  13603. if(!is_error(UnlockConnector))
  13604. {
  13605. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13606. {
  13607. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13608. }
  13609. }
  13610. json_object_put(UnlockConnector);
  13611. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13612. if(gunTotalNumber == 0)
  13613. {
  13614. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13615. goto end;
  13616. }
  13617. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13618. {
  13619. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13620. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13621. goto end;
  13622. }
  13623. else
  13624. {
  13625. //check Transaction active
  13626. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13627. {
  13628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13629. {
  13630. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13631. }
  13632. else
  13633. {
  13634. tempIndex = connectorIdInt -1;
  13635. }
  13636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13637. {
  13638. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13639. {
  13640. //stop Transaction
  13641. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13642. }
  13643. }
  13644. }
  13645. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13646. {
  13647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13648. {
  13649. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13650. }
  13651. else
  13652. {
  13653. tempIndex = connectorIdInt -1;
  13654. }
  13655. for (int index = 0; index < CCS_QUANTITY; index++)
  13656. {
  13657. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13658. {
  13659. //stop Transaction
  13660. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13661. }
  13662. }
  13663. }
  13664. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13665. {
  13666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13667. {
  13668. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13669. }
  13670. else
  13671. {
  13672. tempIndex = connectorIdInt -1;
  13673. }
  13674. for (int index = 0; index < GB_QUANTITY; index++)
  13675. {
  13676. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13677. {
  13678. //stop Transaction
  13679. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13680. }
  13681. }
  13682. }
  13683. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13684. {
  13685. tempIndex = connectorIdInt -1;
  13686. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13687. {
  13688. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13689. {
  13690. //stop Transaction
  13691. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13692. }
  13693. }
  13694. }
  13695. else
  13696. {
  13697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13698. {
  13699. tempIndex = 2;
  13700. }
  13701. else
  13702. {
  13703. tempIndex = connectorIdInt-1;
  13704. }
  13705. for (int index = 0; index < AC_QUANTITY; index++)
  13706. {
  13707. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13708. {
  13709. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13710. }
  13711. }
  13712. }
  13713. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13714. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13715. result = TRUE;
  13716. return result;
  13717. }
  13718. end:
  13719. //json_object_put(obj); --- remove temporally
  13720. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13721. return result;
  13722. }
  13723. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13724. {
  13725. mtrace();
  13726. int result = FAIL;
  13727. pthread_t t;
  13728. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13729. sendUpdateFirmwareConfirmation(uuid);
  13730. if(!interLock.isUpdateFirmwareGoing)
  13731. {
  13732. interLock.isUpdateFirmwareGoing = 1;
  13733. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13734. sleep(1);
  13735. }
  13736. else
  13737. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13738. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13739. return result;
  13740. }
  13741. void *UpdateFirmwareProcess(void *data)
  13742. {
  13743. pthread_detach(pthread_self());
  13744. mtrace();
  13745. int retriesInt =0, retryIntervalInt=0;
  13746. char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
  13747. int port=0;
  13748. char locationstr[2048]={0}, retrieveDatestr[36]={0};
  13749. int isSuccess = 0;
  13750. char ftpbuf[2048];
  13751. char temp[2048];
  13752. char * pch;
  13753. char filenametemp[256];
  13754. json_object *UpdateFirmware;
  13755. UpdateFirmware = json_tokener_parse(data);
  13756. if(!is_error(UpdateFirmware))
  13757. {
  13758. // Required data
  13759. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13760. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13761. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13762. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13763. // Optional data
  13764. if(json_object_object_get(UpdateFirmware, "retries"))
  13765. {
  13766. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13767. }
  13768. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13769. {
  13770. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13771. }
  13772. }
  13773. json_object_put(UpdateFirmware);
  13774. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13775. memset(path, 0, ARRAY_SIZE(path));
  13776. // Wait retrieveData
  13777. if(strlen(retrieveDatestr) > 10)
  13778. {
  13779. do
  13780. {
  13781. sleep(1);
  13782. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13783. }
  13784. // Ready to download
  13785. system("rm -f /mnt/*");
  13786. if(strncmp(locationstr,"http", 4) == 0)
  13787. {
  13788. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13789. sprintf(ftppath,"/%s", path);
  13790. DEBUG_INFO("locationstr: %s\n", locationstr);
  13791. DEBUG_INFO("protocol: %s\n",protocol);
  13792. DEBUG_INFO("host: %s\n",host);
  13793. DEBUG_INFO("path: %s\n",path);
  13794. DEBUG_INFO("ftppath: %s\n",ftppath);
  13795. int ftppathlen=strlen(ftppath);
  13796. int i=1;
  13797. while(i < ftppathlen)
  13798. {
  13799. int len=ftppathlen-i;
  13800. if(ftppath[len]== 47) // '/' ascll code: 47
  13801. {
  13802. DEBUG_INFO("compare '/' all right\n");
  13803. break;
  13804. }
  13805. i=i+1;
  13806. }
  13807. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13808. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13809. filenametemp[i+1] = 0;
  13810. do
  13811. {
  13812. sleep(1);
  13813. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13814. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13815. sleep(1);
  13816. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13817. if(!isSuccess)
  13818. {
  13819. sleep(1);
  13820. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13821. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13822. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13823. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13824. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13825. }
  13826. else
  13827. {
  13828. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13829. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13830. }
  13831. retriesInt--;
  13832. }while((isSuccess == 0)&&(retriesInt >= 0));
  13833. }
  13834. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13835. {
  13836. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13837. memset(temp, 0, ARRAY_SIZE(temp));
  13838. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13839. strcpy(ftpbuf, locationstr);
  13840. int ftppathlen=strlen(ftpbuf);
  13841. int i=1;
  13842. while(i < ftppathlen)
  13843. {
  13844. int len=ftppathlen-i;
  13845. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13846. {
  13847. DEBUG_INFO(" compare '/' all right\n");
  13848. break;
  13849. }
  13850. i=i+1;
  13851. }
  13852. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13853. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13854. filenametemp[i+1] = 0;
  13855. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13856. pch=strchr(temp,'@');
  13857. if(pch==NULL)
  13858. {
  13859. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13860. protocol, host, &port, path);
  13861. strcpy(user,"anonymous");
  13862. strcpy(password,"");
  13863. }
  13864. else
  13865. {
  13866. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13867. protocol, user, host, &port, path);
  13868. }
  13869. sscanf(host,"%[^/]%s",host1, path1);
  13870. sprintf(ftppath,"%s:/%s", host,path);
  13871. if(port == 0)
  13872. {
  13873. port = 21;
  13874. }
  13875. do
  13876. {
  13877. sleep(1);
  13878. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13879. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13880. sleep(1);
  13881. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13882. if(!isSuccess)
  13883. {
  13884. //BulldogUtil.sleepMs(interval*1000);
  13885. DEBUG_INFO("Update firmware request and download file fail.\n");
  13886. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13887. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13888. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13889. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13890. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13891. }
  13892. else
  13893. {
  13894. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13895. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13896. }
  13897. retriesInt--;
  13898. }while((!isSuccess)&&(retriesInt >= 0));
  13899. }
  13900. else if((strncmp(locationstr,"ftp", 3) == 0) || (strncmp(locationstr,"ftps", 4) == 0)) // ftp/ftps
  13901. {
  13902. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13903. memset(temp, 0, ARRAY_SIZE(temp));
  13904. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13905. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13906. int ftppathlen=strlen(ftpbuf);
  13907. int i=1;
  13908. while(i < ftppathlen)
  13909. {
  13910. int len=ftppathlen-i;
  13911. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13912. {
  13913. DEBUG_INFO(" compare '/' all right\n");
  13914. break;
  13915. }
  13916. i=i+1;
  13917. }
  13918. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13919. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13920. filenametemp[i+1] = 0;
  13921. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13922. pch=strchr(temp,'@');
  13923. if(pch==NULL)
  13924. {
  13925. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13926. protocol, host, &port, path);
  13927. strcpy(user,"anonymous");
  13928. strcpy(password,"");
  13929. }
  13930. else
  13931. {
  13932. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13933. protocol, user, password, host, &port, path);
  13934. }
  13935. sscanf(host,"%[^/]%s",host1, path1);
  13936. sprintf(ftppath,"%s", path1);
  13937. //DEBUG_INFO("protocol =%s\n",protocol);
  13938. //DEBUG_INFO("user =%s\n",user);
  13939. //DEBUG_INFO("password =%s\n",password);
  13940. //DEBUG_INFO("host1 =%s\n",host1);
  13941. //DEBUG_INFO("port =%d\n",port);
  13942. //DEBUG_INFO("path1 =%s\n",path1);
  13943. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13944. //ftpFile(host, user, password, port, ftppath, fname);
  13945. //download firmware pthred
  13946. if(port == 0)
  13947. {
  13948. port = 21;
  13949. }
  13950. do
  13951. {
  13952. sleep(1);
  13953. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13954. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13955. sleep(1);
  13956. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13957. if(!isSuccess)
  13958. {
  13959. //BulldogUtil.sleepMs(interval*1000);
  13960. DEBUG_INFO("Update firmware request and download file fail.\n");
  13961. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13962. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13963. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13964. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13965. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13966. }
  13967. else
  13968. {
  13969. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13970. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13971. }
  13972. retriesInt--;
  13973. }while((!isSuccess)&&(retriesInt >= 0));
  13974. }
  13975. else
  13976. {
  13977. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13978. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13979. sleep(1);
  13980. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13981. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13982. }
  13983. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13984. {
  13985. sleep(3);
  13986. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13987. }
  13988. interLock.isUpdateFirmwareGoing = 0;
  13989. pthread_exit(NULL);
  13990. }
  13991. int handleCertificateSignedRequest(char *uuid, char *payload)
  13992. {
  13993. mtrace();
  13994. int result = PASS;
  13995. json_object *CertificateSigned;
  13996. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13997. CertificateSigned = json_tokener_parse(payload);
  13998. if(!is_error(CertificateSigned))
  13999. {
  14000. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  14001. }
  14002. json_object_put(CertificateSigned);
  14003. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  14004. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  14005. fclose(fp);
  14006. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14007. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  14008. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  14009. {
  14010. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  14011. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  14012. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  14013. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  14014. }
  14015. else
  14016. {
  14017. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  14018. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  14019. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14020. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14021. }
  14022. sendCertificateSignedConfirmation(uuid);
  14023. return result;
  14024. }
  14025. int handleDeleteCertificateRequest(char *uuid, char *payload)
  14026. {
  14027. mtrace();
  14028. int result = PASS;
  14029. json_object *DeleteCertificate;
  14030. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  14031. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  14032. DeleteCertificate = json_tokener_parse(payload);
  14033. if(!is_error(DeleteCertificate))
  14034. {
  14035. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14036. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14037. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14038. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14039. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14040. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14041. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14042. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14043. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  14044. {
  14045. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  14046. }
  14047. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  14048. {
  14049. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  14050. }
  14051. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  14052. {
  14053. ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  14054. }
  14055. char temp[256] = {0};
  14056. char compareData[256] = {0};
  14057. int isMatch = TRUE;
  14058. // Check CentralSystemRootCertificate
  14059. if(access(ROOTCA_CS,F_OK) != -1)
  14060. {
  14061. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14062. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14063. for(int i = 0; compareData[i]; i++)
  14064. {
  14065. compareData[i] = tolower(compareData[i]);
  14066. }
  14067. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14068. isMatch = FALSE;
  14069. if(isMatch == TRUE)
  14070. {
  14071. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14072. for(int i = 0; compareData[i]; i++)
  14073. {
  14074. compareData[i] = tolower(compareData[i]);
  14075. }
  14076. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14077. isMatch = FALSE;
  14078. }
  14079. if(isMatch == TRUE)
  14080. {
  14081. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14082. for(int i = 0; compareData[i]; i++)
  14083. {
  14084. compareData[i] = tolower(compareData[i]);
  14085. }
  14086. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14087. isMatch = FALSE;
  14088. }
  14089. if(isMatch == TRUE)
  14090. {
  14091. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  14092. sprintf(temp, "rm -f %s", ROOTCA_CS);
  14093. system(temp);
  14094. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14095. goto End;
  14096. }
  14097. }
  14098. // Check ManufacturerRootCertificate
  14099. if(access(ROOTCA_MF,F_OK) != -1)
  14100. {
  14101. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  14102. isMatch = TRUE;
  14103. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  14104. for(int i = 0; compareData[i]; i++)
  14105. {
  14106. compareData[i] = tolower(compareData[i]);
  14107. }
  14108. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14109. isMatch = FALSE;
  14110. if(isMatch == TRUE)
  14111. {
  14112. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  14113. for(int i = 0; compareData[i]; i++)
  14114. {
  14115. compareData[i] = tolower(compareData[i]);
  14116. }
  14117. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14118. isMatch = FALSE;
  14119. }
  14120. if(isMatch == TRUE)
  14121. {
  14122. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  14123. for(int i = 0; compareData[i]; i++)
  14124. {
  14125. compareData[i] = tolower(compareData[i]);
  14126. }
  14127. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14128. isMatch = FALSE;
  14129. }
  14130. if(isMatch == TRUE)
  14131. {
  14132. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  14133. sprintf(temp, "rm -f %s", ROOTCA_MF);
  14134. system(temp);
  14135. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14136. goto End;
  14137. }
  14138. }
  14139. // Check certCP
  14140. if(access(CERTIFICATE_CP,F_OK) != -1)
  14141. {
  14142. DEBUG_INFO("Checking certCP...\n");
  14143. isMatch = TRUE;
  14144. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  14145. for(int i = 0; compareData[i]; i++)
  14146. {
  14147. compareData[i] = tolower(compareData[i]);
  14148. }
  14149. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14150. isMatch = FALSE;
  14151. if(isMatch == TRUE)
  14152. {
  14153. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  14154. for(int i = 0; compareData[i]; i++)
  14155. {
  14156. compareData[i] = tolower(compareData[i]);
  14157. }
  14158. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14159. isMatch = FALSE;
  14160. }
  14161. if(isMatch == TRUE)
  14162. {
  14163. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  14164. for(int i = 0; compareData[i]; i++)
  14165. {
  14166. compareData[i] = tolower(compareData[i]);
  14167. }
  14168. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14169. isMatch = FALSE;
  14170. }
  14171. if(isMatch == TRUE)
  14172. {
  14173. DEBUG_INFO("Deleting certCP...\n");
  14174. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14175. system(temp);
  14176. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14177. goto End;
  14178. }
  14179. }
  14180. }
  14181. End:
  14182. json_object_put(DeleteCertificate);
  14183. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14184. sendDeleteCertificateConfirmation(uuid);
  14185. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14186. return result;
  14187. }
  14188. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14189. {
  14190. mtrace();
  14191. int result = PASS;
  14192. json_object *ExtendedTriggerMessage;
  14193. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14194. ExtendedTriggerMessage = json_tokener_parse(payload);
  14195. if(!is_error(ExtendedTriggerMessage))
  14196. {
  14197. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14198. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14199. {
  14200. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14201. }
  14202. else
  14203. {
  14204. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14205. }
  14206. }
  14207. json_object_put(ExtendedTriggerMessage);
  14208. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14209. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14210. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14211. {
  14212. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14213. }
  14214. else
  14215. {
  14216. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14217. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14218. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14219. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14220. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14221. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14222. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14223. {
  14224. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14225. }
  14226. else
  14227. {
  14228. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14229. }
  14230. }
  14231. sendExtendedTriggerMessageConfirmation(uuid);
  14232. //==========================
  14233. // Trigger message
  14234. //==========================
  14235. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14236. {
  14237. //sendBootNotificationRequest();
  14238. server_sign = FALSE;
  14239. }
  14240. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14241. {
  14242. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14243. }
  14244. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14245. {
  14246. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14247. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14248. {
  14249. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14250. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14251. }
  14252. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14253. }
  14254. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14255. {
  14256. refreshStartTimer(&clientTime.Heartbeat);
  14257. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14258. }
  14259. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14260. {
  14261. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14262. {
  14263. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14264. }
  14265. else
  14266. {
  14267. for(int idx=0;idx< gunTotalNumber;idx++)
  14268. {
  14269. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14270. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14271. }
  14272. }
  14273. }
  14274. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14275. {
  14276. char cmdBuf[1024]={0};
  14277. sprintf(cmdBuf, "openssl req -newkey rsa:2048 -out %s -nodes -keyout %s -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=%s/OU=IT/CN=%s\" &", CSR_CP, PRIVATE_KEY_CP, ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14278. system(cmdBuf);
  14279. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14280. }
  14281. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14282. {
  14283. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14284. {
  14285. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14286. }
  14287. else
  14288. {
  14289. for(int idx=0;idx< gunTotalNumber;idx++)
  14290. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14291. }
  14292. }
  14293. return result;
  14294. }
  14295. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14296. {
  14297. mtrace();
  14298. int result = PASS;
  14299. json_object *GetInstalledCertificateIds;
  14300. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14301. GetInstalledCertificateIds = json_tokener_parse(payload);
  14302. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14303. if(!is_error(GetInstalledCertificateIds))
  14304. {
  14305. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14306. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14307. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14308. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  14309. // Check CentralSystemRootCertificate
  14310. if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL)
  14311. {
  14312. if(access(ROOTCA_CS,F_OK) != -1)
  14313. {
  14314. char parseData[512] = {0};
  14315. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14316. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14317. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  14318. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14319. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14320. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14321. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14322. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14323. }
  14324. else
  14325. {
  14326. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  14327. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14328. }
  14329. }
  14330. // Check ManufacturerRootCertificate
  14331. else if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL)
  14332. {
  14333. if(access(ROOTCA_MF,F_OK) != -1)
  14334. {
  14335. char parseData[512] = {0};
  14336. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14337. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14338. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  14339. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14340. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14341. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14342. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14343. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14344. }
  14345. else
  14346. {
  14347. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  14348. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14349. }
  14350. }
  14351. else
  14352. {
  14353. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14354. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14355. }
  14356. }
  14357. json_object_put(GetInstalledCertificateIds);
  14358. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14359. sendGetInstalledCertificateIdsConfirmation(uuid);
  14360. return result;
  14361. }
  14362. void* GetLogProcess(void* data)
  14363. {
  14364. pthread_detach(pthread_self());
  14365. mtrace();
  14366. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  14367. int port=0;
  14368. int isSuccess = FALSE;
  14369. char cmdBuf[2048];
  14370. struct tm *tmNow;
  14371. time_t CurrentTime;
  14372. struct tm tmStart;
  14373. struct tm tmStop;
  14374. CurrentTime = time(NULL);
  14375. tmNow=localtime(&CurrentTime);
  14376. uint16_t targetYear, targetMonth;
  14377. json_object *GetLog;
  14378. DEBUG_INFO("GetLogProcess...\n");
  14379. GetLog = json_tokener_parse(data);
  14380. if(!is_error(GetLog))
  14381. {
  14382. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14383. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14384. if(json_object_object_get(GetLog, "retries") != NULL)
  14385. {
  14386. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14387. }
  14388. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14389. {
  14390. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14391. }
  14392. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14393. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14394. {
  14395. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14396. }
  14397. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14398. {
  14399. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14400. }
  14401. }
  14402. json_object_put(GetLog);
  14403. // Pack log to compress file
  14404. if((sscanf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%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) &&
  14405. (sscanf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%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))
  14406. {
  14407. // Pack system log
  14408. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14409. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14410. targetYear = tmStart.tm_year;
  14411. targetMonth = tmStart.tm_mon;
  14412. do
  14413. {
  14414. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14415. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14416. if(targetMonth+1>=13)
  14417. {
  14418. targetYear += 1;
  14419. targetMonth = 1;
  14420. }
  14421. else
  14422. {
  14423. targetMonth += 1;
  14424. }
  14425. }while((targetYear < (tmNow->tm_year+1900)) ||
  14426. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14427. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14428. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14429. sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
  14430. system(cmdBuf);
  14431. // Pack charging & event log
  14432. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14433. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14434. targetYear = tmStart.tm_year;
  14435. targetMonth = tmStart.tm_mon;
  14436. do
  14437. {
  14438. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14439. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14440. if(targetMonth+1>=13)
  14441. {
  14442. targetYear += 1;
  14443. targetMonth = 1;
  14444. }
  14445. else
  14446. {
  14447. targetMonth += 1;
  14448. }
  14449. }while((targetYear < (tmNow->tm_year+1900)) ||
  14450. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14451. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14452. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14453. system(cmdBuf);
  14454. // Combine log file
  14455. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14456. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14457. }
  14458. else
  14459. {
  14460. system("exec /root/logPackTools 'log' 6");
  14461. }
  14462. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14463. system(cmdBuf);
  14464. checkUploadLog();
  14465. //****************location*******************/
  14466. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14467. {
  14468. DEBUG_INFO("location is <Empty>!\n");
  14469. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14470. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14471. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14472. goto end;
  14473. }
  14474. memset(protocol, 0, ARRAY_SIZE(protocol));
  14475. memset(user, 0, ARRAY_SIZE(user) );
  14476. memset(password, 0, ARRAY_SIZE(password));
  14477. memset(host, 0, ARRAY_SIZE(host));
  14478. memset(path, 0, ARRAY_SIZE(path));
  14479. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14480. memset(host1, 0, ARRAY_SIZE(host1));
  14481. memset(path1, 0, ARRAY_SIZE(path1));
  14482. /*location: ftp://user:password@host:port/path*/
  14483. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14484. if((access(fnamePlusPath,F_OK))!=-1)
  14485. {
  14486. DEBUG_INFO("fnamePlusPath exist.\n");
  14487. }
  14488. else
  14489. {
  14490. DEBUG_INFO("fnamePlusPath not exist!\n");
  14491. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14492. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14493. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14494. goto end;
  14495. }
  14496. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14497. {
  14498. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14499. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14500. protocol, host, &port, path);
  14501. strcpy(user,"anonymous");
  14502. strcpy(password,"");
  14503. }
  14504. else
  14505. {
  14506. //DEBUG_INFO("pch=%s\n", pch);
  14507. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14508. protocol, user, password, host, &port, path);
  14509. }
  14510. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14511. {
  14512. DEBUG_INFO("protocol is not ftp/http ! \n");
  14513. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14514. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14515. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14516. goto end;
  14517. }
  14518. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14519. {
  14520. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14521. sprintf(ftppath,"/%s", path);
  14522. do
  14523. {
  14524. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14525. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14526. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14527. sleep(3);
  14528. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14529. if(!isSuccess)
  14530. {
  14531. DEBUG_INFO("Diagnostics fail.\n");
  14532. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14533. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14534. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14535. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14536. }
  14537. else
  14538. {
  14539. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14540. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14541. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14542. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14543. }
  14544. ShmOCPP16Data->GetLog.retries--;
  14545. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14546. }
  14547. else
  14548. {
  14549. sscanf(host,"%[^/]%s",host1, path1);
  14550. if(strlen(path) > 0)
  14551. sprintf(ftppath,"/%s", path);
  14552. else
  14553. sprintf(ftppath,"/%s", path1);
  14554. int ftppathlen=strlen(ftppath);
  14555. int i=1;
  14556. char filenametemp[50];
  14557. while(i < ftppathlen)
  14558. {
  14559. int len=ftppathlen-i;
  14560. if(ftppath[len]== 47) // '/' ascll code: 47
  14561. {
  14562. DEBUG_INFO("find '/' all right\n");
  14563. break;
  14564. }
  14565. i=i+1;
  14566. }
  14567. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14568. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14569. filenametemp[i+1] = 0;
  14570. if(port == 0)
  14571. port = 21;
  14572. do
  14573. {
  14574. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14575. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14576. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14577. sleep(3);
  14578. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14579. if(!isSuccess)
  14580. {
  14581. DEBUG_INFO("Diagnostics fail.\n");
  14582. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14583. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14584. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14585. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14586. }
  14587. else
  14588. {
  14589. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14590. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14591. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14592. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14593. }
  14594. ShmOCPP16Data->GetLog.retries--;
  14595. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14596. }
  14597. end:
  14598. system("rm -f /mnt/*");
  14599. system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
  14600. sleep(5);
  14601. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14602. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14603. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14604. interLock.isGetDiagnosticGoing = 0;
  14605. pthread_exit(NULL);
  14606. }
  14607. int handleGetLogRequest(char *uuid, char *payload)
  14608. {
  14609. mtrace();
  14610. int result = PASS;
  14611. time_t CurrentTime;
  14612. struct tm *tm;
  14613. DEBUG_INFO("handleGetLogRequest...\n");
  14614. pthread_t th_Status;
  14615. CurrentTime = time(NULL);
  14616. tm = localtime(&CurrentTime);
  14617. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14618. sprintf((char*)ShmOCPP16Data->GetLog.Response_filename, "%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);
  14619. if(!interLock.isGetDiagnosticGoing)
  14620. {
  14621. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14622. interLock.isGetDiagnosticGoing = 1;
  14623. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14624. sleep(1);
  14625. }
  14626. else
  14627. {
  14628. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14629. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14630. }
  14631. sendGetLogConfirmation(uuid);
  14632. return result;
  14633. }
  14634. int handleInstallCertificateRequest(char *uuid, char *payload)
  14635. {
  14636. mtrace();
  14637. int result = PASS;
  14638. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14639. json_object *InstallCertificate;
  14640. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14641. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14642. InstallCertificate = json_tokener_parse(payload);
  14643. if(!is_error(InstallCertificate))
  14644. {
  14645. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14646. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14647. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14648. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14649. char temp[1024];
  14650. FILE *fp = fopen(tempCert, "w");
  14651. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14652. fclose(fp);
  14653. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14654. char strExpDate[30];
  14655. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14656. fp = popen(temp, "r");
  14657. if(fp)
  14658. {
  14659. while(fgets(temp, sizeof(temp), fp) != NULL)
  14660. {
  14661. if(strstr(temp, "notAfter=") != NULL)
  14662. {
  14663. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14664. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14665. break;
  14666. }
  14667. }
  14668. }
  14669. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14670. struct tm tmExpDate;
  14671. struct timeb tbExpDate;
  14672. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14673. tbExpDate.time = mktime(&tmExpDate);
  14674. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14675. {
  14676. DEBUG_INFO("The enddate is already expired...\n");
  14677. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14678. goto End;
  14679. }
  14680. // Verify certificate with rootCA
  14681. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14682. fp = popen(temp, "r");
  14683. if(fp)
  14684. {
  14685. while(fgets(temp, sizeof(temp), fp) != NULL)
  14686. {
  14687. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14688. {
  14689. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14690. break;
  14691. }
  14692. else
  14693. {
  14694. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14695. }
  14696. }
  14697. }
  14698. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14699. {
  14700. //=====================================================
  14701. // Verify if the certificate is valid or not. (OCSP?)
  14702. //=====================================================
  14703. /*
  14704. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14705. // Get ocsp url
  14706. char ocspUrl[512];
  14707. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14708. fp = popen(temp, "r");
  14709. if(fp)
  14710. {
  14711. while(fgets(temp, sizeof(temp), fp) != NULL)
  14712. {
  14713. if(strstr(temp, "://") != NULL)
  14714. {
  14715. strcpy(ocspUrl, temp);
  14716. break;
  14717. }
  14718. }
  14719. }
  14720. // Get certificate chain for issuer
  14721. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14722. *
  14723. // Execute OCSP
  14724. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14725. fp = popen(temp, "r");
  14726. if(fp)
  14727. {
  14728. while(fgets(temp, sizeof(temp), fp) != NULL)
  14729. {
  14730. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14731. {
  14732. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14733. break;
  14734. }
  14735. }
  14736. }
  14737. system("rm -f /Storage/OCPP/tempChain.pem");
  14738. pclose(fp);
  14739. */
  14740. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14741. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14742. {
  14743. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14744. goto End;
  14745. }
  14746. else
  14747. DEBUG_INFO("OCSP verifying...PASS.\n");
  14748. }
  14749. else
  14750. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14751. }
  14752. End:
  14753. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14754. {
  14755. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14756. {
  14757. if(access(ROOTCA_CS,F_OK) != -1)
  14758. {
  14759. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14760. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14761. rename(tempCert, ROOTCA_CS);
  14762. }
  14763. else
  14764. {
  14765. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14766. rename(tempCert, ROOTCA_CS);
  14767. }
  14768. }
  14769. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14770. {
  14771. if(access(ROOTCA_MF,F_OK) != -1)
  14772. {
  14773. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14774. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14775. rename(tempCert, ROOTCA_MF);
  14776. }
  14777. else
  14778. {
  14779. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14780. rename(tempCert, ROOTCA_MF);
  14781. }
  14782. }
  14783. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14784. }
  14785. sendInstallCertificateConfirmation(uuid);
  14786. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14787. {
  14788. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14789. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14790. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14791. }
  14792. json_object_put(InstallCertificate);
  14793. return result;
  14794. }
  14795. void *SignedUpdateFirmwareProcess(void *data)
  14796. {
  14797. pthread_detach(pthread_self());
  14798. mtrace();
  14799. char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
  14800. int port=0;
  14801. int isSuccess = 0;
  14802. char ftpbuf[2048];
  14803. char temp[2048];
  14804. char * pch;
  14805. char firmwareFileName[256];
  14806. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14807. json_object *SignedUpdateFirmware;
  14808. SignedUpdateFirmware = json_tokener_parse(data);
  14809. if(!is_error(SignedUpdateFirmware))
  14810. {
  14811. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14812. {
  14813. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14814. }
  14815. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14816. {
  14817. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14818. }
  14819. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14820. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14821. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14822. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14823. {
  14824. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14825. }
  14826. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14827. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14828. }
  14829. json_object_put(SignedUpdateFirmware);
  14830. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14831. memset(path, 0, ARRAY_SIZE(path));
  14832. // Wait retrieveData
  14833. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14834. {
  14835. do
  14836. {
  14837. sleep(1);
  14838. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14839. }
  14840. // Ready to download
  14841. system("rm -f /mnt/*");
  14842. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14843. {
  14844. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14845. sprintf(ftppath,"/%s", path);
  14846. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14847. DEBUG_INFO("protocol: %s\n",protocol);
  14848. DEBUG_INFO("host: %s\n",host);
  14849. DEBUG_INFO("path: %s\n",path);
  14850. DEBUG_INFO("ftppath: %s\n",ftppath);
  14851. int ftppathlen=strlen(ftppath);
  14852. int i=1;
  14853. while(i < ftppathlen)
  14854. {
  14855. int len=ftppathlen-i;
  14856. if(ftppath[len]== 47) // '/' ascll code: 47
  14857. {
  14858. DEBUG_INFO("compare '/' all right\n");
  14859. break;
  14860. }
  14861. i=i+1;
  14862. }
  14863. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14864. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14865. firmwareFileName[i+1] = 0;
  14866. do
  14867. {
  14868. sleep(1);
  14869. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14870. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14871. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14872. sleep(1);
  14873. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14874. if(!isSuccess)
  14875. {
  14876. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14877. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14878. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14879. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14880. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14881. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14882. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14883. }
  14884. else
  14885. {
  14886. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14887. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14888. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14889. }
  14890. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14891. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14892. }
  14893. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14894. {
  14895. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14896. memset(temp, 0, ARRAY_SIZE(temp));
  14897. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14898. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14899. int ftppathlen=strlen(ftpbuf);
  14900. int i=1;
  14901. while(i < ftppathlen)
  14902. {
  14903. int len=ftppathlen-i;
  14904. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14905. {
  14906. DEBUG_INFO(" compare '/' all right\n");
  14907. break;
  14908. }
  14909. i=i+1;
  14910. }
  14911. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14912. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14913. firmwareFileName[i+1] = 0;
  14914. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14915. pch=strchr(temp,'@');
  14916. if(pch==NULL)
  14917. {
  14918. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14919. protocol, host, &port, path);
  14920. strcpy(user,"anonymous");
  14921. strcpy(password,"");
  14922. }
  14923. else
  14924. {
  14925. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14926. protocol, user, host, &port, path);
  14927. }
  14928. sscanf(host,"%[^/]%s",host1, path1);
  14929. sprintf(ftppath,"%s:/%s", host,path);
  14930. if(port == 0)
  14931. {
  14932. port = 21;
  14933. }
  14934. do
  14935. {
  14936. sleep(1);
  14937. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14938. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14939. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14940. sleep(1);
  14941. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14942. if(!isSuccess)
  14943. {
  14944. sleep(1);
  14945. DEBUG_INFO("Update firmware request and download file fail.\n");
  14946. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14947. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14948. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14949. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14950. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14951. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14952. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14953. }
  14954. else
  14955. {
  14956. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14957. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14958. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14959. }
  14960. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14961. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14962. }
  14963. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14964. {
  14965. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14966. memset(temp, 0, ARRAY_SIZE(temp));
  14967. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14968. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14969. int ftppathlen=strlen(ftpbuf);
  14970. int i=1;
  14971. while(i < ftppathlen)
  14972. {
  14973. int len=ftppathlen-i;
  14974. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14975. {
  14976. DEBUG_INFO(" compare '/' all right\n");
  14977. break;
  14978. }
  14979. i=i+1;
  14980. }
  14981. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14982. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14983. firmwareFileName[i+1] = 0;
  14984. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14985. pch=strchr(temp,'@');
  14986. if(pch==NULL)
  14987. {
  14988. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14989. protocol, host, &port, path);
  14990. strcpy(user,"anonymous");
  14991. strcpy(password,"");
  14992. }
  14993. else
  14994. {
  14995. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14996. protocol, user, password, host, &port, path);
  14997. }
  14998. sscanf(host,"%[^/]%s",host1, path1);
  14999. sprintf(ftppath,"%s", path1);
  15000. //DEBUG_INFO("protocol =%s\n",protocol);
  15001. //DEBUG_INFO("user =%s\n",user);
  15002. //DEBUG_INFO("password =%s\n",password);
  15003. //DEBUG_INFO("host1 =%s\n",host1);
  15004. //DEBUG_INFO("port =%d\n",port);
  15005. //DEBUG_INFO("path1 =%s\n",path1);
  15006. //DEBUG_INFO("ftppath=%s\n",ftppath);
  15007. //ftpFile(host, user, password, port, ftppath, fname);
  15008. //download firmware pthred
  15009. if(port == 0)
  15010. {
  15011. port = 21;
  15012. }
  15013. do
  15014. {
  15015. sleep(1);
  15016. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15017. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15018. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15019. sleep(1);
  15020. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15021. if(!isSuccess)
  15022. {
  15023. //BulldogUtil.sleepMs(interval*1000);
  15024. DEBUG_INFO("Update firmware request and download file fail.\n");
  15025. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15026. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15027. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15028. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15029. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15030. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15031. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15032. }
  15033. else
  15034. {
  15035. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15036. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15037. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15038. }
  15039. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15040. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15041. }
  15042. else
  15043. {
  15044. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15045. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15046. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15047. sleep(1);
  15048. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15049. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15050. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15051. }
  15052. // Verify firmware image signature
  15053. struct stat st;
  15054. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15055. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15056. fclose(fp);
  15057. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15058. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15059. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15060. fclose(fp);
  15061. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15062. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15063. if(st.st_size == 0)
  15064. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15065. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15066. {
  15067. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15068. fp = popen(temp, "r");
  15069. if(fp)
  15070. {
  15071. while(fgets(temp, sizeof(temp), fp) != NULL)
  15072. {
  15073. if(strstr(temp, "Verified OK") != NULL)
  15074. {
  15075. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15076. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15077. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15078. }
  15079. else
  15080. {
  15081. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15082. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15083. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15084. sleep(1);
  15085. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15086. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15087. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15088. sleep(1);
  15089. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15090. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15091. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15092. }
  15093. break;
  15094. }
  15095. }
  15096. pclose(fp);
  15097. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15098. }
  15099. interLock.isUpdateFirmwareGoing = 0;
  15100. pthread_exit(NULL);
  15101. }
  15102. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15103. {
  15104. mtrace();
  15105. int result = PASS;
  15106. pthread_t t;
  15107. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15108. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15109. sendSignedUpdateFirmwareConfirmation(uuid);
  15110. if(!interLock.isUpdateFirmwareGoing)
  15111. {
  15112. interLock.isUpdateFirmwareGoing = 1;
  15113. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15114. sleep(1);
  15115. }
  15116. else
  15117. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15118. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15119. return result;
  15120. }
  15121. int handleUnknownRequest(char *uuid, char *payload)
  15122. {
  15123. mtrace();
  15124. int result = PASS;
  15125. DEBUG_INFO("handleUnknownRequest...\n");
  15126. sendUnknownConfirmation(uuid);
  15127. return result;
  15128. }
  15129. //==========================================
  15130. // Handle server response routine
  15131. //==========================================
  15132. void handleAuthorizeResponse(char *payload, int gun_index)
  15133. {
  15134. mtrace();
  15135. char expiryDatestr[36]={0};
  15136. char parentIdTagstr[21]={0};
  15137. char statusstr[20]={0};
  15138. int expiryDateISNULL=FALSE;
  15139. int parentIdTagISNULL=FALSE;
  15140. DEBUG_INFO("handleAuthorizeResponse...\n");
  15141. json_object *Authorize;
  15142. Authorize = json_tokener_parse(payload);
  15143. if(!is_error(Authorize))
  15144. {
  15145. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15146. {
  15147. // Required data
  15148. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15149. // Optional data
  15150. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15151. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15152. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15153. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15154. }
  15155. }
  15156. json_object_put(Authorize);
  15157. if(expiryDateISNULL == FALSE)
  15158. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15159. if(parentIdTagISNULL == FALSE)
  15160. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15161. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15162. //Update idTag information to authorization cache if supproted
  15163. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15164. {
  15165. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15166. }
  15167. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15168. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15169. authorizeRetryTimes = 0;
  15170. }
  15171. void handleBootNotificationResponse(char *payload, int gun_index)
  15172. {
  15173. mtrace();
  15174. char statusStr[12]={0};
  15175. char currentTimeStr[30]={0};
  15176. int intervalInt = 0;
  15177. DEBUG_INFO("handleBootNotificationResponse...\n");
  15178. json_object *BootNotification;
  15179. BootNotification = json_tokener_parse(payload);
  15180. if(!is_error(BootNotification))
  15181. {
  15182. // Required data
  15183. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15184. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15185. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15186. }
  15187. json_object_put(BootNotification);
  15188. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15189. BootNotificationInterval = intervalInt;
  15190. //write back to ShmOCPP16Data->BootNotification
  15191. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15192. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15193. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15194. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15195. {
  15196. BootNotificationInterval = 0;
  15197. if((intervalInt == 0) || (intervalInt >= 10))
  15198. {
  15199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15200. HeartBeatWaitTime = intervalInt;
  15201. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15202. }
  15203. server_sign = TRUE;
  15204. server_pending =FALSE;
  15205. }
  15206. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15207. {
  15208. server_pending = TRUE;
  15209. }
  15210. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15211. srand(time(NULL));
  15212. refreshStartTimer(&clientTime.Heartbeat);
  15213. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15214. SetOcppConnStatus(TRUE);
  15215. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15216. }
  15217. void handleDataTransferResponse(char *payload, int gun_index)
  15218. {
  15219. json_object *DataTransfer = json_tokener_parse(payload);
  15220. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15221. if(!is_error(DataTransfer))
  15222. {
  15223. // Required data
  15224. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15225. // Optional data
  15226. if(json_object_object_get(DataTransfer, "data") != NULL)
  15227. {
  15228. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15229. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15230. if(!is_error(Data))
  15231. {
  15232. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15233. {
  15234. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15235. {
  15236. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15237. }
  15238. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15239. {
  15240. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15241. {
  15242. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status")));
  15243. }
  15244. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15245. {
  15246. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime")));
  15247. }
  15248. }
  15249. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15250. }
  15251. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15252. {
  15253. if(json_object_object_get(Data, "status") != NULL)
  15254. {
  15255. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15256. }
  15257. if(json_object_object_get(Data, "exiResponse") != NULL)
  15258. {
  15259. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15260. }
  15261. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15262. }
  15263. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15264. {
  15265. if(json_object_object_get(Data, "status") != NULL)
  15266. {
  15267. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15268. }
  15269. if(json_object_object_get(Data, "ocspResult") != NULL)
  15270. {
  15271. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15272. }
  15273. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15274. }
  15275. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15276. {
  15277. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15278. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15279. }
  15280. else
  15281. {
  15282. if(json_object_object_get(Data, "msgId") != NULL)
  15283. {
  15284. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15285. {
  15286. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  15287. }
  15288. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15289. {
  15290. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15291. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15292. }
  15293. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyFeeAct") != NULL)
  15294. {
  15295. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15296. {
  15297. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15298. if(json_object_object_get(Data, "occupancySN") != NULL)
  15299. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancySN, "%s", json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15300. if(json_object_object_get(Data, "startTime") != NULL)
  15301. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_startTime, "%s", json_object_get_string(json_object_object_get(Data, "startTime")));
  15302. if(json_object_object_get(Data, "duration") != NULL)
  15303. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_duration = json_object_get_int(json_object_object_get(Data, "duration"));
  15304. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15305. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancyFee = json_object_get_double(json_object_object_get(Data, "occupancyFee"));
  15306. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].OccupancyFeeActReq = 0;
  15307. }
  15308. else
  15309. {
  15310. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15311. {
  15312. if(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq)
  15313. {
  15314. strcpy((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].response_status, "Rejected");
  15315. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq = 0;
  15316. }
  15317. }
  15318. }
  15319. }
  15320. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15321. {
  15322. if(json_object_object_get(Data, "occupancySN") != NULL)
  15323. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15324. }
  15325. }
  15326. }
  15327. }
  15328. json_object_put(Data);
  15329. }
  15330. }
  15331. json_object_put(DataTransfer);
  15332. }
  15333. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15334. {
  15335. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15336. //struct json_object *obj;
  15337. // obj = json_tokener_parse(payload);
  15338. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15339. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15340. //No fields are defined.
  15341. }
  15342. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15343. {
  15344. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15345. //struct json_object *obj;
  15346. // obj = json_tokener_parse(payload);
  15347. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15348. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15349. //No fields are defined.
  15350. }
  15351. void handleHeartbeatResponse(char *payload, int gun_index)
  15352. {
  15353. mtrace();
  15354. DEBUG_INFO("handleHeartbeatResponse...\n");
  15355. json_object *Heartbeat;
  15356. Heartbeat = json_tokener_parse(payload);
  15357. if(!is_error(Heartbeat))
  15358. {
  15359. // Required data
  15360. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15361. }
  15362. json_object_put(Heartbeat);
  15363. if(FirstHeartBeat == 0)
  15364. {
  15365. FirstHeartBeat = 1;
  15366. DEBUG_INFO("FirstHeartBeat \n");
  15367. }
  15368. HeartBeatWithNOResponse = 0;
  15369. refreshStartTimer(&clientTime.Heartbeat);
  15370. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15371. }
  15372. void handleMeterValuesResponse(char *payload, int gun_index)
  15373. {
  15374. mtrace();
  15375. DEBUG_INFO("handleMeterValuesResponse...\n");
  15376. isQueueSendable = 1;
  15377. }
  15378. void handleStartTransactionResponse(char *payload, int gun_index)
  15379. {
  15380. mtrace();
  15381. //int transactionIdInt = 0;
  15382. FILE *outfile;
  15383. char data[100]={0};
  15384. DEBUG_INFO("handleStartTransactionResponse...\n");
  15385. json_object *StartTransaction;
  15386. StartTransaction = json_tokener_parse(payload);
  15387. if(!is_error(StartTransaction))
  15388. {
  15389. // Required data
  15390. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15391. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15392. // Optional data
  15393. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15394. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15395. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15396. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15397. }
  15398. json_object_put(StartTransaction);
  15399. OCPP_updatePeriodEnergy(gun_index);
  15400. //-----------Start : write to the Queue TransactionId file -----------------//
  15401. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15402. {}
  15403. else
  15404. {
  15405. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15406. if(log == NULL)
  15407. {
  15408. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15409. return ;
  15410. }
  15411. else
  15412. {
  15413. fclose(log);
  15414. }
  15415. }
  15416. // open file for writing
  15417. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15418. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15419. {
  15420. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15421. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15422. fputs(data, outfile);
  15423. fclose (outfile);
  15424. DEBUG_INFO("Update QueueTransactionId done...\n");
  15425. }
  15426. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15427. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15428. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15429. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15430. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15431. isQueueSendable = 1;
  15432. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15433. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15434. }
  15435. void handleStatusNotificationResponse(char *payload, int gun_index)
  15436. {
  15437. mtrace();
  15438. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15439. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15440. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15441. if(gun_index != 99)
  15442. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15443. }
  15444. void handleStopTransactionnResponse(char *payload, int gun_index)
  15445. {
  15446. mtrace();
  15447. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15448. json_object *StopTransaction;
  15449. StopTransaction = json_tokener_parse(payload);
  15450. if(!is_error(StopTransaction))
  15451. {
  15452. // Optional data
  15453. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15454. {
  15455. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15456. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15457. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15458. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15460. }
  15461. }
  15462. json_object_put(StopTransaction);
  15463. isQueueSendable = 1;
  15464. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15465. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15466. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15467. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15468. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15469. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15470. }
  15471. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15472. {
  15473. mtrace();
  15474. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15475. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15476. }
  15477. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15478. {
  15479. mtrace();
  15480. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15481. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15482. }
  15483. void handleSignCertificateResponse(char *payload, int gun_index)
  15484. {
  15485. mtrace();
  15486. DEBUG_INFO("handleSignCertificateResponse...\n");
  15487. json_object *SignCertificate;
  15488. SignCertificate = json_tokener_parse(payload);
  15489. if(!is_error(SignCertificate))
  15490. {
  15491. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15492. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15493. }
  15494. json_object_put(SignCertificate);
  15495. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15496. }
  15497. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15498. {
  15499. mtrace();
  15500. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15501. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15502. }
  15503. //==========================================
  15504. // Handle Error routine
  15505. //==========================================
  15506. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15507. {
  15508. mtrace();
  15509. #ifdef SystemLogMessage
  15510. DEBUG_INFO("errorCode: %s\n", errorCode);
  15511. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15512. DEBUG_INFO("errorDetails: %s\n", payload);
  15513. #endif
  15514. }
  15515. //===============================================
  15516. // Common routine
  15517. //===============================================
  15518. int initialConfigurationTable(void)
  15519. {
  15520. //clock_t start_t, end_t, total_t;
  15521. FILE *fp;
  15522. FILE *outfile;
  15523. char str[512]={0};
  15524. int confVersion = 26;
  15525. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15526. //start_t = clock();
  15527. //printf("Starting of the program, start_t = %ld\n", start_t);
  15528. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15529. // Check configuration file size is correct
  15530. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15531. {
  15532. struct stat st;
  15533. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15534. if(st.st_size < 3100)
  15535. {
  15536. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15537. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15538. }
  15539. }
  15540. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15541. {
  15542. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15543. if(outfile == NULL)
  15544. {
  15545. DEBUG_INFO("Error opening file\n");
  15546. return FALSE;
  15547. }
  15548. /*Core Profile*/
  15549. //AllowOfflineTxForUnknownId
  15550. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15554. //AuthorizationCacheEnabled
  15555. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15559. //AuthorizeRemoteTxRequests
  15560. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15564. //BlinkRepeat
  15565. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15569. //ClockAlignedDataInterval
  15570. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15574. //ConnectionTimeOut
  15575. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15577. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15579. else
  15580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15582. //GetConfigurationMaxKeys
  15583. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15587. // HeartbeatInterval
  15588. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15592. // LightIntensity
  15593. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15597. // LocalAuthorizeOffline
  15598. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15602. // LocalPreAuthorize
  15603. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15607. // MaxEnergyOnInvalidId
  15608. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15612. // MeterValuesAlignedData
  15613. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15615. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  15617. else
  15618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15620. // MeterValuesAlignedDataMaxLength
  15621. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15623. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15625. else
  15626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15628. // MeterValuesSampledData
  15629. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  15633. else
  15634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15636. // MeterValuesSampledDataMaxLength
  15637. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15641. else
  15642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15644. // MeterValueSampleInterval
  15645. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15649. // MinimumStatusDuration
  15650. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15653. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15655. // NumberOfConnectors
  15656. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15659. {
  15660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15661. }
  15662. else
  15663. {
  15664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15665. }
  15666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15667. // ResetRetries
  15668. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15672. // ConnectorPhaseRotation
  15673. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15677. // ConnectorPhaseRotationMaxLength
  15678. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15682. // StopTransactionOnEVSideDisconnect
  15683. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15687. // StopTransactionOnInvalidId
  15688. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15692. // StopTxnAlignedData
  15693. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15697. // StopTxnAlignedDataMaxLength
  15698. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15700. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15701. {
  15702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 8);
  15703. }
  15704. else
  15705. {
  15706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 10);
  15707. }
  15708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15709. // StopTxnSampledData
  15710. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "" );
  15713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15714. // StopTxnSampledDataMaxLength
  15715. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15718. {
  15719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 8);
  15720. }
  15721. else
  15722. {
  15723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 10);
  15724. }
  15725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15726. // SupportedFeatureProfiles
  15727. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15731. // SupportedFeatureProfilesMaxLength
  15732. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15736. // TransactionMessageAttempts
  15737. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15740. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15742. // TransactionMessageRetryInterval
  15743. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15746. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15748. // UnlockConnectorOnEVSideDisconnect
  15749. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15753. // WebSocketPingInterval
  15754. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15758. // QueueOffLineMeterValues
  15759. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15763. // AuthorizationKey
  15764. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15768. // SecurityProfile
  15769. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15773. // DefaultPrice
  15774. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15778. // CustomDisplayCostAndPrice
  15779. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15783. // CustomIdleFeeAfterStop
  15784. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15788. // TimeOffset
  15789. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15793. // NextTimeOffsetTransitionDateTime
  15794. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15798. // TimeOffsetNextTransition
  15799. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15803. // SystemUptimeSec
  15804. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15808. // FreeVend
  15809. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15813. // FreeVendIdtag
  15814. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15818. // OcppServer
  15819. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15821. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15823. // MaintainServer
  15824. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15826. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15828. // StatusNotificationPeriodically
  15829. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15833. // StatusNotificationInterval
  15834. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15838. // PreAuthAmount
  15839. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15843. // isEnableLocalPowerSharing
  15844. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15848. // PowerSharingServerIP
  15849. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15851. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15853. // EVCCID_PREFIX
  15854. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15858. // OffLineMaxChargingPower
  15859. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15863. // Configuration Version
  15864. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15868. // Charging profile refresh interval
  15869. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15873. // CpoName
  15874. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15878. // Ocpp Software certificated version
  15879. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15883. // Check certificate of download link
  15884. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  15885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  15886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "FALSE");
  15887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  15888. // RFID endian type
  15889. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = 1;
  15890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemName, "RfidEndianType");
  15891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE");
  15892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","RfidEndianType", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData);
  15893. // Authorization timeout
  15894. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = 1;
  15895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemName, "AuthorizeTimeout");
  15896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "15");
  15897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeTimeout", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  15898. // Enable AC charger CCS function
  15899. ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemAccessibility = 1;
  15900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemName, "EnableAcCcs");
  15901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData, "FALSE");
  15902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EnableAcCcs", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData);
  15903. //* Local Auth List Management Profile*/
  15904. #if 0
  15905. //For OCTT Test Case
  15906. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15909. #endif
  15910. #if 1
  15911. //LocalAuthListEnabled
  15912. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15916. #endif
  15917. //LocalAuthListMaxLength
  15918. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15922. //SendLocalListMaxLength
  15923. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15927. //ReserveConnectorZeroSupported
  15928. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15932. //* Smart Charging Profile */
  15933. //ChargeProfileMaxStackLevel
  15934. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15938. // ChargingScheduleAllowedChargingRateUnit
  15939. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15943. // ChargingScheduleMaxPeriods
  15944. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15948. // ConnectorSwitch3to1PhaseSupported
  15949. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15953. // MaxChargingProfilesInstalled
  15954. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15958. fclose(outfile);
  15959. }
  15960. else
  15961. {
  15962. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15963. char keystr[60]={0};
  15964. char readonlystr[10]={0};
  15965. char valuestr[256]={0};
  15966. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15967. if(fp == NULL) {
  15968. DEBUG_INFO("Error opening file");
  15969. return FALSE;
  15970. }
  15971. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15972. {
  15973. //DEBUG_INFO("Get Configuration \n");
  15974. if(strlen(str) > 0)
  15975. {
  15976. json_object *OCPPConfiguration;
  15977. OCPPConfiguration = json_tokener_parse(str);
  15978. if(json_object_object_get(OCPPConfiguration, "key") != NULL)
  15979. strcpy(keystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"key")));
  15980. if(json_object_object_get(OCPPConfiguration, "readonly") != NULL)
  15981. strcpy(readonlystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"readonly")));
  15982. if(json_object_object_get(OCPPConfiguration, "value") != NULL)
  15983. strcpy(valuestr, json_object_get_string(json_object_object_get(OCPPConfiguration,"value")));
  15984. json_object_put(OCPPConfiguration);
  15985. // DEBUG_INFO("keystr=%s\n",keystr);
  15986. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  15987. // DEBUG_INFO("valuestr=%s\n",valuestr);
  15988. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  15989. {
  15990. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15991. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  15993. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15994. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15995. }
  15996. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  15997. {
  15998. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15999. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  16001. }
  16002. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  16003. {
  16004. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  16006. }
  16007. if(strcmp(keystr, "BlinkRepeat") == 0)
  16008. {
  16009. //Charger.BlinkRepeat = Integer.parseInt(value);
  16010. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  16012. }
  16013. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  16014. {
  16015. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  16017. }
  16018. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  16019. {
  16020. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  16022. }
  16023. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16024. {
  16025. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16027. }
  16028. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16029. {
  16030. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16032. HeartBeatWaitTime = atoi(valuestr);
  16033. }
  16034. if(strcmp(keystr, "LightIntensity") == 0)
  16035. {
  16036. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16038. }
  16039. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16040. {
  16041. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16043. }
  16044. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16045. {
  16046. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16048. }
  16049. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16050. {
  16051. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16053. }
  16054. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16055. {
  16056. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16058. }
  16059. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16060. {
  16061. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16063. }
  16064. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16065. {
  16066. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16068. }
  16069. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16070. {
  16071. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16073. }
  16074. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16075. {
  16076. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16077. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16078. }
  16079. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16080. {
  16081. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16083. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16084. }
  16085. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16086. {
  16087. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16089. }
  16090. if(strcmp(keystr, "ResetRetries") == 0)
  16091. {
  16092. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16094. }
  16095. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16096. {
  16097. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16099. }
  16100. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16101. {
  16102. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16104. }
  16105. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16106. {
  16107. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16109. }
  16110. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16111. {
  16112. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16114. }
  16115. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16116. {
  16117. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16119. }
  16120. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16121. {
  16122. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16124. }
  16125. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16126. {
  16127. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16129. }
  16130. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16131. {
  16132. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16134. }
  16135. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16136. {
  16137. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16139. }
  16140. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16141. {
  16142. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16144. }
  16145. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16146. {
  16147. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16149. TransactionMessageAttemptsValue = atoi(valuestr);
  16150. }
  16151. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16152. {
  16153. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16155. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16156. }
  16157. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16158. {
  16159. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16161. }
  16162. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16163. {
  16164. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16166. }
  16167. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16168. {
  16169. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16171. }
  16172. if(strcmp(keystr, "AuthorizationKey") == 0)
  16173. {
  16174. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16175. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16177. }
  16178. if(strcmp(keystr, "SecurityProfile") == 0)
  16179. {
  16180. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16182. }
  16183. if(strcmp(keystr, "DefaultPrice") == 0)
  16184. {
  16185. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16187. }
  16188. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16189. {
  16190. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16192. }
  16193. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16194. {
  16195. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16197. }
  16198. if(strcmp(keystr, "TimeOffset") == 0)
  16199. {
  16200. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16202. }
  16203. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16204. {
  16205. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16207. }
  16208. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16209. {
  16210. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16212. }
  16213. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16214. {
  16215. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16217. }
  16218. if(strcmp(keystr, "FreeVend") == 0)
  16219. {
  16220. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16222. }
  16223. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16224. {
  16225. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16227. }
  16228. if(strcmp(keystr, "OcppServer") == 0)
  16229. {
  16230. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16231. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16232. }
  16233. if(strcmp(keystr, "MaintainServer") == 0)
  16234. {
  16235. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16236. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16237. }
  16238. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16239. {
  16240. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16242. }
  16243. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16244. {
  16245. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16247. }
  16248. if(strcmp(keystr, "PreAuthAmount") == 0)
  16249. {
  16250. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16252. }
  16253. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16254. {
  16255. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16257. }
  16258. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16259. {
  16260. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16261. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16262. }
  16263. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16264. {
  16265. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16267. }
  16268. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16269. {
  16270. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16272. }
  16273. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16274. {
  16275. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16277. }
  16278. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16279. {
  16280. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16282. }
  16283. if(strcmp(keystr, "CpoName") == 0)
  16284. {
  16285. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16287. }
  16288. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16289. {
  16290. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16292. }
  16293. if(strcmp(keystr, "AuthDownloadlinkCertificate") == 0)
  16294. {
  16295. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", valuestr);
  16297. }
  16298. if(strcmp(keystr, "RfidEndianType") == 0)
  16299. {
  16300. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE");
  16302. }
  16303. if(strcmp(keystr, "AuthorizeTimeout") == 0)
  16304. {
  16305. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "%s", valuestr);
  16307. }
  16308. if(strcmp(keystr, "EnableAcCcs") == 0)
  16309. {
  16310. ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData, "%s", valuestr);
  16312. }
  16313. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16314. {
  16315. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16317. }
  16318. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16319. {
  16320. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16322. }
  16323. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16324. {
  16325. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16327. }
  16328. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16329. {
  16330. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16332. }
  16333. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16334. {
  16335. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16337. }
  16338. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16339. {
  16340. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16342. }
  16343. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16344. {
  16345. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16347. }
  16348. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16349. {
  16350. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16352. }
  16353. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16354. {
  16355. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16357. }
  16358. }
  16359. }
  16360. fclose(fp);
  16361. }
  16362. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16363. {
  16364. return PASS;
  16365. }
  16366. else
  16367. {
  16368. return FAIL;
  16369. }
  16370. }
  16371. void StoreConfigurationTable(void)
  16372. {
  16373. FILE *outfile;
  16374. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16375. if(outfile == NULL)
  16376. {
  16377. DEBUG_INFO("Error opening file");
  16378. return ;
  16379. }
  16380. /*Core Profile*/
  16381. //AllowOfflineTxForUnknownId
  16382. /*
  16383. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16384. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16387. */
  16388. //DEBUG_INFO("data=%s\n",data);
  16389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16390. //AuthorizationCacheEnabled
  16391. /*
  16392. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16395. */
  16396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16397. //AuthorizeRemoteTxRequests
  16398. /*
  16399. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16402. */
  16403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16404. //BlinkRepeat
  16405. /*
  16406. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16409. */
  16410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16411. //ClockAlignedDataInterval
  16412. /*
  16413. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16416. */
  16417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16418. //ConnectionTimeOut
  16419. /*
  16420. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16423. */
  16424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16425. //GetConfigurationMaxKeys
  16426. /*
  16427. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16430. */
  16431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16432. // HeartbeatInterval
  16433. /*
  16434. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16437. */
  16438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16439. // LightIntensity
  16440. /*
  16441. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16444. */
  16445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16446. // LocalAuthorizeOffline
  16447. /*
  16448. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16451. */
  16452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16453. // LocalPreAuthorize
  16454. /*
  16455. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16458. */
  16459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16460. // MaxEnergyOnInvalidId
  16461. /*
  16462. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16465. */
  16466. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16468. // MeterValuesAlignedData
  16469. /*
  16470. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16473. */
  16474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16475. // MeterValuesAlignedDataMaxLength
  16476. /*
  16477. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16480. */
  16481. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16482. // MeterValuesSampledData
  16483. /*
  16484. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16487. */
  16488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16489. // MeterValuesSampledDataMaxLength
  16490. /*
  16491. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16494. */
  16495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16496. // MeterValueSampleInterval
  16497. /*
  16498. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16501. */
  16502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16503. // MinimumStatusDuration
  16504. /*
  16505. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16508. */
  16509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16510. // NumberOfConnectors
  16511. /*
  16512. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16514. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16515. {
  16516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16517. }
  16518. else
  16519. {
  16520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16521. }
  16522. */
  16523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16524. // ResetRetries
  16525. /*
  16526. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16529. */
  16530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16531. // ConnectorPhaseRotation
  16532. /*
  16533. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16536. */
  16537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16538. // ConnectorPhaseRotationMaxLength
  16539. /*
  16540. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16543. */
  16544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16545. // StopTransactionOnEVSideDisconnect
  16546. /*
  16547. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16550. */
  16551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16552. // StopTransactionOnInvalidId
  16553. /*
  16554. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16557. */
  16558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16559. // StopTxnAlignedData
  16560. /*
  16561. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16564. */
  16565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16566. // StopTxnAlignedDataMaxLength
  16567. /*
  16568. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16571. */
  16572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16573. // StopTxnSampledData
  16574. /*
  16575. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16578. */
  16579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16580. // StopTxnSampledDataMaxLength
  16581. /*
  16582. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16585. */
  16586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16587. // SupportedFeatureProfiles
  16588. /*
  16589. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16592. */
  16593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16594. // SupportedFeatureProfilesMaxLength
  16595. /*
  16596. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16599. */
  16600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16601. // TransactionMessageAttempts
  16602. /*
  16603. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16606. */
  16607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16608. // TransactionMessageRetryInterval
  16609. /*
  16610. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16613. */
  16614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16615. // UnlockConnectorOnEVSideDisconnect
  16616. /*
  16617. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16620. */
  16621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16622. // WebSocketPingInterval
  16623. /*
  16624. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16627. */
  16628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16629. // QueueOffLineMeterValues
  16630. /*
  16631. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16634. */
  16635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16636. // AuthorizationKey
  16637. /*
  16638. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16641. */
  16642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16643. // SecurityProfile
  16644. /*
  16645. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16648. */
  16649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16650. // DefaultPrice
  16651. /*
  16652. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16655. */
  16656. json_object *tmp;
  16657. tmp = json_tokener_parse((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16658. if(!is_error(tmp))
  16659. {
  16660. DEBUG_INFO("JSON string type\n");
  16661. json_object *target = json_object_new_object();
  16662. json_object_object_add(target, "key", json_object_new_string("DefaultPrice"));
  16663. json_object_object_add(target, "readonly", (ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility?json_object_new_boolean(0):json_object_new_boolean(1)));
  16664. json_object_object_add(target, "value", json_object_new_string((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData));
  16665. fprintf(outfile, "%s\n", json_object_to_json_string_ext(target, JSON_C_TO_STRING_PLAIN));
  16666. json_object_put(target);
  16667. }
  16668. else
  16669. {
  16670. DEBUG_INFO("Normal string type\n");
  16671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16672. }
  16673. json_object_put(tmp);
  16674. // CustomDisplayCostAndPrice
  16675. /*
  16676. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16679. */
  16680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16681. // CustomIdleFeeAfterStop
  16682. /*
  16683. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16686. */
  16687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16688. // TimeOffset
  16689. /*
  16690. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16693. */
  16694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16695. // NextTimeOffsetTransitionDateTime
  16696. /*
  16697. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16700. */
  16701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16702. // TimeOffsetNextTransition
  16703. /*
  16704. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16707. */
  16708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16709. // SystemUptimeSec
  16710. /*
  16711. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16714. */
  16715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16716. // FreeVend
  16717. /*
  16718. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16721. */
  16722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16723. // FreeVendIdtag
  16724. /*
  16725. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16728. */
  16729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16730. // OcppServer
  16731. /*
  16732. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16735. */
  16736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16737. // MaintainServer
  16738. /*
  16739. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16742. */
  16743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16744. // StatusNotificationPeriodically
  16745. /*
  16746. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16749. */
  16750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16751. // StatusNotificationInterval
  16752. /*
  16753. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16756. */
  16757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16758. // PreAuthAmount
  16759. /*
  16760. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16763. */
  16764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16765. // isEnableLocalPowerSharing
  16766. /*
  16767. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16770. */
  16771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16772. // PowerSharingServerIP
  16773. /*
  16774. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16777. */
  16778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16779. // EVCCID_PREFIX
  16780. /*
  16781. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16784. */
  16785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16786. // OffLineMaxChargingPower
  16787. /*
  16788. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16791. */
  16792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16793. // ConfigurationVersion
  16794. /*
  16795. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16798. */
  16799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16800. // CharingProfileRefreshInterval
  16801. /*
  16802. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16805. */
  16806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16807. // CpoName
  16808. /*
  16809. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16812. */
  16813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16814. // OcppSoftwareVersion
  16815. /*
  16816. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16819. */
  16820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16821. // AuthDownloadlinkCertificate
  16822. /*
  16823. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  16824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  16825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE" );
  16826. */
  16827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  16828. // RfidEndianType
  16829. /*
  16830. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = 1;
  16831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemName, "RfidEndianType");
  16832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "BIG" );
  16833. */
  16834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","RfidEndianType", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData);
  16835. // AuthorizeTimeout
  16836. /*
  16837. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = 1;
  16838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemName, "AuthorizeTimeout");
  16839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "60" );
  16840. */
  16841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeTimeout", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  16842. // EnableAcCcs
  16843. /*
  16844. ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemAccessibility = 1;
  16845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemName, "EnableAcCcs");
  16846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData, "TRUE" );
  16847. */
  16848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EnableAcCcs", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData);
  16849. //* Local Auth List Management Profile*/
  16850. //LocalAuthListEnabled
  16851. /*
  16852. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16855. */
  16856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16857. //LocalAuthListMaxLength
  16858. /*
  16859. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16862. */
  16863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16864. //SendLocalListMaxLength
  16865. /*
  16866. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16869. */
  16870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16871. //ReserveConnectorZeroSupported
  16872. /*
  16873. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16876. */
  16877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16878. //* Smart Charging Profile */
  16879. //ChargeProfileMaxStackLevel
  16880. /*
  16881. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16884. */
  16885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16886. // ChargingScheduleAllowedChargingRateUnit
  16887. /*
  16888. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16891. */
  16892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16893. // ChargingScheduleMaxPeriods
  16894. /*
  16895. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16898. */
  16899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16900. // ConnectorSwitch3to1PhaseSupported
  16901. /*
  16902. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16905. */
  16906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16907. // MaxChargingProfilesInstalled
  16908. /*
  16909. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16912. */
  16913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16914. fclose(outfile);
  16915. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16916. }
  16917. void getKeyValue(char *keyReq)
  16918. {
  16919. int isEmpty = FALSE;
  16920. int isKnowKey = FALSE;
  16921. DEBUG_INFO("keyReq = %s\n", keyReq);
  16922. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16923. isEmpty = TRUE;
  16924. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16925. {
  16926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16929. {
  16930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16931. }
  16932. else
  16933. {
  16934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16935. }
  16936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16937. isKnowKey = TRUE;
  16938. }
  16939. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16940. {
  16941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16944. {
  16945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16946. }
  16947. else
  16948. {
  16949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16950. }
  16951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16952. isKnowKey = TRUE;
  16953. }
  16954. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16955. {
  16956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16959. {
  16960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16961. }
  16962. else
  16963. {
  16964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16965. }
  16966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16967. isKnowKey = TRUE;
  16968. }
  16969. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16970. {
  16971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16974. {
  16975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16976. }
  16977. else
  16978. {
  16979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16980. }
  16981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16982. isKnowKey = TRUE;
  16983. }
  16984. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16985. {
  16986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16989. {
  16990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16991. }
  16992. else
  16993. {
  16994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16995. }
  16996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16997. isKnowKey = TRUE;
  16998. }
  16999. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  17000. {
  17001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  17002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  17003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  17004. {
  17005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  17006. }
  17007. else
  17008. {
  17009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  17010. }
  17011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  17012. isKnowKey = TRUE;
  17013. }
  17014. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  17015. {
  17016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  17017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  17018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  17019. {
  17020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  17021. }
  17022. else
  17023. {
  17024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  17025. }
  17026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  17027. isKnowKey = TRUE;
  17028. }
  17029. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  17030. {
  17031. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  17032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  17033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17034. {
  17035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  17036. }
  17037. else
  17038. {
  17039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  17040. }
  17041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  17042. isKnowKey = TRUE;
  17043. }
  17044. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  17045. {
  17046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  17047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  17048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17049. {
  17050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  17051. }
  17052. else
  17053. {
  17054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  17055. }
  17056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  17057. isKnowKey = TRUE;
  17058. }
  17059. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  17060. {
  17061. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  17063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17064. {
  17065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  17066. }
  17067. else
  17068. {
  17069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  17070. }
  17071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  17072. isKnowKey = TRUE;
  17073. }
  17074. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  17075. {
  17076. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  17077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  17078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17079. {
  17080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  17081. }
  17082. else
  17083. {
  17084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17085. }
  17086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17087. isKnowKey = TRUE;
  17088. }
  17089. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17090. {
  17091. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17094. {
  17095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17096. }
  17097. else
  17098. {
  17099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17100. }
  17101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17102. isKnowKey = TRUE;
  17103. }
  17104. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17105. {
  17106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17109. {
  17110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17111. }
  17112. else
  17113. {
  17114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17115. }
  17116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17117. isKnowKey = TRUE;
  17118. }
  17119. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17120. {
  17121. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17124. {
  17125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17126. }
  17127. else
  17128. {
  17129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17130. }
  17131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17132. isKnowKey = TRUE;
  17133. }
  17134. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17135. {
  17136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17139. {
  17140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17141. }
  17142. else
  17143. {
  17144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17145. }
  17146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17147. isKnowKey = TRUE;
  17148. }
  17149. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17150. {
  17151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17154. {
  17155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17156. }
  17157. else
  17158. {
  17159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17160. }
  17161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17162. isKnowKey = TRUE;
  17163. }
  17164. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17165. {
  17166. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17169. {
  17170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17171. }
  17172. else
  17173. {
  17174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17175. }
  17176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17177. isKnowKey = TRUE;
  17178. }
  17179. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17180. {
  17181. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17184. {
  17185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17186. }
  17187. else
  17188. {
  17189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17190. }
  17191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17192. isKnowKey = TRUE;
  17193. }
  17194. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17195. {
  17196. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17199. {
  17200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17201. }
  17202. else
  17203. {
  17204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17205. }
  17206. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17208. isKnowKey = TRUE;
  17209. }
  17210. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17211. {
  17212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17215. {
  17216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17217. }
  17218. else
  17219. {
  17220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17221. }
  17222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17223. isKnowKey = TRUE;
  17224. }
  17225. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17226. {
  17227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17230. {
  17231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17232. }
  17233. else
  17234. {
  17235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17236. }
  17237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17238. isKnowKey = TRUE;
  17239. }
  17240. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17241. {
  17242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17245. {
  17246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17247. }
  17248. else
  17249. {
  17250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17251. }
  17252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17253. isKnowKey = TRUE;
  17254. }
  17255. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17256. {
  17257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17260. {
  17261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17262. }
  17263. else
  17264. {
  17265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17266. }
  17267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17268. isKnowKey = TRUE;
  17269. }
  17270. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17271. {
  17272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17275. {
  17276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17277. }
  17278. else
  17279. {
  17280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17281. }
  17282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17283. isKnowKey = TRUE;
  17284. }
  17285. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17286. {
  17287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17290. {
  17291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17292. }
  17293. else
  17294. {
  17295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17296. }
  17297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17298. isKnowKey = TRUE;
  17299. }
  17300. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17301. {
  17302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17305. {
  17306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17307. }
  17308. else
  17309. {
  17310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17311. }
  17312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17313. isKnowKey = TRUE;
  17314. }
  17315. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17316. {
  17317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17320. {
  17321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17322. }
  17323. else
  17324. {
  17325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17326. }
  17327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17328. isKnowKey = TRUE;
  17329. }
  17330. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17331. {
  17332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17335. {
  17336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17337. }
  17338. else
  17339. {
  17340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17341. }
  17342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17343. isKnowKey = TRUE;
  17344. }
  17345. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17346. {
  17347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17350. {
  17351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17352. }
  17353. else
  17354. {
  17355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17356. }
  17357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17358. isKnowKey = TRUE;
  17359. }
  17360. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17361. {
  17362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17365. {
  17366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17367. }
  17368. else
  17369. {
  17370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17371. }
  17372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17373. isKnowKey = TRUE;
  17374. }
  17375. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17376. {
  17377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17380. {
  17381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17382. }
  17383. else
  17384. {
  17385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17386. }
  17387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17388. isKnowKey = TRUE;
  17389. }
  17390. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17391. {
  17392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17395. {
  17396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17397. }
  17398. else
  17399. {
  17400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17401. }
  17402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17403. isKnowKey = TRUE;
  17404. }
  17405. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17406. {
  17407. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17410. {
  17411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17412. }
  17413. else
  17414. {
  17415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17416. }
  17417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17418. isKnowKey = TRUE;
  17419. }
  17420. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17421. {
  17422. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17425. {
  17426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17427. }
  17428. else
  17429. {
  17430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17431. }
  17432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17433. isKnowKey = TRUE;
  17434. }
  17435. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17436. {
  17437. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17440. {
  17441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17442. }
  17443. else
  17444. {
  17445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17446. }
  17447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17448. isKnowKey = TRUE;
  17449. }
  17450. /*
  17451. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17452. {
  17453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17456. {
  17457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17458. }
  17459. else
  17460. {
  17461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17462. }
  17463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17464. isKnowKey = TRUE;
  17465. }*/
  17466. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17467. {
  17468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17471. {
  17472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17473. }
  17474. else
  17475. {
  17476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17477. }
  17478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17479. isKnowKey = TRUE;
  17480. }
  17481. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17482. {
  17483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17486. {
  17487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17488. }
  17489. else
  17490. {
  17491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17492. }
  17493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17494. isKnowKey = TRUE;
  17495. }
  17496. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17497. {
  17498. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17501. {
  17502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17503. }
  17504. else
  17505. {
  17506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17507. }
  17508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17509. isKnowKey = TRUE;
  17510. }
  17511. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17512. {
  17513. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17516. {
  17517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17518. }
  17519. else
  17520. {
  17521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17522. }
  17523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17524. isKnowKey = TRUE;
  17525. }
  17526. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17527. {
  17528. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17531. {
  17532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17533. }
  17534. else
  17535. {
  17536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17537. }
  17538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17539. isKnowKey = TRUE;
  17540. }
  17541. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17542. {
  17543. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17546. {
  17547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17548. }
  17549. else
  17550. {
  17551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17552. }
  17553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17554. isKnowKey = TRUE;
  17555. }
  17556. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17557. {
  17558. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17561. {
  17562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17563. }
  17564. else
  17565. {
  17566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17567. }
  17568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17569. isKnowKey = TRUE;
  17570. }
  17571. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17572. {
  17573. struct sysinfo s_info;
  17574. int error = sysinfo(&s_info);
  17575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17578. {
  17579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17580. }
  17581. else
  17582. {
  17583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17584. }
  17585. if(error != 0)
  17586. {
  17587. DEBUG_WARN("System uptime get error: %d\n", error);
  17588. }
  17589. else
  17590. {
  17591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17592. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17593. }
  17594. isKnowKey = TRUE;
  17595. }
  17596. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17597. {
  17598. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17601. {
  17602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17603. }
  17604. else
  17605. {
  17606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17607. }
  17608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17609. isKnowKey = TRUE;
  17610. }
  17611. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17612. {
  17613. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17616. {
  17617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17618. }
  17619. else
  17620. {
  17621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17622. }
  17623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17624. isKnowKey = TRUE;
  17625. }
  17626. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17627. {
  17628. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17631. {
  17632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17633. }
  17634. else
  17635. {
  17636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17637. }
  17638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17639. isKnowKey = TRUE;
  17640. }
  17641. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17642. {
  17643. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17646. {
  17647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17648. }
  17649. else
  17650. {
  17651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17652. }
  17653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17654. isKnowKey = TRUE;
  17655. }
  17656. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17657. {
  17658. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17660. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17661. {
  17662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17663. }
  17664. else
  17665. {
  17666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17667. }
  17668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17669. isKnowKey = TRUE;
  17670. }
  17671. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17672. {
  17673. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17676. {
  17677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17678. }
  17679. else
  17680. {
  17681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17682. }
  17683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17684. isKnowKey = TRUE;
  17685. }
  17686. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17687. {
  17688. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17691. {
  17692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17693. }
  17694. else
  17695. {
  17696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17697. }
  17698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17699. isKnowKey = TRUE;
  17700. }
  17701. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17702. {
  17703. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17706. {
  17707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17708. }
  17709. else
  17710. {
  17711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17712. }
  17713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17714. isKnowKey = TRUE;
  17715. }
  17716. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17717. {
  17718. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17721. {
  17722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17723. }
  17724. else
  17725. {
  17726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17727. }
  17728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17729. isKnowKey = TRUE;
  17730. }
  17731. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17732. {
  17733. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17736. {
  17737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17738. }
  17739. else
  17740. {
  17741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17742. }
  17743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17744. isKnowKey = TRUE;
  17745. }
  17746. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17747. {
  17748. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17750. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17751. {
  17752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17753. }
  17754. else
  17755. {
  17756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17757. }
  17758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17759. isKnowKey = TRUE;
  17760. }
  17761. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17762. {
  17763. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17766. {
  17767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17768. }
  17769. else
  17770. {
  17771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17772. }
  17773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17774. isKnowKey = TRUE;
  17775. }
  17776. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17777. {
  17778. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17780. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17781. {
  17782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17783. }
  17784. else
  17785. {
  17786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17787. }
  17788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17789. isKnowKey = TRUE;
  17790. }
  17791. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17792. {
  17793. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17796. {
  17797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17798. }
  17799. else
  17800. {
  17801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17802. }
  17803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17804. isKnowKey = TRUE;
  17805. }
  17806. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17807. {
  17808. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17810. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17811. {
  17812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17813. }
  17814. else
  17815. {
  17816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17817. }
  17818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17819. isKnowKey = TRUE;
  17820. }
  17821. if(isEmpty || strcmp(keyReq, "AuthDownloadlinkCertificate") == 0 )
  17822. {
  17823. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthDownloadlinkCertificate].Item, "AuthDownloadlinkCertificate");
  17824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Key, "AuthDownloadlinkCertificate");
  17825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  17826. {
  17827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "0"/*"FALSE"*/);
  17828. }
  17829. else
  17830. {
  17831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "1"/*"TRUE"*/);
  17832. }
  17833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData );
  17834. isKnowKey = TRUE;
  17835. }
  17836. if(isEmpty || strcmp(keyReq, "RfidEndianType") == 0 )
  17837. {
  17838. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_RfidEndianType].Item, "RfidEndianType");
  17839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].Key, "RfidEndianType");
  17840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility == 1)
  17841. {
  17842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].ReadOnly, "0"/*"FALSE"*/);
  17843. }
  17844. else
  17845. {
  17846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].ReadOnly, "1"/*"TRUE"*/);
  17847. }
  17848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].Value, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE");
  17849. isKnowKey = TRUE;
  17850. }
  17851. if(isEmpty || strcmp(keyReq, "AuthorizeTimeout") == 0 )
  17852. {
  17853. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeTimeout].Item, "AuthorizeTimeout");
  17854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].Key, "AuthorizeTimeout");
  17855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility == 1)
  17856. {
  17857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].ReadOnly, "0"/*"FALSE"*/);
  17858. }
  17859. else
  17860. {
  17861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].ReadOnly, "1"/*"TRUE"*/);
  17862. }
  17863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  17864. isKnowKey = TRUE;
  17865. }
  17866. if(isEmpty || strcmp(keyReq, "EnableAcCcs") == 0 )
  17867. {
  17868. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EnableAcCcs].Item, "EnableAcCcs");
  17869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EnableAcCcs].Key, "EnableAcCcs");
  17870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemAccessibility == 1)
  17871. {
  17872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EnableAcCcs].ReadOnly, "0"/*"FALSE"*/);
  17873. }
  17874. else
  17875. {
  17876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EnableAcCcs].ReadOnly, "1"/*"TRUE"*/);
  17877. }
  17878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EnableAcCcs].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData );
  17879. isKnowKey = TRUE;
  17880. }
  17881. #if 1
  17882. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17883. {
  17884. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17886. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17887. {
  17888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17889. }
  17890. else
  17891. {
  17892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17893. }
  17894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17895. isKnowKey = TRUE;
  17896. }
  17897. #endif
  17898. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17899. {
  17900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17902. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17903. {
  17904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17905. }
  17906. else
  17907. {
  17908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17909. }
  17910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17911. isKnowKey = TRUE;
  17912. }
  17913. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17914. {
  17915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17917. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17918. {
  17919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17920. }
  17921. else
  17922. {
  17923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17924. }
  17925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17926. isKnowKey = TRUE;
  17927. }
  17928. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17929. {
  17930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17932. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17933. {
  17934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17935. }
  17936. else
  17937. {
  17938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17939. }
  17940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17941. isKnowKey = TRUE;
  17942. }
  17943. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17944. {
  17945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17947. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17948. {
  17949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17950. }
  17951. else
  17952. {
  17953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17954. }
  17955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17956. isKnowKey = TRUE;
  17957. }
  17958. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17959. {
  17960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17962. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17963. {
  17964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17965. }
  17966. else
  17967. {
  17968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17969. }
  17970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17971. isKnowKey = TRUE;
  17972. }
  17973. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17974. {
  17975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17977. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17978. {
  17979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17980. }
  17981. else
  17982. {
  17983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17984. }
  17985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17986. isKnowKey = TRUE;
  17987. }
  17988. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17989. {
  17990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17992. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17993. {
  17994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17995. }
  17996. else
  17997. {
  17998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17999. }
  18000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  18001. isKnowKey = TRUE;
  18002. }
  18003. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  18004. {
  18005. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  18006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  18007. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  18008. {
  18009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  18010. }
  18011. else
  18012. {
  18013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  18014. }
  18015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  18016. isKnowKey = TRUE;
  18017. }
  18018. //=========================================================
  18019. if(!isEmpty && !isKnowKey)
  18020. {
  18021. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  18022. strcpy(unknownkey[UnknownKeynum], keyReq);
  18023. UnknownKeynum = UnknownKeynum + 1;
  18024. }
  18025. }
  18026. void processUnkownKey(void)
  18027. {
  18028. DEBUG_INFO("processUnkownKey...\n");
  18029. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  18030. for(int index=0; index < UnknownKeynum; index++)
  18031. {
  18032. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  18033. {
  18034. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  18035. }
  18036. }
  18037. }
  18038. int setKeyValue(char *key, char *value)
  18039. {
  18040. int isSuccess = NotSupported;
  18041. int check_ascii=0;
  18042. char str[501]={0};
  18043. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  18044. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  18045. {
  18046. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  18047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  18048. {
  18049. strcpy(str, (const char*)value);
  18050. for(int i = 0; str[i]; i++){
  18051. str[i] = tolower(str[i]);
  18052. }
  18053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18054. isSuccess = ConfigurationStatus_Accepted;
  18055. }
  18056. else
  18057. {
  18058. isSuccess = ConfigurationStatus_Rejected;
  18059. }
  18060. }
  18061. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  18062. {
  18063. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  18064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  18065. {
  18066. strcpy(str, (const char*)value);
  18067. for(int i = 0; str[i]; i++){
  18068. str[i] = tolower(str[i]);
  18069. }
  18070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18071. isSuccess = ConfigurationStatus_Accepted;
  18072. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  18073. }
  18074. else
  18075. {
  18076. isSuccess = ConfigurationStatus_Rejected;
  18077. }
  18078. }
  18079. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  18080. {
  18081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  18082. {
  18083. strcpy(str, (const char*)value);
  18084. for(int i = 0; str[i]; i++)
  18085. {
  18086. str[i] = tolower(str[i]);
  18087. }
  18088. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  18089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18090. isSuccess = ConfigurationStatus_Accepted;
  18091. }
  18092. else
  18093. {
  18094. isSuccess = ConfigurationStatus_Rejected;
  18095. }
  18096. }
  18097. if(strcmp(key, "BlinkRepeat") == 0)
  18098. {
  18099. //Charger.BlinkRepeat = Integer.parseInt(value);
  18100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  18101. {
  18102. check_ascii = value[0];
  18103. if( (check_ascii < 48) || (check_ascii > 57) )
  18104. {
  18105. isSuccess = ConfigurationStatus_Rejected;
  18106. }
  18107. else
  18108. {
  18109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  18110. isSuccess = ConfigurationStatus_Accepted;
  18111. }
  18112. }
  18113. else
  18114. {
  18115. isSuccess = ConfigurationStatus_Rejected;
  18116. }
  18117. }
  18118. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  18119. {
  18120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  18121. {
  18122. check_ascii = value[0];
  18123. if( (check_ascii < 48) || (check_ascii > 57) )
  18124. {
  18125. isSuccess = ConfigurationStatus_Rejected;
  18126. }
  18127. else
  18128. {
  18129. if((atoi(value) == 0) || (atoi(value) >= 5))
  18130. {
  18131. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  18132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  18133. isSuccess = ConfigurationStatus_Accepted;
  18134. }
  18135. else
  18136. isSuccess = ConfigurationStatus_Rejected;
  18137. }
  18138. }
  18139. else
  18140. {
  18141. isSuccess = ConfigurationStatus_Rejected;
  18142. }
  18143. }
  18144. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18145. {
  18146. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18147. {
  18148. check_ascii = value[0];
  18149. if( (check_ascii < 48) || (check_ascii > 57) )
  18150. {
  18151. isSuccess = ConfigurationStatus_Rejected;
  18152. }
  18153. else
  18154. {
  18155. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18157. isSuccess = ConfigurationStatus_Accepted;
  18158. }
  18159. }
  18160. else
  18161. {
  18162. isSuccess = ConfigurationStatus_Rejected;
  18163. }
  18164. }
  18165. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18166. {
  18167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18168. {
  18169. check_ascii = value[0];
  18170. if( (check_ascii < 48) || (check_ascii > 57) )
  18171. {
  18172. isSuccess = ConfigurationStatus_Rejected;
  18173. }
  18174. else
  18175. {
  18176. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18178. isSuccess = ConfigurationStatus_Accepted;
  18179. }
  18180. }
  18181. else
  18182. {
  18183. isSuccess = ConfigurationStatus_Rejected;
  18184. }
  18185. }
  18186. if(strcmp(key, "HeartbeatInterval") == 0)
  18187. {
  18188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18189. {
  18190. check_ascii = value[0];
  18191. if( (check_ascii < 48) || (check_ascii > 57) )
  18192. {
  18193. isSuccess = ConfigurationStatus_Rejected;
  18194. }
  18195. else
  18196. {
  18197. if((atoi(value) == 0) || (atoi(value) >= 10))
  18198. {
  18199. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18201. HeartBeatWaitTime = atoi(value);
  18202. isSuccess = ConfigurationStatus_Accepted;
  18203. }
  18204. else
  18205. {
  18206. isSuccess = ConfigurationStatus_Rejected;
  18207. }
  18208. }
  18209. }
  18210. else
  18211. {
  18212. isSuccess = ConfigurationStatus_Rejected;
  18213. }
  18214. }
  18215. if(strcmp(key, "LightIntensity") == 0)
  18216. {
  18217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18218. {
  18219. check_ascii = value[0];
  18220. if( (check_ascii < 48) || (check_ascii > 57) )
  18221. {
  18222. isSuccess = ConfigurationStatus_Rejected;
  18223. }
  18224. else
  18225. {
  18226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18227. isSuccess = ConfigurationStatus_Accepted;
  18228. }
  18229. }
  18230. else
  18231. {
  18232. isSuccess = ConfigurationStatus_Rejected;
  18233. }
  18234. }
  18235. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18236. {
  18237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18238. {
  18239. strcpy(str, (const char*)value);
  18240. for(int i = 0; str[i]; i++)
  18241. {
  18242. str[i] = tolower(str[i]);
  18243. }
  18244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18245. isSuccess = ConfigurationStatus_Accepted;
  18246. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18247. }
  18248. else
  18249. {
  18250. isSuccess = ConfigurationStatus_Rejected;
  18251. }
  18252. }
  18253. if(strcmp(key, "LocalPreAuthorize") == 0)
  18254. {
  18255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18256. {
  18257. strcpy(str, (const char*)value);
  18258. for(int i = 0; str[i]; i++)
  18259. {
  18260. str[i] = tolower(str[i]);
  18261. }
  18262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18263. isSuccess = ConfigurationStatus_Accepted;
  18264. }
  18265. else
  18266. {
  18267. isSuccess = ConfigurationStatus_Rejected;
  18268. }
  18269. }
  18270. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18271. {
  18272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18273. {
  18274. check_ascii = value[0];
  18275. if( (check_ascii < 48) || (check_ascii > 57) )
  18276. {
  18277. isSuccess = ConfigurationStatus_Rejected;
  18278. }
  18279. else
  18280. {
  18281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18282. isSuccess = ConfigurationStatus_Accepted;
  18283. }
  18284. }
  18285. else
  18286. {
  18287. isSuccess = ConfigurationStatus_Rejected;
  18288. }
  18289. }
  18290. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18291. {
  18292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18293. {
  18294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18295. isSuccess = ConfigurationStatus_Accepted;
  18296. }
  18297. else
  18298. {
  18299. isSuccess = ConfigurationStatus_Rejected;
  18300. }
  18301. }
  18302. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18303. {
  18304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18305. {
  18306. check_ascii = value[0];
  18307. if( (check_ascii < 48) || (check_ascii > 57) )
  18308. {
  18309. isSuccess = ConfigurationStatus_Rejected;
  18310. }
  18311. else
  18312. {
  18313. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18315. isSuccess = ConfigurationStatus_Accepted;
  18316. }
  18317. }
  18318. else
  18319. {
  18320. isSuccess = ConfigurationStatus_Rejected;
  18321. }
  18322. }
  18323. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18324. {
  18325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18326. {
  18327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18328. isSuccess = ConfigurationStatus_Accepted;
  18329. }
  18330. else
  18331. {
  18332. isSuccess = ConfigurationStatus_Rejected;
  18333. }
  18334. }
  18335. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18336. {
  18337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18338. {
  18339. check_ascii = value[0];
  18340. if( (check_ascii < 48) || (check_ascii > 57) )
  18341. {
  18342. isSuccess = ConfigurationStatus_Rejected;
  18343. }
  18344. else
  18345. {
  18346. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18348. isSuccess = ConfigurationStatus_Accepted;
  18349. }
  18350. }
  18351. else
  18352. {
  18353. isSuccess = ConfigurationStatus_Rejected;
  18354. }
  18355. }
  18356. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18357. {
  18358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18359. {
  18360. check_ascii = value[0];
  18361. if( (check_ascii < 48) || (check_ascii > 57) )
  18362. {
  18363. isSuccess = ConfigurationStatus_Rejected;
  18364. }
  18365. else
  18366. {
  18367. if((atoi(value) == 0) || (atoi(value) >= 3))
  18368. {
  18369. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18371. isSuccess = ConfigurationStatus_Accepted;
  18372. }
  18373. else
  18374. {
  18375. isSuccess = ConfigurationStatus_Rejected;
  18376. }
  18377. }
  18378. }
  18379. else
  18380. {
  18381. isSuccess = ConfigurationStatus_Rejected;
  18382. }
  18383. }
  18384. if(strcmp(key, "MinimumStatusDuration") == 0)
  18385. {
  18386. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18387. {
  18388. check_ascii = value[0];
  18389. if( (check_ascii < 48) || (check_ascii > 57) )
  18390. {
  18391. isSuccess = ConfigurationStatus_Rejected;
  18392. }
  18393. else
  18394. {
  18395. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18396. {
  18397. isSuccess = ConfigurationStatus_Rejected;
  18398. }
  18399. else
  18400. {
  18401. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18403. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18404. isSuccess = ConfigurationStatus_Accepted;
  18405. }
  18406. }
  18407. }
  18408. else
  18409. {
  18410. isSuccess = ConfigurationStatus_Rejected;
  18411. }
  18412. }
  18413. if(strcmp(key, "NumberOfConnectors") == 0)
  18414. {
  18415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18416. {
  18417. check_ascii = value[0];
  18418. if( (check_ascii < 48) || (check_ascii > 57) )
  18419. {
  18420. isSuccess = ConfigurationStatus_Rejected;
  18421. }
  18422. else
  18423. {
  18424. //Charger.ResetRetries = Integer.parseInt(value);
  18425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18426. isSuccess = ConfigurationStatus_Accepted;
  18427. }
  18428. }
  18429. else
  18430. {
  18431. isSuccess = ConfigurationStatus_Rejected;
  18432. }
  18433. }
  18434. if(strcmp(key, "ResetRetries") == 0)
  18435. {
  18436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18437. {
  18438. check_ascii = value[0];
  18439. if( (check_ascii < 48) || (check_ascii > 57) )
  18440. {
  18441. isSuccess = ConfigurationStatus_Rejected;
  18442. }
  18443. else
  18444. {
  18445. //Charger.ResetRetries = Integer.parseInt(value);
  18446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18447. isSuccess = ConfigurationStatus_Accepted;
  18448. }
  18449. }
  18450. else
  18451. {
  18452. isSuccess = ConfigurationStatus_Rejected;
  18453. }
  18454. }
  18455. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18456. {
  18457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18458. {
  18459. strcpy(str, (const char*)value);
  18460. for(int i = 0; str[i]; i++)
  18461. {
  18462. str[i] = tolower(str[i]);
  18463. }
  18464. if(strcmp(str, "notapplicable")== 0)
  18465. {
  18466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18467. isSuccess = ConfigurationStatus_Accepted;
  18468. }
  18469. else if(strcmp(str, "unknown")== 0)
  18470. {
  18471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18472. isSuccess = ConfigurationStatus_Accepted;
  18473. }
  18474. else if(strcmp(str, "rst")== 0)
  18475. {
  18476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18477. isSuccess = ConfigurationStatus_Accepted;
  18478. }
  18479. else if(strcmp(str, "rts")== 0)
  18480. {
  18481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18482. isSuccess = ConfigurationStatus_Accepted;
  18483. }
  18484. else if(strcmp(str, "srt")== 0)
  18485. {
  18486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18487. isSuccess = ConfigurationStatus_Accepted;
  18488. }
  18489. else if(strcmp(str, "str")== 0)
  18490. {
  18491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18492. isSuccess = ConfigurationStatus_Accepted;
  18493. }
  18494. else if(strcmp(str, "trs")== 0)
  18495. {
  18496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18497. isSuccess = ConfigurationStatus_Accepted;
  18498. }
  18499. else if(strcmp(str, "tsr")== 0)
  18500. {
  18501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18502. isSuccess = ConfigurationStatus_Accepted;
  18503. }
  18504. else
  18505. {
  18506. isSuccess = ConfigurationStatus_Rejected;
  18507. }
  18508. }
  18509. else
  18510. {
  18511. isSuccess = ConfigurationStatus_Rejected;
  18512. }
  18513. }
  18514. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18515. {
  18516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18517. {
  18518. check_ascii = value[0];
  18519. if( (check_ascii < 48) || (check_ascii > 57) )
  18520. {
  18521. isSuccess = ConfigurationStatus_Rejected;
  18522. }
  18523. else
  18524. {
  18525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18526. isSuccess = ConfigurationStatus_Accepted;
  18527. }
  18528. }
  18529. else
  18530. {
  18531. isSuccess = ConfigurationStatus_Rejected;
  18532. }
  18533. }
  18534. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18535. {
  18536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18537. {
  18538. strcpy(str, (const char*)value);
  18539. for(int i = 0; str[i]; i++)
  18540. {
  18541. str[i] = tolower(str[i]);
  18542. }
  18543. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18545. isSuccess = ConfigurationStatus_Accepted;
  18546. }
  18547. else
  18548. {
  18549. isSuccess = ConfigurationStatus_Rejected;
  18550. }
  18551. }
  18552. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18553. {
  18554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18555. {
  18556. strcpy(str, (const char*)value);
  18557. for(int i = 0; str[i]; i++)
  18558. {
  18559. str[i] = tolower(str[i]);
  18560. }
  18561. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18563. isSuccess = ConfigurationStatus_Accepted;
  18564. }
  18565. else
  18566. {
  18567. isSuccess = ConfigurationStatus_Rejected;
  18568. }
  18569. }
  18570. if(strcmp(key, "StopTxnAlignedData") == 0)
  18571. {
  18572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18573. {
  18574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18575. isSuccess = ConfigurationStatus_Accepted;
  18576. }
  18577. else
  18578. {
  18579. isSuccess = ConfigurationStatus_Rejected;
  18580. }
  18581. }
  18582. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18583. {
  18584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18585. {
  18586. check_ascii = value[0];
  18587. if( (check_ascii < 48) || (check_ascii > 57) )
  18588. {
  18589. isSuccess = ConfigurationStatus_Rejected;
  18590. }
  18591. else
  18592. {
  18593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18594. isSuccess = ConfigurationStatus_Accepted;
  18595. }
  18596. }
  18597. else
  18598. {
  18599. isSuccess = ConfigurationStatus_Rejected;
  18600. }
  18601. }
  18602. if(strcmp(key, "StopTxnSampledData") == 0)
  18603. {
  18604. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18605. {
  18606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18607. isSuccess = ConfigurationStatus_Accepted;
  18608. }
  18609. else
  18610. {
  18611. isSuccess = ConfigurationStatus_Rejected;
  18612. }
  18613. }
  18614. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18615. {
  18616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18617. {
  18618. check_ascii = value[0];
  18619. if( (check_ascii < 48) || (check_ascii > 57) )
  18620. {
  18621. isSuccess = ConfigurationStatus_Rejected;
  18622. }
  18623. else
  18624. {
  18625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18626. isSuccess = ConfigurationStatus_Accepted;
  18627. }
  18628. }
  18629. else
  18630. {
  18631. isSuccess = ConfigurationStatus_Rejected;
  18632. }
  18633. }
  18634. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18635. {
  18636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18637. {
  18638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18639. isSuccess = ConfigurationStatus_Accepted;
  18640. }
  18641. else
  18642. {
  18643. isSuccess = ConfigurationStatus_Rejected;
  18644. }
  18645. }
  18646. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18647. {
  18648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18649. {
  18650. check_ascii = value[0];
  18651. if( (check_ascii < 48) || (check_ascii > 57) )
  18652. {
  18653. isSuccess = ConfigurationStatus_Rejected;
  18654. }
  18655. else
  18656. {
  18657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18658. isSuccess = ConfigurationStatus_Accepted;
  18659. }
  18660. }
  18661. else
  18662. {
  18663. isSuccess = ConfigurationStatus_Rejected;
  18664. }
  18665. }
  18666. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18667. {
  18668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18669. {
  18670. check_ascii = value[0];
  18671. if( (check_ascii < 48) || (check_ascii > 57) )
  18672. {
  18673. isSuccess = ConfigurationStatus_Rejected;
  18674. }
  18675. else
  18676. {
  18677. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18679. TransactionMessageAttemptsValue = atoi(value);
  18680. isSuccess = ConfigurationStatus_Accepted;
  18681. }
  18682. }
  18683. else
  18684. {
  18685. isSuccess = ConfigurationStatus_Rejected;
  18686. }
  18687. }
  18688. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18689. {
  18690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18691. {
  18692. check_ascii = value[0];
  18693. if( (check_ascii < 48) || (check_ascii > 57) )
  18694. {
  18695. isSuccess = ConfigurationStatus_Rejected;
  18696. }
  18697. else
  18698. {
  18699. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18701. TransactionMessageRetryIntervalValue = atoi(value);
  18702. isSuccess = ConfigurationStatus_Accepted;
  18703. }
  18704. }
  18705. else
  18706. {
  18707. isSuccess = ConfigurationStatus_Rejected;
  18708. }
  18709. }
  18710. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18711. {
  18712. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18713. {
  18714. strcpy(str, (const char*)value);
  18715. for(int i = 0; str[i]; i++)
  18716. {
  18717. str[i] = tolower(str[i]);
  18718. }
  18719. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18721. isSuccess = ConfigurationStatus_Accepted;
  18722. }
  18723. else
  18724. {
  18725. isSuccess = ConfigurationStatus_Rejected;
  18726. }
  18727. }
  18728. if(strcmp(key, "WebSocketPingInterval") == 0)
  18729. {
  18730. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18731. {
  18732. check_ascii = value[0];
  18733. if( (check_ascii < 48) || (check_ascii > 57) )
  18734. {
  18735. isSuccess = ConfigurationStatus_Rejected;
  18736. }
  18737. else
  18738. {
  18739. if((atoi(value) == 0) || (atoi(value) >= 10))
  18740. {
  18741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18742. isSuccess = ConfigurationStatus_Accepted;
  18743. }
  18744. else
  18745. isSuccess = ConfigurationStatus_Rejected;
  18746. }
  18747. }
  18748. else
  18749. {
  18750. isSuccess = ConfigurationStatus_Rejected;
  18751. }
  18752. }
  18753. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18754. {
  18755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18756. {
  18757. strcpy(str, (const char*)value);
  18758. for(int i = 0; str[i]; i++)
  18759. {
  18760. str[i] = tolower(str[i]);
  18761. }
  18762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18763. isSuccess = ConfigurationStatus_Accepted;
  18764. }
  18765. else
  18766. {
  18767. isSuccess = ConfigurationStatus_Rejected;
  18768. }
  18769. }
  18770. if(strcmp(key, "AuthorizationKey") == 0)
  18771. {
  18772. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18773. {
  18774. strcpy(str, (const char*)value);
  18775. int strlength = strlen(str);
  18776. char capture[3];
  18777. char stackItem = 0;
  18778. char password[21] = {0};
  18779. printf("String length: %d\n", strlength);
  18780. for(int idx=0; idx<(strlength/2); idx++)
  18781. {
  18782. capture[0] = str[(idx*2)];
  18783. capture[1] = str[(idx*2)+1];
  18784. capture[2] = 0;
  18785. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  18786. sprintf(password,"%s%c", password, stackItem);
  18787. }
  18788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  18789. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18790. isSuccess = ConfigurationStatus_Accepted;
  18791. }
  18792. else
  18793. {
  18794. isSuccess = ConfigurationStatus_Rejected;
  18795. }
  18796. }
  18797. if(strcmp(key, "SecurityProfile") == 0)
  18798. {
  18799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18800. {
  18801. check_ascii = value[0];
  18802. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18803. {
  18804. isSuccess = ConfigurationStatus_Rejected;
  18805. }
  18806. else if(check_ascii == 0x33)
  18807. {
  18808. isSuccess = NotSupported;
  18809. }
  18810. else
  18811. {
  18812. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18813. {
  18814. if(((check_ascii - 0x30) == 1) ||
  18815. ((check_ascii - 0x30) == 2) ||
  18816. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18817. {
  18818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18819. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18820. isSuccess = ConfigurationStatus_Accepted;
  18821. }
  18822. else
  18823. isSuccess = ConfigurationStatus_Rejected;
  18824. }
  18825. else
  18826. isSuccess = ConfigurationStatus_Rejected;
  18827. }
  18828. }
  18829. else
  18830. {
  18831. isSuccess = ConfigurationStatus_Rejected;
  18832. }
  18833. }
  18834. if(strcmp(key, "DefaultPrice") == 0)
  18835. {
  18836. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18837. {
  18838. strcpy(str, (const char*)value);
  18839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18840. isSuccess = ConfigurationStatus_Accepted;
  18841. }
  18842. else
  18843. {
  18844. isSuccess = ConfigurationStatus_Rejected;
  18845. }
  18846. }
  18847. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18848. {
  18849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18850. {
  18851. strcpy(str, (const char*)value);
  18852. for(int i = 0; str[i]; i++)
  18853. {
  18854. str[i] = tolower(str[i]);
  18855. }
  18856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18857. isSuccess = ConfigurationStatus_Accepted;
  18858. }
  18859. else
  18860. {
  18861. isSuccess = ConfigurationStatus_Rejected;
  18862. }
  18863. }
  18864. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18865. {
  18866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18867. {
  18868. strcpy(str, (const char*)value);
  18869. for(int i = 0; str[i]; i++)
  18870. {
  18871. str[i] = tolower(str[i]);
  18872. }
  18873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18874. isSuccess = ConfigurationStatus_Accepted;
  18875. }
  18876. else
  18877. {
  18878. isSuccess = ConfigurationStatus_Rejected;
  18879. }
  18880. }
  18881. if(strcmp(key, "TimeOffset") == 0)
  18882. {
  18883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18884. {
  18885. strcpy(str, (const char*)value);
  18886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18887. isSuccess = ConfigurationStatus_Accepted;
  18888. }
  18889. else
  18890. {
  18891. isSuccess = ConfigurationStatus_Rejected;
  18892. }
  18893. }
  18894. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18895. {
  18896. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18897. {
  18898. strcpy(str, (const char*)value);
  18899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18900. isSuccess = ConfigurationStatus_Accepted;
  18901. }
  18902. else
  18903. {
  18904. isSuccess = ConfigurationStatus_Rejected;
  18905. }
  18906. }
  18907. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18908. {
  18909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18910. {
  18911. strcpy(str, (const char*)value);
  18912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18913. isSuccess = ConfigurationStatus_Accepted;
  18914. }
  18915. else
  18916. {
  18917. isSuccess = ConfigurationStatus_Rejected;
  18918. }
  18919. }
  18920. if(strcmp(key, "SystemUptimeSec") == 0)
  18921. {
  18922. isSuccess = NotSupported;
  18923. }
  18924. if(strcmp(key, "FreeVend") == 0)
  18925. {
  18926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18927. {
  18928. strcpy(str, (const char*)value);
  18929. for(int i = 0; str[i]; i++)
  18930. {
  18931. str[i] = tolower(str[i]);
  18932. }
  18933. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18935. isSuccess = ConfigurationStatus_Accepted;
  18936. }
  18937. else
  18938. {
  18939. isSuccess = ConfigurationStatus_Rejected;
  18940. }
  18941. }
  18942. if(strcmp(key, "FreeVendIdtag") == 0)
  18943. {
  18944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18945. {
  18946. strcpy(str, (const char*)value);
  18947. if(strlen(str) <= 20)
  18948. {
  18949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18950. isSuccess = ConfigurationStatus_Accepted;
  18951. }
  18952. else
  18953. {
  18954. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18955. isSuccess = ConfigurationStatus_Rejected;
  18956. }
  18957. }
  18958. else
  18959. {
  18960. isSuccess = ConfigurationStatus_Rejected;
  18961. }
  18962. }
  18963. if(strcmp(key, "OcppServer") == 0)
  18964. {
  18965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18966. {
  18967. strcpy(str, (const char*)value);
  18968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18969. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18970. isSuccess = ConfigurationStatus_Accepted;
  18971. }
  18972. else
  18973. {
  18974. isSuccess = ConfigurationStatus_Rejected;
  18975. }
  18976. }
  18977. if(strcmp(key, "MaintainServer") == 0)
  18978. {
  18979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18980. {
  18981. strcpy(str, (const char*)value);
  18982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18983. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18984. isSuccess = ConfigurationStatus_Accepted;
  18985. }
  18986. else
  18987. {
  18988. isSuccess = ConfigurationStatus_Rejected;
  18989. }
  18990. }
  18991. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18992. {
  18993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18994. {
  18995. strcpy(str, (const char*)value);
  18996. for(int i = 0; str[i]; i++)
  18997. {
  18998. str[i] = tolower(str[i]);
  18999. }
  19000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  19001. isSuccess = ConfigurationStatus_Accepted;
  19002. }
  19003. else
  19004. {
  19005. isSuccess = ConfigurationStatus_Rejected;
  19006. }
  19007. }
  19008. if(strcmp(key, "StatusNotificationInterval") == 0)
  19009. {
  19010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  19011. {
  19012. check_ascii = value[0];
  19013. if( (check_ascii < 48) || (check_ascii > 57) )
  19014. {
  19015. isSuccess = ConfigurationStatus_Rejected;
  19016. }
  19017. else
  19018. {
  19019. if((atoi(value) == 0) || (atoi(value) >= 10))
  19020. {
  19021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  19022. isSuccess = ConfigurationStatus_Accepted;
  19023. }
  19024. else
  19025. isSuccess = ConfigurationStatus_Rejected;
  19026. }
  19027. }
  19028. else
  19029. {
  19030. isSuccess = ConfigurationStatus_Rejected;
  19031. }
  19032. }
  19033. if(strcmp(key, "PreAuthAmount") == 0)
  19034. {
  19035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  19036. {
  19037. check_ascii = value[0];
  19038. if( (check_ascii < 48) || (check_ascii > 57) )
  19039. {
  19040. isSuccess = ConfigurationStatus_Rejected;
  19041. }
  19042. else
  19043. {
  19044. if(atof(value) >= 0)
  19045. {
  19046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  19047. isSuccess = ConfigurationStatus_Accepted;
  19048. }
  19049. else
  19050. isSuccess = ConfigurationStatus_Rejected;
  19051. }
  19052. }
  19053. else
  19054. {
  19055. isSuccess = ConfigurationStatus_Rejected;
  19056. }
  19057. }
  19058. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  19059. {
  19060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  19061. {
  19062. check_ascii = value[0];
  19063. if( (check_ascii < 48) || (check_ascii > 57) )
  19064. {
  19065. isSuccess = ConfigurationStatus_Rejected;
  19066. }
  19067. else
  19068. {
  19069. if(atoi(value) >= 0)
  19070. {
  19071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  19072. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  19073. isSuccess = ConfigurationStatus_Accepted;
  19074. }
  19075. else
  19076. isSuccess = ConfigurationStatus_Rejected;
  19077. }
  19078. }
  19079. else
  19080. {
  19081. isSuccess = ConfigurationStatus_Rejected;
  19082. }
  19083. }
  19084. if(strcmp(key, "PowerSharingServerIP") == 0)
  19085. {
  19086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  19087. {
  19088. strcpy(str, (const char*)value);
  19089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  19090. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  19091. isSuccess = ConfigurationStatus_Accepted;
  19092. }
  19093. else
  19094. {
  19095. isSuccess = ConfigurationStatus_Rejected;
  19096. }
  19097. }
  19098. if(strcmp(key, "EVCCID_PREFIX") == 0)
  19099. {
  19100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  19101. {
  19102. strcpy(str, (const char*)value);
  19103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  19104. isSuccess = ConfigurationStatus_Accepted;
  19105. }
  19106. else
  19107. {
  19108. isSuccess = ConfigurationStatus_Rejected;
  19109. }
  19110. }
  19111. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  19112. {
  19113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  19114. {
  19115. if(atoi(value) > modelnameInfo.ratedPower)
  19116. {
  19117. isSuccess = ConfigurationStatus_Rejected;
  19118. }
  19119. else{
  19120. strcpy(str, (const char*)value);
  19121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  19122. isSuccess = ConfigurationStatus_Accepted;
  19123. }
  19124. }
  19125. else
  19126. {
  19127. isSuccess = ConfigurationStatus_Rejected;
  19128. }
  19129. }
  19130. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  19131. {
  19132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  19133. {
  19134. if((atoi(value) != 0) && (atoi(value) < 5))
  19135. {
  19136. isSuccess = ConfigurationStatus_Rejected;
  19137. }
  19138. else{
  19139. strcpy(str, (const char*)value);
  19140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  19141. isSuccess = ConfigurationStatus_Accepted;
  19142. }
  19143. }
  19144. else
  19145. {
  19146. isSuccess = ConfigurationStatus_Rejected;
  19147. }
  19148. }
  19149. if(strcmp(key, "CpoName") == 0)
  19150. {
  19151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19152. {
  19153. strcpy(str, (const char*)value);
  19154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19155. isSuccess = ConfigurationStatus_Accepted;
  19156. }
  19157. else
  19158. {
  19159. isSuccess = ConfigurationStatus_Rejected;
  19160. }
  19161. }
  19162. if(strcmp(key, "OcppSoftwareVersion") == 0)
  19163. {
  19164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  19165. {
  19166. strcpy(str, (const char*)value);
  19167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", str );
  19168. isSuccess = ConfigurationStatus_Accepted;
  19169. }
  19170. else
  19171. {
  19172. isSuccess = ConfigurationStatus_Rejected;
  19173. }
  19174. }
  19175. if(strcmp(key, "AuthDownloadlinkCertificate") == 0)
  19176. {
  19177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  19178. {
  19179. strcpy(str, (const char*)value);
  19180. for(int i = 0; str[i]; i++)
  19181. {
  19182. str[i] = tolower(str[i]);
  19183. }
  19184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19185. isSuccess = ConfigurationStatus_Accepted;
  19186. }
  19187. else
  19188. {
  19189. isSuccess = ConfigurationStatus_Rejected;
  19190. }
  19191. }
  19192. if(strcmp(key, "RfidEndianType") == 0)
  19193. {
  19194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility == 1)
  19195. {
  19196. strcpy(str, (const char*)value);
  19197. if((strcmp(str, "BIG")==0) || (strcmp(str, "LITTLE")==0))
  19198. {
  19199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "%s", str );
  19200. ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = (strcmp(str, "BIG")==0)?1:0;
  19201. isSuccess = ConfigurationStatus_Accepted;
  19202. }
  19203. else
  19204. isSuccess = ConfigurationStatus_Rejected;
  19205. }
  19206. else
  19207. {
  19208. isSuccess = ConfigurationStatus_Rejected;
  19209. }
  19210. }
  19211. if(strcmp(key, "AuthorizeTimeout") == 0)
  19212. {
  19213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility == 1)
  19214. {
  19215. strcpy(str, (const char*)value);
  19216. check_ascii = value[0];
  19217. if((check_ascii < 48) || (check_ascii > 57))
  19218. {
  19219. isSuccess = ConfigurationStatus_Rejected;
  19220. }
  19221. else
  19222. {
  19223. if((atoi(value) >= 10) && (atoi(value) <= 300))
  19224. {
  19225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "%s", str );
  19226. isSuccess = ConfigurationStatus_Accepted;
  19227. }
  19228. else
  19229. {
  19230. isSuccess = ConfigurationStatus_Rejected;
  19231. }
  19232. }
  19233. }
  19234. else
  19235. {
  19236. isSuccess = ConfigurationStatus_Rejected;
  19237. }
  19238. }
  19239. if(strcmp(key, "EnableAcCcs") == 0)
  19240. {
  19241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemAccessibility == 1)
  19242. {
  19243. strcpy(str, (const char*)value);
  19244. for(int i = 0; str[i]; i++)
  19245. {
  19246. str[i] = tolower(str[i]);
  19247. }
  19248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EnableAcCcs].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19249. isSuccess = ConfigurationStatus_Accepted;
  19250. }
  19251. else
  19252. {
  19253. isSuccess = ConfigurationStatus_Rejected;
  19254. }
  19255. }
  19256. #if 0
  19257. //For OCPP Test Case
  19258. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19259. {
  19260. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19261. {
  19262. strcpy(str, (const char*)value);
  19263. for(int i = 0; str[i]; i++)
  19264. {
  19265. str[i] = tolower(str[i]);
  19266. }
  19267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19268. isSuccess = ConfigurationStatus_Accepted;
  19269. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19270. }
  19271. else
  19272. {
  19273. isSuccess = ConfigurationStatus_Rejected;
  19274. }
  19275. }
  19276. #endif
  19277. #if 1
  19278. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19279. {
  19280. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19281. {
  19282. strcpy(str, (const char*)value);
  19283. for(int i = 0; str[i]; i++)
  19284. {
  19285. str[i] = tolower(str[i]);
  19286. }
  19287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19288. isSuccess = ConfigurationStatus_Accepted;
  19289. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19290. }
  19291. else
  19292. {
  19293. isSuccess = ConfigurationStatus_Rejected;
  19294. }
  19295. }
  19296. #endif
  19297. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19298. {
  19299. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19300. {
  19301. check_ascii = value[0];
  19302. if( (check_ascii < 48) || (check_ascii > 57) )
  19303. {
  19304. isSuccess = ConfigurationStatus_Rejected;
  19305. }
  19306. else
  19307. {
  19308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19309. isSuccess = ConfigurationStatus_Accepted;
  19310. }
  19311. }
  19312. else
  19313. {
  19314. isSuccess = ConfigurationStatus_Rejected;
  19315. }
  19316. }
  19317. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19318. {
  19319. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19320. {
  19321. check_ascii = value[0];
  19322. if( (check_ascii < 48) || (check_ascii > 57) )
  19323. {
  19324. isSuccess = ConfigurationStatus_Rejected;
  19325. }
  19326. else
  19327. {
  19328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19329. isSuccess = ConfigurationStatus_Accepted;
  19330. }
  19331. }
  19332. else
  19333. {
  19334. isSuccess = ConfigurationStatus_Rejected;
  19335. }
  19336. }
  19337. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19338. {
  19339. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19340. {
  19341. strcpy(str, (const char*)value);
  19342. for(int i = 0; str[i]; i++)
  19343. {
  19344. str[i] = tolower(str[i]);
  19345. }
  19346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19347. isSuccess = ConfigurationStatus_Accepted;
  19348. }
  19349. else
  19350. {
  19351. isSuccess = ConfigurationStatus_Rejected;
  19352. }
  19353. }
  19354. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19355. {
  19356. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19357. {
  19358. check_ascii = value[0];
  19359. if( (check_ascii < 48) || (check_ascii > 57) )
  19360. {
  19361. isSuccess = ConfigurationStatus_Rejected;
  19362. }
  19363. else
  19364. {
  19365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19366. isSuccess = ConfigurationStatus_Accepted;
  19367. }
  19368. }
  19369. else
  19370. {
  19371. isSuccess = ConfigurationStatus_Rejected;
  19372. }
  19373. }
  19374. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19375. {
  19376. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19377. {
  19378. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19379. isSuccess = ConfigurationStatus_Accepted;
  19380. }
  19381. else
  19382. {
  19383. isSuccess = ConfigurationStatus_Rejected;
  19384. }
  19385. }
  19386. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19387. {
  19388. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19389. {
  19390. check_ascii = value[0];
  19391. if( (check_ascii < 48) || (check_ascii > 57) )
  19392. {
  19393. isSuccess = ConfigurationStatus_Rejected;
  19394. }
  19395. else
  19396. {
  19397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19398. isSuccess = ConfigurationStatus_Accepted;
  19399. }
  19400. }
  19401. else
  19402. {
  19403. isSuccess = ConfigurationStatus_Rejected;
  19404. }
  19405. }
  19406. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19407. {
  19408. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19409. {
  19410. strcpy(str, (const char*)value);
  19411. for(int i = 0; str[i]; i++)
  19412. {
  19413. str[i] = tolower(str[i]);
  19414. }
  19415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19416. isSuccess = ConfigurationStatus_Accepted;
  19417. }
  19418. else
  19419. {
  19420. isSuccess = ConfigurationStatus_Rejected;
  19421. }
  19422. }
  19423. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19424. {
  19425. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19426. {
  19427. check_ascii = value[0];
  19428. if( (check_ascii < 48) || (check_ascii > 57) )
  19429. {
  19430. isSuccess = ConfigurationStatus_Rejected;
  19431. }
  19432. else
  19433. {
  19434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19435. isSuccess = ConfigurationStatus_Accepted;
  19436. }
  19437. }
  19438. else
  19439. {
  19440. isSuccess = ConfigurationStatus_Rejected;
  19441. }
  19442. }
  19443. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19444. return isSuccess;
  19445. }
  19446. int TransactionMessageAttemptsGet(void)
  19447. {
  19448. return TransactionMessageAttemptsValue;
  19449. }
  19450. int FirstHeartBeatResponse(void)
  19451. {
  19452. return FirstHeartBeat;
  19453. }
  19454. int TransactionMessageRetryIntervalGet(void)
  19455. {
  19456. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19457. }
  19458. int ReadHttpStatus(int sock)
  19459. {
  19460. //char c;
  19461. char buff[1024]="",*ptr=buff+1;
  19462. int bytes_received, status;
  19463. DEBUG_INFO("Begin Response ..\n");
  19464. while((bytes_received = recv(sock, ptr, 1, 0))){
  19465. if(bytes_received==-1){
  19466. perror("ReadHttpStatus");
  19467. exit(1);
  19468. }
  19469. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19470. ptr++;
  19471. }
  19472. *ptr=0;
  19473. ptr=buff+1;
  19474. sscanf(ptr,"%*s %d ", &status);
  19475. DEBUG_INFO("%s\n",ptr);
  19476. DEBUG_INFO("status=%d\n",status);
  19477. DEBUG_INFO("End Response ..\n");
  19478. return (bytes_received>0)?status:0;
  19479. }
  19480. //the only filed that it parsed is 'Content-Length'
  19481. int ParseHeader(int sock)
  19482. {
  19483. //char c;
  19484. char buff[1024]="",*ptr=buff+4;
  19485. int bytes_received;
  19486. DEBUG_INFO("Begin HEADER ..\n");
  19487. while((bytes_received = recv(sock, ptr, 1, 0))){
  19488. if(bytes_received==-1){
  19489. perror("Parse Header");
  19490. exit(1);
  19491. }
  19492. if(
  19493. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19494. (ptr[-1]=='\r') && (*ptr=='\n' )
  19495. ) break;
  19496. ptr++;
  19497. }
  19498. *ptr=0;
  19499. ptr=buff+4;
  19500. //printf("%s",ptr);
  19501. if(bytes_received){
  19502. ptr=strstr(ptr,"Content-Length:");
  19503. if(ptr){
  19504. sscanf(ptr,"%*s %d",&bytes_received);
  19505. }else
  19506. bytes_received=-1; //unknown size
  19507. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19508. }
  19509. DEBUG_INFO("End HEADER ..\n");
  19510. return bytes_received ;
  19511. }
  19512. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19513. {
  19514. int result = TRUE;
  19515. char rmFileCmd[300]={0};
  19516. char FilePath[256]={0};
  19517. char ftpbuf[2048];
  19518. int systemresult;
  19519. sprintf(FilePath,"/mnt/%s",filename);
  19520. system("ping 8.8.8.8 &");
  19521. if((access(FilePath,F_OK))!=-1)
  19522. {
  19523. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19524. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19525. system(rmFileCmd);
  19526. }
  19527. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19528. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19529. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  19530. else
  19531. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19532. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19533. systemresult = system(ftpbuf);
  19534. if(systemresult != 0)
  19535. {
  19536. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19537. result = FALSE;
  19538. }
  19539. system("pkill ping");
  19540. return result;
  19541. }
  19542. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19543. {
  19544. int result = TRUE;
  19545. char rmFileCmd[300]={0};
  19546. char FilePath[256]={0};
  19547. char ftpbuf[2048];
  19548. int systemresult;
  19549. sprintf(FilePath,"/mnt/%s",filename);
  19550. system("ping 8.8.8.8 &");
  19551. if((access(FilePath,F_OK))!=-1)
  19552. {
  19553. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19554. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19555. system(rmFileCmd);
  19556. }
  19557. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19558. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19559. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19560. systemresult = system(ftpbuf);
  19561. if(systemresult != 0)
  19562. {
  19563. DEBUG_WARN("scp error!\n");
  19564. result = FALSE;
  19565. }
  19566. system("pkill ping");
  19567. return result;
  19568. }
  19569. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19570. {
  19571. int result = TRUE;
  19572. char rmFileCmd[300]={0};
  19573. char FilePath[256]={0};
  19574. char ftpbuf[2048];
  19575. int systemresult;
  19576. sprintf(FilePath,"/mnt/%s",filename);
  19577. system("ping 8.8.8.8 &");
  19578. if((access(FilePath,F_OK))!=-1)
  19579. {
  19580. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19581. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19582. system(rmFileCmd);
  19583. }
  19584. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19585. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19586. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  19587. else
  19588. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19589. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19590. systemresult = system(ftpbuf);
  19591. if(systemresult != 0)
  19592. {
  19593. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19594. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --ca-certificate=/root/cacert.pem",filename, url);
  19595. else
  19596. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --no-check-certificate",filename, url);
  19597. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19598. systemresult = system(ftpbuf);
  19599. if(systemresult != 0)
  19600. {
  19601. DEBUG_WARN("FTP download fail!\n");
  19602. result = FALSE;
  19603. }
  19604. }
  19605. system("pkill ping");
  19606. return result;
  19607. }
  19608. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19609. {
  19610. char rmFileCmd[100]={0};
  19611. char FilePath[100]={0};
  19612. char buf[512];
  19613. int systemresult = 0;
  19614. //DEBUG_INFO("filename=%s\n",filename);
  19615. //DEBUG_INFO("url=%s\n",url);
  19616. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19617. if((access(FilePath,F_OK))!=-1)
  19618. {
  19619. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19620. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19621. system(rmFileCmd);
  19622. }
  19623. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19624. if(fp == NULL)
  19625. {
  19626. DEBUG_INFO("log is NULL\n");
  19627. return FALSE;
  19628. }
  19629. else
  19630. {
  19631. fprintf(fp, "%s\n", url);
  19632. fprintf(fp, "%s\n", filename);
  19633. fclose(fp);
  19634. }
  19635. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19636. if(phpFP == NULL)
  19637. {
  19638. DEBUG_INFO("PHP upload fail.\n");
  19639. return FALSE;
  19640. }
  19641. else
  19642. {
  19643. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19644. {
  19645. if(strstr(buf, "result") != NULL)
  19646. {
  19647. sscanf(buf, "result: %d", &systemresult);
  19648. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19649. }
  19650. }
  19651. pclose(phpFP);
  19652. }
  19653. if(systemresult != 1)
  19654. {
  19655. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19656. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19657. if(phpFP == NULL)
  19658. {
  19659. DEBUG_WARN("PHP PUT upload fail.\n");
  19660. return FALSE;
  19661. }
  19662. else
  19663. {
  19664. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19665. {
  19666. if(strstr(buf, "result") != NULL)
  19667. {
  19668. sscanf(buf, "result: %d", &systemresult);
  19669. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19670. }
  19671. }
  19672. pclose(phpFP);
  19673. }
  19674. }
  19675. if(systemresult != 1)
  19676. {
  19677. DEBUG_WARN("PHP PUT upload fail.\n");
  19678. return FALSE;
  19679. }
  19680. return TRUE;
  19681. }
  19682. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19683. {
  19684. int result = FALSE;
  19685. char ftpbuf[200];
  19686. int systemresult;
  19687. /*
  19688. // Domaind name transfer to IP address
  19689. struct hostent* server;
  19690. char *IPbuffer;
  19691. server = gethostbyname(location);
  19692. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19693. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19694. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19695. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19696. systemresult = system(ftpbuf);
  19697. if(systemresult != 0)
  19698. {
  19699. DEBUG_INFO("ftpput error!\n");
  19700. }
  19701. else
  19702. {
  19703. result = TRUE;
  19704. DEBUG_INFO("ftpput OK!\n");
  19705. }
  19706. return result;
  19707. }
  19708. int GetOcppServerURL()
  19709. {
  19710. int result = FALSE;
  19711. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19712. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19713. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19714. struct yuarel url;
  19715. char urlStr[512];
  19716. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19717. {
  19718. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19719. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19720. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19721. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19722. if(yuarel_parse(&url, urlStr) != -1)
  19723. {
  19724. sprintf(OcppProtocol, "%s", url.scheme);
  19725. sprintf(OcppHost, "%s", url.host);
  19726. if(url.path == NULL)
  19727. OcppTempPath[0] = '\0';
  19728. else
  19729. {
  19730. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19731. {
  19732. sprintf(OcppTempPath, "%s/", url.path);
  19733. }
  19734. else
  19735. {
  19736. sprintf(OcppTempPath, "%s", url.path);
  19737. }
  19738. }
  19739. if(url.port == 0)
  19740. {
  19741. if(strcmp(OcppProtocol, "wss") == 0)
  19742. OcppPort = 443;
  19743. else
  19744. OcppPort = 80;
  19745. }
  19746. else
  19747. OcppPort = url.port;
  19748. result = TRUE;
  19749. }
  19750. }
  19751. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19752. {
  19753. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19754. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19755. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19756. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19757. if(yuarel_parse(&url, urlStr) != -1)
  19758. {
  19759. sprintf(OcppProtocol, "%s", url.scheme);
  19760. sprintf(OcppHost, "%s", url.host);
  19761. if(url.path == NULL)
  19762. OcppTempPath[0] = '\0';
  19763. else
  19764. sprintf(OcppTempPath, "%s", url.path);
  19765. if(url.port == 0)
  19766. {
  19767. if(strcmp(OcppProtocol, "wss") == 0)
  19768. OcppPort = 443;
  19769. else
  19770. OcppPort = 80;
  19771. }
  19772. else
  19773. OcppPort = url.port;
  19774. result = TRUE;
  19775. }
  19776. }
  19777. else
  19778. {
  19779. strcpy(OcppHost,"");
  19780. }
  19781. return result;
  19782. }
  19783. int GetOcppPath()
  19784. {
  19785. int result = FALSE;
  19786. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19787. {
  19788. if(OcppTempPath == NULL)
  19789. {
  19790. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19791. }
  19792. else
  19793. {
  19794. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19795. }
  19796. result = TRUE;
  19797. goto End;
  19798. }
  19799. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19800. {
  19801. if(OcppTempPath == NULL)
  19802. {
  19803. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19804. }
  19805. else
  19806. {
  19807. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19808. }
  19809. result = TRUE;
  19810. goto End;
  19811. }
  19812. else
  19813. {
  19814. strcpy(OcppPath,"");
  19815. }
  19816. End:
  19817. return result;
  19818. }
  19819. int GetOcppPort()
  19820. {
  19821. return OcppPort;
  19822. }
  19823. int GetOcppConnStatus(void)
  19824. {
  19825. return ShmOCPP16Data->OcppConnStatus;
  19826. }
  19827. void SetOcppConnStatus(uint8_t status)
  19828. {
  19829. ShmOCPP16Data->OcppConnStatus = status;
  19830. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19831. }
  19832. int GetHeartBeatWithNOResponse(void)
  19833. {
  19834. return HeartBeatWithNOResponse;
  19835. }
  19836. void SetHeartBeatWithNOResponse(void)
  19837. {
  19838. HeartBeatWithNOResponse = 0;
  19839. }
  19840. void GetStartTransactionIdTag(int gun_index)
  19841. {
  19842. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19843. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19844. }
  19845. int GetStartTransactionId(int gun_index)
  19846. {
  19847. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19848. }
  19849. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19850. {
  19851. char ch;
  19852. FILE *fptr1;
  19853. int temptransactionId;
  19854. char str[100]={0};
  19855. temptransactionId = 0;
  19856. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19857. {
  19858. DEBUG_INFO("IdTag is empty.\n");
  19859. return temptransactionId;
  19860. }
  19861. /*------ Read the file ----------------*/
  19862. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19863. if (!fptr1)
  19864. {
  19865. DEBUG_INFO("QueueTransactionId file open error.\n");
  19866. //printf(" File not found or unable to open the input file!!\n");
  19867. return temptransactionId;
  19868. }
  19869. ch=fgetc(fptr1);
  19870. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19871. rewind(fptr1);
  19872. if(ch!=EOF)
  19873. {
  19874. // printf("%c",ch);
  19875. while (fgets(str, 100, fptr1) != NULL)
  19876. {
  19877. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19878. if(str[0]=='\0')
  19879. {
  19880. break;
  19881. }
  19882. char *revbuf[8] = {0}; // Variable store string split
  19883. int num = 0;// Quantity after string split
  19884. DEBUG_INFO("Transaction queue data= %s\n", str);
  19885. splitstring(str,",",revbuf,&num); // String split
  19886. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19887. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19888. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19889. DEBUG_INFO("------------------------------\n");
  19890. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19891. {
  19892. if(isStopTransaction)
  19893. {
  19894. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19895. {
  19896. temptransactionId = atoi(revbuf[2]);
  19897. //break;
  19898. }
  19899. }
  19900. else
  19901. {
  19902. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19903. {
  19904. temptransactionId = atoi(revbuf[2]);
  19905. //break;
  19906. }
  19907. }
  19908. }
  19909. }
  19910. }
  19911. else
  19912. DEBUG_INFO("EOF\n");
  19913. fclose(fptr1);
  19914. /*------- End of reading ---------------*/
  19915. return temptransactionId;
  19916. }
  19917. void SetTransactionIdZero(int transactionId)
  19918. {
  19919. char ch;
  19920. FILE *fptr1, *fptr2;
  19921. int temptransactionId = 0;
  19922. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19923. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19924. if (!fptr1)
  19925. {
  19926. //printf(" File not found or unable to open the input file!!\n");
  19927. return ;
  19928. }
  19929. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19930. if (!fptr2)
  19931. {
  19932. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19933. fclose(fptr1);
  19934. return ;
  19935. }
  19936. ch=fgetc(fptr1);
  19937. rewind(fptr1);
  19938. if(ch!=EOF)
  19939. {
  19940. // copy all contents to the temporary file except the specific line
  19941. while (fgets(str, 100, fptr1) != NULL)
  19942. {
  19943. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19944. if(str[0]=='\0')
  19945. {
  19946. break;
  19947. }
  19948. char *revbuf[8] = {0};
  19949. int num = 0;
  19950. strcpy(strtemp, str);
  19951. splitstring(str,",",revbuf,&num);
  19952. if(revbuf[2][0] != '\0')
  19953. {
  19954. temptransactionId = atoi(revbuf[2]);
  19955. if(transactionId != temptransactionId)
  19956. {
  19957. fprintf(fptr2, "%s\n", strtemp);
  19958. }
  19959. }
  19960. }
  19961. }
  19962. fclose(fptr1);
  19963. fclose(fptr2);
  19964. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19965. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19966. /*------ Read the file ----------------*/
  19967. }
  19968. int InternetDisconnect(void)
  19969. {
  19970. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19971. }
  19972. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19973. void storeTempStopTransaction(int gun_index)
  19974. {
  19975. char guid[37]={0};
  19976. int tempIndex = 0;
  19977. char TempStopTransaction[256];
  19978. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19979. DEBUG_INFO("storeTempStopTransaction...\n");
  19980. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19981. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19982. //=========================== Stop Transaction Time ===============================================
  19983. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  19984. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19985. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19986. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19987. {
  19988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19989. {
  19990. tempIndex = ((gun_index==2) ? 1: 0);
  19991. }
  19992. else
  19993. {
  19994. tempIndex = gun_index;
  19995. }
  19996. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19997. {
  19998. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19999. {
  20000. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  20001. }
  20002. }// END OF CHAdeMO_QUANTITY
  20003. }
  20004. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20005. {
  20006. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20007. {
  20008. tempIndex = ((gun_index==2) ? 1: 0);
  20009. }
  20010. else
  20011. {
  20012. tempIndex = gun_index;
  20013. }
  20014. for (int index = 0; index < CCS_QUANTITY; index++)
  20015. {
  20016. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20017. {
  20018. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  20019. }
  20020. }// END OF CCS_QUANTITY
  20021. }
  20022. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20023. {
  20024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20025. {
  20026. tempIndex = ((gun_index==2) ? 1: 0);
  20027. }
  20028. else
  20029. {
  20030. tempIndex = gun_index;
  20031. }
  20032. for (int index = 0; index < GB_QUANTITY; index++)
  20033. {
  20034. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20035. {
  20036. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  20037. }
  20038. }// END OF GB_QUANTITY
  20039. }
  20040. else if(gunType[gun_index] == GUN_TYPE_DO)
  20041. {
  20042. tempIndex = gun_index;
  20043. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20044. {
  20045. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20046. {
  20047. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  20048. }
  20049. }
  20050. }
  20051. else
  20052. {
  20053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20054. {
  20055. tempIndex = 2;
  20056. }
  20057. else
  20058. {
  20059. tempIndex = gun_index;
  20060. }
  20061. for (int index = 0; index < AC_QUANTITY; index++)
  20062. {
  20063. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20064. {
  20065. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  20066. }
  20067. }// END OF AC_QUANTITY
  20068. }
  20069. //======================================== Message create ==============================================
  20070. json_object *StopTransaction = json_object_new_object();
  20071. json_object *transactionDatas = json_object_new_array();
  20072. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  20073. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  20074. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  20075. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  20076. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  20077. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  20078. meterValueBufferQuery(gun_index, transactionDatas);
  20079. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  20080. random_uuid(guid);
  20081. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  20082. ,MESSAGE_TYPE_CALL
  20083. ,guid
  20084. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  20085. json_object_put(StopTransaction);
  20086. // Check File "TempStopTransaction" Exist
  20087. if((access(TempStopTransaction,F_OK))!=-1)
  20088. {
  20089. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  20090. fclose(fopen(TempStopTransaction, "w"));
  20091. }
  20092. else
  20093. {
  20094. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  20095. FILE *log = fopen(TempStopTransaction, "w+");
  20096. if(log == NULL)
  20097. {
  20098. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  20099. return ;
  20100. }
  20101. else
  20102. {
  20103. fclose(log);
  20104. }
  20105. }
  20106. //Add TempStopTransaction | Update TempStopTransaction
  20107. // open file for writing
  20108. FILE *outfile;
  20109. outfile = fopen (TempStopTransaction, "a");
  20110. //DEBUG_INFO("data = %s\n", queuedata);
  20111. fputs(queuedata, outfile);
  20112. fputs("\n", outfile);
  20113. fclose (outfile);
  20114. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20115. OCPP_updatePeriodEnergy(gun_index);
  20116. }
  20117. void checkTempStopTransaction(int gun_index)
  20118. {
  20119. FILE *fptr1;
  20120. char ch;
  20121. char str[QUEUE_MESSAGE_LENGTH]={0};
  20122. char guid[37]={0};
  20123. char tempdata[65]={0};
  20124. char connectorStr[2]={0};
  20125. char TempStopTransaction[256];
  20126. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20127. fptr1 = fopen(TempStopTransaction, "r");
  20128. //TempStopTransaction格式: 槍號,StopTransaction封包
  20129. if (!fptr1)
  20130. {
  20131. //printf(" File not found or unable to open the input file!!\n");
  20132. return ;
  20133. }
  20134. ch=fgetc(fptr1);
  20135. //printf(" Now the content of the file %s is : \n",fname);
  20136. rewind(fptr1);
  20137. if(ch!=EOF)
  20138. {
  20139. // copy all contents to the temporary file except the specific line
  20140. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  20141. {
  20142. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20143. if(str[0]=='\0')
  20144. {
  20145. break;
  20146. }
  20147. //TempStopTransaction格式: 槍號,StopTransaction封包
  20148. strncpy(connectorStr, str, 1);
  20149. if(atoi(connectorStr) != (gun_index+1))
  20150. {
  20151. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  20152. fclose(fptr1);
  20153. return ;
  20154. }
  20155. //random_uuid(guid);
  20156. strncpy(guid, str+6, 36); //copy guid
  20157. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  20158. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  20159. {
  20160. //DEBUG_INFO("StopTransaction mapitem pass\n");
  20161. }
  20162. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  20163. OCPP_insert_transaction_msg(NO, str);
  20164. memset(str,0,ARRAY_SIZE(str));
  20165. }
  20166. }
  20167. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  20168. fclose(fptr1);
  20169. remove(TempStopTransaction); // remove the original file
  20170. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20171. }
  20172. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  20173. {
  20174. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20175. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  20176. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  20177. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  20178. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  20179. }
  20180. void FillTransactionId(int ConnectorId, int TransactionId)
  20181. {
  20182. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20183. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  20184. }
  20185. int GetWebSocketPingInterval(void)
  20186. {
  20187. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  20188. }
  20189. int GetServerSign(void)
  20190. {
  20191. return server_sign;
  20192. }
  20193. uint8_t GetOcppSecurityProfile()
  20194. {
  20195. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  20196. }
  20197. void MergeCertificates()
  20198. {
  20199. char cmdBuf[2048]={0};
  20200. if(access(ROOTCA_CS,F_OK) != -1)
  20201. {
  20202. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  20203. }
  20204. else
  20205. {
  20206. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  20207. }
  20208. system(cmdBuf);
  20209. }
  20210. void GetOcppChargerBoxId(uint8_t *data)
  20211. {
  20212. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20213. }
  20214. void GetOcppSecurityPassword(uint8_t *data)
  20215. {
  20216. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  20217. }
  20218. void SetOcppVersion(uint8_t *version)
  20219. {
  20220. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  20221. DEBUG_INFO("ocpp version: %s\n", version);
  20222. if(strstr((char*)version, "ocpp1.6") != NULL)
  20223. {
  20224. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  20225. }
  20226. else if(strstr((char*)version, "ocpp2.0") != NULL)
  20227. {
  20228. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  20229. system("pkill OcppBackend");
  20230. }
  20231. }
  20232. void SetServerSign(int value)
  20233. {
  20234. server_sign = value;
  20235. }
  20236. int GetBootNotificationInterval(void)
  20237. {
  20238. return BootNotificationInterval;
  20239. }
  20240. int GetInternetConn(void)
  20241. {
  20242. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  20243. }
  20244. int GetBackendConnectionTimeout(void)
  20245. {
  20246. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20247. }
  20248. int isConnectorInitMode(int gun_index)
  20249. {
  20250. int tempIndex = 0;
  20251. int result = TRUE;
  20252. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20253. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20254. {
  20255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20256. {
  20257. tempIndex = ((gun_index==2) ? 1: 0);
  20258. }
  20259. else
  20260. {
  20261. tempIndex = gun_index;
  20262. }
  20263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20264. {
  20265. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20266. {
  20267. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20268. } //end of the same index
  20269. }//end of for CHAdeMO_QUANTITY
  20270. }
  20271. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20272. {
  20273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20274. {
  20275. tempIndex = ((gun_index==2) ? 1: 0);
  20276. }
  20277. else
  20278. {
  20279. tempIndex = gun_index;
  20280. }
  20281. for (int index = 0; index < CCS_QUANTITY; index++)
  20282. {
  20283. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20284. {
  20285. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20286. } //end of the same index
  20287. } // end of for CCS_QUANTITY
  20288. }
  20289. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20290. {
  20291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20292. {
  20293. tempIndex = ((gun_index==2) ? 1: 0);
  20294. }
  20295. else
  20296. {
  20297. tempIndex = gun_index;
  20298. }
  20299. for (int index = 0; index < GB_QUANTITY; index++)
  20300. {
  20301. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20302. {
  20303. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20304. } //end of the same index
  20305. } // end of for GB_QUANTITY
  20306. }
  20307. else if(gunType[gun_index] == GUN_TYPE_DO)
  20308. {
  20309. tempIndex = gun_index;
  20310. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20311. {
  20312. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20313. {
  20314. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20315. } //end of the same index
  20316. }
  20317. }
  20318. else
  20319. {
  20320. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20321. {
  20322. tempIndex = 2;
  20323. }
  20324. else
  20325. {
  20326. tempIndex = gun_index;
  20327. }
  20328. for (int index = 0; index < AC_QUANTITY; index++)
  20329. {
  20330. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20331. {
  20332. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20333. }//end of the same index
  20334. }//end of for AC_QUANTITY
  20335. }
  20336. return result;
  20337. }
  20338. void refreshProcDogTimer()
  20339. {
  20340. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20341. }
  20342. void InitialSystemValue(void)
  20343. {
  20344. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20345. locallistVersion=0;
  20346. BootNotificationInterval = 0;
  20347. authorizeRetryTimes = 0;
  20348. GunStatusInterval = 10;
  20349. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20350. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20351. //Heart Beat
  20352. HeartBeatWithNOResponse = 0;
  20353. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20354. if(HeartBeatWaitTime == 0)
  20355. FirstHeartBeat = TRUE;
  20356. else
  20357. FirstHeartBeat = FALSE;
  20358. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20359. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20360. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20361. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20362. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20363. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20364. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20365. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20366. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20367. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20368. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20369. //Status && ConnectorPlugIn Setting
  20370. Connector0PreviousSystemStatus = 99;
  20371. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20372. {
  20373. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20374. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20375. }
  20376. for (int index = 0; index < CCS_QUANTITY; index++)
  20377. {
  20378. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20379. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20380. }
  20381. for (int index = 0; index < GB_QUANTITY; index++)
  20382. {
  20383. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20384. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20385. }
  20386. for (int index = 0; index < AC_QUANTITY; index++)
  20387. {
  20388. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20389. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20390. }
  20391. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20392. {
  20393. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20394. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20395. }
  20396. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20397. {
  20398. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20399. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20400. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20401. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20402. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20403. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20404. }
  20405. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20406. refreshStartTimer(&clientTime.Heartbeat);
  20407. sleep(1);
  20408. }
  20409. void LWS_Send(char *str)
  20410. {
  20411. //=====================================================
  20412. // Check InternetConn 0: disconnected, 1: connected
  20413. //====================================================
  20414. if(GetOcppConnStatus() == 0)
  20415. {
  20416. DEBUG_INFO("offline now !!!\n");
  20417. return;
  20418. }
  20419. // Only disable isWebsocketSendable operation initiated by charger
  20420. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20421. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20422. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20423. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20424. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20425. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20426. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20427. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20428. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20429. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20430. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20431. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20432. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20433. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20434. {
  20435. isWebsocketSendable = 0;
  20436. }
  20437. pthread_mutex_lock(&lock_send);
  20438. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20439. sprintf((char *)SendBuffer, "%s", str);
  20440. SendBufLen = strlen(str);
  20441. pthread_mutex_unlock(&lock_send);
  20442. lws_callback_on_writable(wsi_client);
  20443. //lws_service(context, 0);
  20444. //sleep(1);
  20445. }
  20446. void LWS_SendNow(char *str)
  20447. {
  20448. //=====================================================
  20449. // Check InternetConn 0: disconnected, 1: connected
  20450. //====================================================
  20451. if(GetOcppConnStatus() == 0)
  20452. {
  20453. DEBUG_INFO("offline now !!!\n");
  20454. return;
  20455. }
  20456. // Only disable isWebsocketSendable operation initiated by charger
  20457. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20458. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20459. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20460. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20461. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20462. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20463. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20464. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20465. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20466. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20467. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20468. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20469. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20470. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20471. {
  20472. isWebsocketSendable = 0;
  20473. }
  20474. pthread_mutex_lock(&lock_send);
  20475. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20476. sprintf((char *)SendBuffer, "%s", str);
  20477. SendBufLen = strlen(str);
  20478. pthread_mutex_unlock(&lock_send);
  20479. lws_callback_on_writable(wsi_client);
  20480. lws_service(context, 0);
  20481. //sleep(1);
  20482. }