MessageHandler.c 1008 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430
  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. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='Z'))
  4394. ) // 'D' means DC
  4395. {
  4396. // DO series
  4397. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4398. {
  4399. gunTotalNumber += 1;
  4400. gunType[gun_index] = GUN_TYPE_DO;
  4401. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4402. {
  4403. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4404. {
  4405. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4406. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4407. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4408. }
  4409. }
  4410. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4411. {
  4412. case Gun_Type_Chademo:
  4413. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4414. break;
  4415. case Gun_Type_CCS_2:
  4416. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4417. break;
  4418. case Gun_Type_GB:
  4419. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4420. break;
  4421. case Gun_Type_AC:
  4422. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4423. break;
  4424. default:
  4425. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4426. break;
  4427. }
  4428. }
  4429. }
  4430. else
  4431. {
  4432. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4433. {
  4434. gunTotalNumber += 1;
  4435. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4436. {
  4437. case Gun_Type_Chademo:
  4438. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4439. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4440. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4441. {
  4442. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4443. {
  4444. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4445. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4446. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4447. }
  4448. }
  4449. break;
  4450. case Gun_Type_CCS_2:
  4451. gunType[gun_index] = GUN_TYPE_CCS;
  4452. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4453. for (int index = 0; index < CCS_QUANTITY; index++)
  4454. {
  4455. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4456. {
  4457. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4458. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4459. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4460. }
  4461. }
  4462. break;
  4463. case Gun_Type_GB:
  4464. gunType[gun_index] = GUN_TYPE_GBT;
  4465. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4466. for (int index = 0; index < GB_QUANTITY; index++)
  4467. {
  4468. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4469. {
  4470. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4471. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4472. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4473. }
  4474. }
  4475. break;
  4476. case Gun_Type_AC:
  4477. gunType[gun_index] = GUN_TYPE_AC;
  4478. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4479. for (int index = 0; index < AC_QUANTITY; index++)
  4480. {
  4481. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4482. {
  4483. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4484. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4485. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4486. }
  4487. }
  4488. break;
  4489. default:
  4490. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4491. break;
  4492. }
  4493. }
  4494. }
  4495. }
  4496. else
  4497. {
  4498. DEBUG_ERROR("Model name parsing fail.\n");
  4499. result = FAIL;
  4500. }
  4501. if(result != PASS)sleep(5);
  4502. return result;
  4503. }
  4504. void checkRemoteStart(uint8_t connectorIdInt)
  4505. {
  4506. uint8_t tempIndex;
  4507. int result = PASS;
  4508. char cmdBuf[512];
  4509. //check Transaction active
  4510. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4511. {
  4512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4513. {
  4514. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4515. }
  4516. else
  4517. {
  4518. tempIndex = connectorIdInt -1;
  4519. }
  4520. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4521. {
  4522. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4523. {
  4524. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4525. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4526. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4527. {
  4528. //Reserved
  4529. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4530. }
  4531. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4532. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4533. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4534. {
  4535. //Reserved
  4536. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4537. result = FAIL;
  4538. goto end;
  4539. }
  4540. else
  4541. {
  4542. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4543. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4544. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4545. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4546. {
  4547. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4548. result = FAIL;
  4549. goto end;
  4550. }
  4551. }//END FOR ELSE
  4552. }
  4553. }// END FOR CHAdeMO_QUANTITY
  4554. }
  4555. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4556. {
  4557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4558. {
  4559. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4560. }
  4561. else
  4562. {
  4563. tempIndex = connectorIdInt -1;
  4564. }
  4565. for (int index = 0; index < CCS_QUANTITY; index++)
  4566. {
  4567. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4568. {
  4569. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4570. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4571. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4572. {
  4573. //Reserved
  4574. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4575. }
  4576. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4577. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4578. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4579. {
  4580. //Reserved
  4581. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4582. result = FAIL;
  4583. goto end;
  4584. }
  4585. else
  4586. {
  4587. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4588. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4589. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4590. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4591. {
  4592. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4593. result = FAIL;
  4594. goto end;
  4595. }
  4596. }// END FOR ELSE
  4597. }
  4598. }// END FOR CCS_QUANTITY
  4599. }
  4600. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4601. {
  4602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4603. {
  4604. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4605. }
  4606. else
  4607. {
  4608. tempIndex = connectorIdInt -1;
  4609. }
  4610. for (int index = 0; index < GB_QUANTITY; index++)
  4611. {
  4612. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4613. {
  4614. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4615. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4616. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4617. {
  4618. //Reserved
  4619. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4620. }
  4621. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4622. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4623. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4624. {
  4625. //Reserved
  4626. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4627. result = FAIL;
  4628. goto end;
  4629. }
  4630. else
  4631. {
  4632. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4633. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4634. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4635. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4636. {
  4637. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4638. result = FAIL;
  4639. goto end;
  4640. }
  4641. }// END FOR ELSE
  4642. }
  4643. } // END FOR GB_QUANTITY
  4644. }
  4645. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4646. {
  4647. tempIndex = connectorIdInt -1;
  4648. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4649. {
  4650. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4651. {
  4652. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4653. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4654. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4655. {
  4656. //Reserved
  4657. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4658. }
  4659. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4660. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4661. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4662. {
  4663. //Reserved
  4664. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4665. result = FAIL;
  4666. goto end;
  4667. }
  4668. else
  4669. {
  4670. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4671. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4672. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4673. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4674. {
  4675. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4676. result = FAIL;
  4677. goto end;
  4678. }
  4679. }// END FOR ELSE
  4680. }
  4681. } // END FOR GB_QUANTITY
  4682. }
  4683. else
  4684. {
  4685. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4686. {
  4687. tempIndex = 2;
  4688. }
  4689. else
  4690. {
  4691. tempIndex = connectorIdInt -1;
  4692. }
  4693. for (int index = 0; index < AC_QUANTITY; index++)
  4694. {
  4695. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4696. {
  4697. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4698. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4699. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4700. {
  4701. //Reserved
  4702. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4703. }
  4704. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4705. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4706. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4707. {
  4708. //Reserved
  4709. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4710. result = FAIL;
  4711. goto end;
  4712. }
  4713. else
  4714. {
  4715. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4716. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4717. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4718. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4719. {
  4720. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4721. result = FAIL;
  4722. goto end;
  4723. }
  4724. }//END FOR ELSE
  4725. }
  4726. }// END FOR AC_QUANTITY
  4727. }
  4728. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4729. {
  4730. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4731. {
  4732. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4733. {
  4734. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4735. system(cmdBuf);
  4736. }
  4737. }
  4738. else
  4739. {
  4740. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4741. result = FAIL;
  4742. }
  4743. }
  4744. end:
  4745. if(result == PASS)
  4746. {
  4747. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4748. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4749. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4750. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4751. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4752. }
  4753. }
  4754. int isConnector0Unavailable()
  4755. {
  4756. uint8_t result = YES;
  4757. uint8_t tempIndex;
  4758. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4759. {
  4760. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4761. {
  4762. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4763. {
  4764. tempIndex = ((gun_index==2) ? 1: 0);
  4765. }
  4766. else
  4767. {
  4768. tempIndex = gun_index;
  4769. }
  4770. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4771. {
  4772. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4773. {
  4774. 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))
  4775. {
  4776. result = NO;
  4777. }
  4778. }
  4779. }
  4780. }
  4781. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4782. {
  4783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4784. {
  4785. tempIndex = ((gun_index==2) ? 1: 0);
  4786. }
  4787. else
  4788. {
  4789. tempIndex = gun_index;
  4790. }
  4791. for (int index = 0; index < CCS_QUANTITY; index++)
  4792. {
  4793. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4794. {
  4795. 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))
  4796. {
  4797. result = NO;
  4798. }
  4799. }
  4800. }
  4801. }
  4802. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4803. {
  4804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4805. {
  4806. tempIndex = ((gun_index==2) ? 1: 0);
  4807. }
  4808. else
  4809. {
  4810. tempIndex = gun_index;
  4811. }
  4812. for (int index = 0; index < GB_QUANTITY; index++)
  4813. {
  4814. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4815. {
  4816. 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))
  4817. {
  4818. result = NO;
  4819. }
  4820. }
  4821. }
  4822. }
  4823. else if(gunType[gun_index] == GUN_TYPE_DO)
  4824. {
  4825. tempIndex = gun_index;
  4826. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4827. {
  4828. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4829. {
  4830. 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))
  4831. {
  4832. result = NO;
  4833. }
  4834. }
  4835. }
  4836. }
  4837. else
  4838. {
  4839. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4840. {
  4841. tempIndex = 2;
  4842. }
  4843. else
  4844. {
  4845. tempIndex = gun_index;
  4846. }
  4847. for (int index = 0; index < AC_QUANTITY; index++)
  4848. {
  4849. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4850. {
  4851. 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))
  4852. {
  4853. result = NO;
  4854. }
  4855. }
  4856. }// END
  4857. }
  4858. }
  4859. return result;
  4860. }
  4861. void CheckSystemValue(void)
  4862. {
  4863. char filenmae[100]={0};
  4864. char str[100]={0};
  4865. int tempIndex = 0;
  4866. //===============================
  4867. // send Heartbeat
  4868. //===============================
  4869. if((server_sign == TRUE) && (HeartBeatWaitTime > 0) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4870. {
  4871. //parameter for test
  4872. if(HeartBeatWithNOResponse < 1)
  4873. sendHeartbeatRequest(0);
  4874. //===========================
  4875. // Reset Waiting Time
  4876. //===========================
  4877. HeartBeatWithNOResponse += 1;
  4878. }
  4879. //===============================
  4880. // Tcci credit deduct report
  4881. //===============================
  4882. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4883. {
  4884. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4885. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4886. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4887. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4888. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4889. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4890. }
  4891. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4892. {
  4893. OCPP_query_deduct_info();
  4894. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4895. }
  4896. if(ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq)
  4897. {
  4898. OCPP_insert_occupancyDeduct_info((char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN, (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo,
  4899. ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult, ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount,
  4900. (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo);
  4901. ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = FALSE;
  4902. }
  4903. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryOccupancyDeduct) > 5)
  4904. {
  4905. OCPP_query_occupancyDeduct_info();
  4906. refreshStartTimer(&clientTime.TcciQueryOccupancyDeduct);
  4907. }
  4908. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4909. {
  4910. // ClockAlign MeterValue
  4911. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4912. {
  4913. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4914. {
  4915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4916. {
  4917. tempIndex = ((gun_index==2) ? 1: 0);
  4918. }
  4919. else
  4920. {
  4921. tempIndex = gun_index;
  4922. }
  4923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4924. {
  4925. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4926. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4927. {
  4928. reqClockAlignMeter[gun_index] = 1;
  4929. }
  4930. }// End for CHAdeMO
  4931. }
  4932. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4933. {
  4934. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4935. {
  4936. tempIndex = ((gun_index==2) ? 1: 0);
  4937. }
  4938. else
  4939. {
  4940. tempIndex = gun_index;
  4941. }
  4942. for (int index = 0; index < CCS_QUANTITY; index++)
  4943. {
  4944. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4945. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4946. {
  4947. reqClockAlignMeter[gun_index] = 1;
  4948. }
  4949. } // End for CCS
  4950. }
  4951. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4952. {
  4953. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4954. {
  4955. tempIndex = ((gun_index==2) ? 1: 0);
  4956. }
  4957. else
  4958. {
  4959. tempIndex = gun_index;
  4960. }
  4961. for (int index = 0; index < GB_QUANTITY; index++)
  4962. {
  4963. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4964. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4965. {
  4966. reqClockAlignMeter[gun_index] = 1;
  4967. }
  4968. }// End for GB
  4969. }
  4970. else if(gunType[gun_index] == GUN_TYPE_DO)
  4971. {
  4972. tempIndex = gun_index;
  4973. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4974. {
  4975. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4976. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4977. {
  4978. reqClockAlignMeter[gun_index] = 1;
  4979. }
  4980. }
  4981. }
  4982. else
  4983. {
  4984. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4985. {
  4986. tempIndex = 2;
  4987. }
  4988. else
  4989. {
  4990. tempIndex = gun_index;
  4991. }
  4992. for (int index = 0; index < AC_QUANTITY; index++)
  4993. {
  4994. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4995. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4996. {
  4997. reqClockAlignMeter[gun_index] = 1;
  4998. }
  4999. }//End for AC
  5000. }
  5001. }
  5002. }
  5003. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  5004. {
  5005. //==========================================
  5006. // Check remote start without connector id
  5007. //==========================================
  5008. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  5009. {
  5010. int connectorIdInt = -1;
  5011. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  5012. {
  5013. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  5014. {
  5015. connectorIdInt = (gun_index+1);
  5016. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  5017. checkRemoteStart(connectorIdInt);
  5018. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  5019. break;
  5020. }
  5021. }
  5022. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  5023. {
  5024. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5025. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  5026. }
  5027. }
  5028. //==========================================
  5029. // csu trigger DataTransferReq
  5030. //==========================================
  5031. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  5032. {
  5033. sendDataTransferRequest(gun_index);
  5034. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  5035. }
  5036. //==========================================
  5037. // CSU Trigger Authorize Request
  5038. //==========================================
  5039. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  5040. {
  5041. sendAuthorizeRequest(0);
  5042. authorizeRetryTimes = authorizeRetryTimes + 1;
  5043. if(authorizeRetryTimes < 3)
  5044. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5045. }
  5046. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  5047. {
  5048. authorizeRetryTimes = 0;
  5049. SetOcppConnStatus(FALSE);
  5050. server_sign = FALSE;
  5051. }
  5052. 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))
  5053. {
  5054. sendAuthorizeRequest(0);
  5055. }
  5056. //==========================================
  5057. // Charger start transaction
  5058. //==========================================
  5059. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  5060. {
  5061. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  5062. meterValueBufferClear(gun_index);
  5063. sendStartTransactionRequest(gun_index);
  5064. refreshStartTimer(&clientTime.StartTransaction);
  5065. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5066. storeTempStopTransaction(gun_index);
  5067. }
  5068. //==========================================
  5069. // Charger stop transaction
  5070. //==========================================
  5071. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  5072. {
  5073. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5074. sendStopTransactionRequest(gun_index);
  5075. OCPP_updatePeriodEnergy(gun_index);
  5076. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  5077. refreshStartTimer(&clientTime.StopTransaction);
  5078. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  5079. }
  5080. //==========================================
  5081. // Charger OCMF message
  5082. //==========================================
  5083. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  5084. {
  5085. sendOcmfByDataTransferRequest(gun_index);
  5086. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  5087. }
  5088. //==========================================
  5089. // Charger status report
  5090. //==========================================
  5091. //--- Check Mode Change ---//
  5092. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5093. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5094. {
  5095. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5096. {
  5097. tempIndex = ((gun_index==2) ? 1: 0);
  5098. }
  5099. else
  5100. {
  5101. tempIndex = gun_index;
  5102. }
  5103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5104. {
  5105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5106. {
  5107. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5108. {
  5109. // Sent unplug message for California pricing logic
  5110. 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])
  5111. {
  5112. uint8_t ts[36];
  5113. getNowDatetime(ts);
  5114. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5115. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5116. if(strcmp((char*)dmsVersion, "2.0")==0)
  5117. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5118. else
  5119. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5120. sendUnplugByDataTransferRequest(gun_index);
  5121. interLock.isSentUnplug[gun_index] = 1;
  5122. }
  5123. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5124. {
  5125. interLock.isSentUnplug[gun_index] = 0;
  5126. }
  5127. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5128. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5129. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5130. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5131. {
  5132. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5133. if((access(filenmae,F_OK))!=-1)
  5134. {
  5135. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5136. sprintf(str,"rm -f %s",filenmae);
  5137. system(str);
  5138. }
  5139. }
  5140. }
  5141. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5142. #if 1 // for TempStopTransaction
  5143. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5144. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5145. {
  5146. checkTempStopTransaction(gun_index);
  5147. }
  5148. #endif
  5149. }
  5150. }
  5151. }
  5152. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5153. {
  5154. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5155. {
  5156. tempIndex = ((gun_index==2) ? 1: 0);
  5157. }
  5158. else
  5159. {
  5160. tempIndex = gun_index;
  5161. }
  5162. for (int index = 0; index < CCS_QUANTITY; index++)
  5163. {
  5164. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5165. {
  5166. 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]*/ )
  5167. {
  5168. // Sent unplug message for California pricing logic
  5169. 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])
  5170. {
  5171. uint8_t ts[36];
  5172. getNowDatetime(ts);
  5173. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5174. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5175. if(strcmp((char*)dmsVersion, "2.0")==0)
  5176. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5177. else
  5178. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5179. sendUnplugByDataTransferRequest(gun_index);
  5180. interLock.isSentUnplug[gun_index] = 1;
  5181. }
  5182. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5183. {
  5184. interLock.isSentUnplug[gun_index] = 0;
  5185. }
  5186. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  5187. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  5188. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5189. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5190. {
  5191. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5192. if((access(filenmae,F_OK))!=-1)
  5193. {
  5194. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5195. sprintf(str,"rm -f %s",filenmae);
  5196. system(str);
  5197. }
  5198. }
  5199. }
  5200. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5201. #if 1 // for TempStopTransaction
  5202. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5203. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5204. {
  5205. checkTempStopTransaction(gun_index);
  5206. }
  5207. #endif
  5208. }
  5209. }
  5210. }
  5211. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5212. {
  5213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5214. {
  5215. tempIndex = ((gun_index==2) ? 1: 0);
  5216. }
  5217. else
  5218. {
  5219. tempIndex = gun_index;
  5220. }
  5221. for (int index = 0; index < GB_QUANTITY; index++)
  5222. {
  5223. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5224. {
  5225. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5226. {
  5227. // Sent unplug message for California pricing logic
  5228. 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])
  5229. {
  5230. uint8_t ts[36];
  5231. getNowDatetime(ts);
  5232. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5233. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5234. if(strcmp((char*)dmsVersion, "2.0")==0)
  5235. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5236. else
  5237. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5238. sendUnplugByDataTransferRequest(gun_index);
  5239. interLock.isSentUnplug[gun_index] = 1;
  5240. }
  5241. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5242. {
  5243. interLock.isSentUnplug[gun_index] = 0;
  5244. }
  5245. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5246. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5247. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5248. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5249. {
  5250. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5251. if((access(filenmae,F_OK))!=-1)
  5252. {
  5253. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5254. sprintf(str,"rm -f %s",filenmae);
  5255. system(str);
  5256. }
  5257. }
  5258. }
  5259. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5260. #if 1 // for TempStopTransaction
  5261. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5262. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5263. {
  5264. checkTempStopTransaction(gun_index);
  5265. }
  5266. #endif
  5267. }
  5268. }
  5269. }
  5270. else if(gunType[gun_index] == GUN_TYPE_DO)
  5271. {
  5272. tempIndex = gun_index;
  5273. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5274. {
  5275. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5276. {
  5277. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5278. {
  5279. // Sent unplug message for California pricing logic
  5280. 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])
  5281. {
  5282. uint8_t ts[36];
  5283. getNowDatetime(ts);
  5284. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5285. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5286. if(strcmp((char*)dmsVersion, "2.0")==0)
  5287. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5288. else
  5289. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5290. sendUnplugByDataTransferRequest(gun_index);
  5291. interLock.isSentUnplug[gun_index] = 1;
  5292. }
  5293. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  5294. {
  5295. interLock.isSentUnplug[gun_index] = 0;
  5296. }
  5297. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5298. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5299. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5300. 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
  5301. {
  5302. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5303. if((access(filenmae,F_OK))!=-1)
  5304. {
  5305. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5306. sprintf(str,"rm -f %s",filenmae);
  5307. system(str);
  5308. }
  5309. }
  5310. }
  5311. 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);
  5312. #if 1 // for TempStopTransaction
  5313. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5314. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5315. {
  5316. checkTempStopTransaction(gun_index);
  5317. }
  5318. #endif
  5319. }
  5320. }
  5321. }
  5322. else
  5323. {
  5324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5325. {
  5326. tempIndex = 2;
  5327. }
  5328. else
  5329. {
  5330. tempIndex = gun_index;
  5331. }
  5332. for (int index = 0; index < AC_QUANTITY; index++)
  5333. {
  5334. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5335. {
  5336. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5337. {
  5338. // Sent unplug message for California pricing logic
  5339. 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])
  5340. {
  5341. uint8_t ts[36];
  5342. getNowDatetime(ts);
  5343. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5344. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5345. if(strcmp((char*)dmsVersion, "2.0")==0)
  5346. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5347. else
  5348. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5349. sendUnplugByDataTransferRequest(gun_index);
  5350. interLock.isSentUnplug[gun_index] = 1;
  5351. }
  5352. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5353. {
  5354. interLock.isSentUnplug[gun_index] = 0;
  5355. }
  5356. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5357. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5358. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5359. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5360. {
  5361. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5362. if((access(filenmae,F_OK))!=-1)
  5363. {
  5364. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5365. sprintf(str,"rm -f %s",filenmae);
  5366. system(str);
  5367. }
  5368. }
  5369. }
  5370. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5371. #if 1 // for TempStopTransaction
  5372. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5373. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5374. {
  5375. checkTempStopTransaction(gun_index);
  5376. }
  5377. #endif
  5378. }
  5379. }// END
  5380. }
  5381. if(isWebsocketSendable && (server_sign == TRUE) && (isConnector0Unavailable() != Connector0PreviousSystemStatus))
  5382. {
  5383. sendConnector0StatusNotificationRequest();
  5384. Connector0PreviousSystemStatus = isConnector0Unavailable();
  5385. }
  5386. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  5387. (
  5388. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  5389. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  5390. )
  5391. )
  5392. {
  5393. sendStatusNotificationRequest(gun_index);
  5394. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  5395. }
  5396. //==============================================
  5397. // TCCI related DataTransfer messages
  5398. //==============================================
  5399. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  5400. {
  5401. reportReaderStatus(gun_index);
  5402. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5403. }
  5404. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq == 1))
  5405. {
  5406. occupancyFeeAct(gun_index);
  5407. }
  5408. //==============================================
  5409. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5410. //==============================================
  5411. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5412. ((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))))
  5413. {
  5414. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5415. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5416. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5417. }
  5418. //==============================================
  5419. // Meter report
  5420. //==============================================
  5421. // Trigger MeterValue
  5422. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5423. {
  5424. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5425. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5426. }
  5427. // Clock-aligned Meter value
  5428. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5429. {
  5430. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5431. reqClockAlignMeter[gun_index] = 0;
  5432. }
  5433. // Sample period MeterValue
  5434. 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))))
  5435. {
  5436. //check Transaction active
  5437. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5438. {
  5439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5440. {
  5441. tempIndex = ((gun_index==2) ? 1: 0);
  5442. }
  5443. else
  5444. {
  5445. tempIndex = gun_index;
  5446. }
  5447. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5448. {
  5449. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5450. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5451. {
  5452. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5453. {
  5454. reqSampleMeter[gun_index] = 1;
  5455. }
  5456. }
  5457. }// End for CHAdeMO
  5458. }
  5459. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5460. {
  5461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5462. {
  5463. tempIndex = ((gun_index==2) ? 1: 0);
  5464. }
  5465. else
  5466. {
  5467. tempIndex = gun_index;
  5468. }
  5469. for (int index = 0; index < CCS_QUANTITY; index++)
  5470. {
  5471. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5472. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5473. {
  5474. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5475. {
  5476. reqSampleMeter[gun_index] = 1;
  5477. }
  5478. }
  5479. } // End for CCS
  5480. }
  5481. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5482. {
  5483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5484. {
  5485. tempIndex = ((gun_index==2) ? 1: 0);
  5486. }
  5487. else
  5488. {
  5489. tempIndex = gun_index;
  5490. }
  5491. for (int index = 0; index < GB_QUANTITY; index++)
  5492. {
  5493. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5494. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5495. {
  5496. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5497. {
  5498. reqSampleMeter[gun_index] = 1;
  5499. }
  5500. }
  5501. }// End for GB
  5502. }
  5503. else if(gunType[gun_index] == GUN_TYPE_DO)
  5504. {
  5505. tempIndex = gun_index;
  5506. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5507. {
  5508. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5509. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5510. {
  5511. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5512. {
  5513. reqSampleMeter[gun_index] = 1;
  5514. }
  5515. }
  5516. }
  5517. }
  5518. else
  5519. {
  5520. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5521. {
  5522. tempIndex = 2;
  5523. }
  5524. else
  5525. {
  5526. tempIndex = gun_index;
  5527. }
  5528. for (int index = 0; index < AC_QUANTITY; index++)
  5529. {
  5530. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5531. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5532. {
  5533. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5534. {
  5535. reqSampleMeter[gun_index] = 1;
  5536. }
  5537. }
  5538. }//End for AC
  5539. }
  5540. if(reqSampleMeter[gun_index] == 1)
  5541. {
  5542. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5543. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5544. storeTempStopTransaction(gun_index);
  5545. reqSampleMeter[gun_index] = 0;
  5546. }
  5547. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5548. }
  5549. //==============================================
  5550. // Check Connector reserved
  5551. //==============================================
  5552. //===============================
  5553. // Check if Reserve is expired
  5554. //===============================
  5555. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5556. {
  5557. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5558. {
  5559. DEBUG_INFO("reserve expired.\n");
  5560. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5561. }
  5562. }//END OF Check if Reserve is expired
  5563. //==========================================
  5564. // csu trigger FirmwareStatusNotificationReq
  5565. //==========================================
  5566. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5567. {
  5568. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5569. }
  5570. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5571. {
  5572. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5573. }
  5574. //==========================================
  5575. // csu trigger DiagnosticsStatusNotificationReq
  5576. //==========================================
  5577. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5578. {
  5579. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5580. }
  5581. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5582. {
  5583. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5584. }
  5585. //==========================================
  5586. // csu trigger CancelReservationConf
  5587. //==========================================
  5588. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5589. {
  5590. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5591. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5592. }
  5593. //==========================================
  5594. // csu trigger ChangeAvailabilityConf
  5595. //==========================================
  5596. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5597. {
  5598. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5599. }
  5600. //==========================================
  5601. // csu trigger UnlockConnectorConf
  5602. //==========================================
  5603. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5604. {
  5605. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5606. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5607. }
  5608. //==========================================
  5609. // csu trigger ReserveNowConf
  5610. //==========================================
  5611. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5612. {
  5613. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5614. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5615. }
  5616. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5617. {
  5618. sendSignCertificateRequest();
  5619. }
  5620. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5621. {
  5622. sendSecurityEventNotificationRequest();
  5623. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5624. }
  5625. // Support 15118
  5626. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5627. {
  5628. json_object *data = json_object_new_object();
  5629. // Read csr file content
  5630. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5631. FILE *fp=fopen(CSR_V2G,"r");
  5632. char *line = NULL;
  5633. size_t len = 0;
  5634. while(getline(&line, &len, fp) != -1)
  5635. {
  5636. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5637. {
  5638. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5639. }
  5640. }
  5641. fclose(fp);
  5642. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5643. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5644. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5645. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5646. json_object_put(data);
  5647. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5648. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5649. }
  5650. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5651. {
  5652. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5653. int parseCertResult = FAIL;
  5654. json_object *data = json_object_new_object();
  5655. json_object *idToken = json_object_new_object();
  5656. json_object *iso15118CertificateHashData = json_object_new_array();
  5657. // Read CERTIFICATE_PnCAuth file content
  5658. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5659. {
  5660. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5661. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5662. char *line = NULL;
  5663. size_t len = 0;
  5664. while(getline(&line, &len, fp) != -1)
  5665. {
  5666. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5667. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5668. }
  5669. fclose(fp);
  5670. }
  5671. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5672. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5673. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5674. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5675. json_object_object_add(data, "idToken", idToken);
  5676. char parseData[512] = {0};
  5677. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5678. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5679. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5680. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5681. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5682. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5683. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5684. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5685. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5686. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5687. for(int idx=0; idx < 4; idx++)
  5688. {
  5689. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5690. {
  5691. json_object *OCSPRequestDataType = json_object_new_object();
  5692. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5693. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5694. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5695. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5696. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5697. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5698. parseCertResult = PASS;
  5699. }
  5700. }
  5701. if(parseCertResult == PASS)
  5702. {
  5703. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5704. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5705. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5706. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5707. json_object_put(data);
  5708. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5709. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5710. }
  5711. else
  5712. {
  5713. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5714. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5715. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5716. }
  5717. }
  5718. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5719. {
  5720. json_object *data = json_object_new_object();
  5721. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5722. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5723. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5724. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5725. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5726. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5727. json_object_put(data);
  5728. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5729. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5730. }
  5731. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5732. {
  5733. json_object *data = json_object_new_object();
  5734. json_object *OCSPRequestDataType = json_object_new_object();
  5735. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5736. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5737. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5738. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5739. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5740. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5741. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5742. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5743. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5744. json_object_put(data);
  5745. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5746. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5747. }
  5748. }
  5749. }
  5750. //==========================================
  5751. // send request routine
  5752. //==========================================
  5753. int sendAuthorizeRequest(int gun_index)
  5754. {
  5755. mtrace();
  5756. int result = FAIL;
  5757. char message[100]={0};
  5758. char guid[37];
  5759. char tempdata[65]={0};
  5760. DEBUG_INFO("sendAuthorizeRequest...\n");
  5761. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5762. //Local Authorize
  5763. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5764. {
  5765. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5766. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5767. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5768. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5769. result = PASS;
  5770. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5771. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5772. authorizeRetryTimes = 0;
  5773. return result;
  5774. }
  5775. 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))||
  5776. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5777. {
  5778. // Query from cache
  5779. DEBUG_INFO("Authorize from cache.\n");
  5780. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5781. // Query from list
  5782. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5783. {
  5784. DEBUG_INFO("Authorize from list.\n");
  5785. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5786. }
  5787. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5788. {
  5789. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5790. {
  5791. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5792. }
  5793. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5794. {
  5795. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5796. }
  5797. if(!GetOcppConnStatus())
  5798. {
  5799. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5800. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5801. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5802. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5803. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5804. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5805. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5806. authorizeRetryTimes = 0;
  5807. return result;
  5808. }
  5809. }
  5810. else
  5811. {
  5812. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5813. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5814. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5815. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5816. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5817. else
  5818. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5819. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5820. result = PASS;
  5821. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5822. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5823. authorizeRetryTimes = 0;
  5824. return result;
  5825. }
  5826. }
  5827. //initialize struct Authorize
  5828. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5829. //get data from shared memory
  5830. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5831. random_uuid(guid);
  5832. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5833. LWS_Send(message);
  5834. sprintf(tempdata, "Authorize,%d", gun_index);
  5835. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5836. {
  5837. result = PASS;
  5838. DEBUG_INFO("Authorize mapItem pass\n");
  5839. }
  5840. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5841. return result;
  5842. }
  5843. int sendBootNotificationRequest(void)
  5844. {
  5845. mtrace();
  5846. int result = FAIL;
  5847. char message[500]={0}, payload[700]={0};
  5848. char guid[37]={0};
  5849. char tempdata[65]={0};
  5850. // Fill BootNotification fields
  5851. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5852. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5853. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5854. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5855. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5856. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5857. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5858. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5859. ShmOCPP16Data->ChargeBoxId
  5860. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5861. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5862. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5863. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5864. ,ShmOCPP16Data->BootNotification.CpIccid
  5865. ,ShmOCPP16Data->BootNotification.CpImsi);
  5866. random_uuid(guid);
  5867. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5868. LWS_Send(message);
  5869. sprintf(tempdata, "BootNotification,0");
  5870. 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*/)
  5871. {
  5872. result = PASS;
  5873. }
  5874. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5875. strcpy(queuedata,message);
  5876. return result;
  5877. }
  5878. int sendDataTransferRequest(int gun_index)
  5879. {
  5880. mtrace();
  5881. char message[10240]={0};
  5882. char guid[37]={0};
  5883. char tempdata[65]={0};
  5884. int result = FAIL;
  5885. json_object *DataTransfer = json_object_new_object();
  5886. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5887. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5888. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5889. random_uuid(guid);
  5890. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5891. guid,
  5892. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5893. json_object_put(DataTransfer);
  5894. LWS_Send(message);
  5895. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5896. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5897. {
  5898. result = PASS;
  5899. DEBUG_INFO("DataTransfer mapItem pass\n");
  5900. }
  5901. return result;
  5902. }
  5903. int sendUnplugByDataTransferRequest(int gun_index)
  5904. {
  5905. mtrace();
  5906. char message[10752]={0};
  5907. char guid[37]={0};
  5908. char tempdata[65]={0};
  5909. int result = FAIL;
  5910. random_uuid(guid);
  5911. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5912. (gun_index+1),
  5913. MESSAGE_TYPE_CALL,
  5914. guid,
  5915. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5916. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5917. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5918. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5919. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5920. {
  5921. result = PASS;
  5922. DEBUG_INFO("DataTransfer mapItem pass\n");
  5923. }
  5924. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5925. return result;
  5926. }
  5927. int sendOcmfByDataTransferRequest(int gun_index)
  5928. {
  5929. mtrace();
  5930. json_object *DataTransfer = json_object_new_object();
  5931. json_object *data = json_object_new_object();
  5932. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5933. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5934. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5935. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5936. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5937. json_object_object_add(DataTransfer, "data", data);
  5938. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5939. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5940. char message[3000]={0};
  5941. char guid[37]={0};
  5942. char tempdata[65]={0};
  5943. int result = FAIL;
  5944. random_uuid(guid);
  5945. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5946. (gun_index+1),
  5947. MESSAGE_TYPE_CALL,
  5948. guid,
  5949. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5950. json_object_put(DataTransfer);
  5951. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5952. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5953. {
  5954. result = PASS;
  5955. DEBUG_INFO("DataTransfer mapItem pass\n");
  5956. }
  5957. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5958. return result;
  5959. }
  5960. int sendDiagnosticsStatusNotificationRequest(char *status)
  5961. {
  5962. mtrace();
  5963. int result = FAIL;
  5964. char message[110]={0};
  5965. char guid[37]={0};
  5966. char tempdata[65]={0};
  5967. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5968. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5969. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5970. random_uuid(guid);
  5971. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5972. LWS_SendNow(message);
  5973. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5974. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5975. {
  5976. result = PASS;
  5977. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5978. }
  5979. //#ifdef SystemLogMessage
  5980. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5981. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5982. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5983. //#endif
  5984. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5985. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5986. //record status
  5987. if(strcmp(status,"Idle")==0)
  5988. {
  5989. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5990. }
  5991. else if(strcmp(status,"Uploaded")==0)
  5992. {
  5993. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5994. }
  5995. else if(strcmp(status,"UploadFailed")==0)
  5996. {
  5997. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5998. }
  5999. else if(strcmp(status,"Uploading")==0)
  6000. {
  6001. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  6002. }
  6003. return result;
  6004. }
  6005. int sendFirmwareStatusNotificationRequest(char *status)
  6006. {
  6007. mtrace();
  6008. int result = FAIL;
  6009. char message[110]={0};
  6010. char guid[37]={0};
  6011. char tempdata[65]={0};
  6012. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  6013. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  6014. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  6015. random_uuid(guid);
  6016. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  6017. LWS_SendNow(message);
  6018. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6019. 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*/)
  6020. {
  6021. result = PASS;
  6022. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  6023. }
  6024. //#ifdef SystemLogMessage
  6025. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  6026. //DEBUG_INFO("Message: %s\n", SendBuffer);
  6027. //#endif
  6028. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  6029. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  6030. //record status
  6031. if(strcmp(status,"Downloaded")==0)
  6032. {
  6033. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  6034. }
  6035. else if(strcmp(status,"DownloadFailed")==0)
  6036. {
  6037. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  6038. }
  6039. else if(strcmp(status,"Downloading")==0)
  6040. {
  6041. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  6042. }
  6043. else if(strcmp(status,"Idle")==0)
  6044. {
  6045. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  6046. }
  6047. else if(strcmp(status,"InstallationFailed")==0)
  6048. {
  6049. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  6050. }
  6051. else if(strcmp(status,"Installing")==0)
  6052. {
  6053. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  6054. }
  6055. else if(strcmp(status,"Installed")==0)
  6056. {
  6057. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  6058. }
  6059. return result;
  6060. }
  6061. int sendHeartbeatRequest(int gun_index)
  6062. {
  6063. mtrace();
  6064. int result = FAIL;
  6065. char message[80]={0};
  6066. char guid[37]={0};
  6067. char tempdata[65]={0};
  6068. random_uuid(guid);
  6069. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  6070. , MESSAGE_TYPE_CALL
  6071. , guid );
  6072. LWS_Send(message);
  6073. sprintf(tempdata, "Heartbeat,%d", 0);
  6074. 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*/)
  6075. {
  6076. result = PASS;
  6077. }
  6078. return result;
  6079. }
  6080. int sendStartTransactionRequest(int gun_index)
  6081. {
  6082. mtrace();
  6083. int result = FAIL;
  6084. char message[250]={0};
  6085. char guid[37]={0};
  6086. struct timeval tmnow;
  6087. struct tm *tm;
  6088. char buf[28];//, usec_buf[6];
  6089. char tempdata[65]={0};
  6090. int tempIndex = 0;
  6091. DEBUG_INFO("sendStartTransactionRequest...\n");
  6092. gettimeofday(&tmnow, NULL);
  6093. time_t t;
  6094. t = time(NULL);
  6095. /*UTC time and date*/
  6096. tm = gmtime(&t);
  6097. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6098. #if 0 // remove temporally
  6099. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6100. strcat(buf,".");
  6101. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6102. strcat(buf,usec_buf);
  6103. #endif
  6104. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  6105. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  6106. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6107. // clear StartTransaction Response
  6108. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  6109. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  6110. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  6111. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  6112. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6113. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6114. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6115. {
  6116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6117. {
  6118. tempIndex = ((gun_index==2) ? 1: 0);
  6119. }
  6120. else
  6121. {
  6122. tempIndex = gun_index;
  6123. }
  6124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6125. {
  6126. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6127. {
  6128. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6129. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  6130. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6131. }
  6132. }
  6133. }
  6134. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6135. {
  6136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6137. {
  6138. tempIndex = ((gun_index==2) ? 1: 0);
  6139. }
  6140. else
  6141. {
  6142. tempIndex = gun_index;
  6143. }
  6144. for (int index = 0; index < CCS_QUANTITY; index++)
  6145. {
  6146. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6147. {
  6148. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6149. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  6150. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6151. }
  6152. }
  6153. }
  6154. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6155. {
  6156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6157. {
  6158. tempIndex = ((gun_index==2) ? 1: 0);
  6159. }
  6160. else
  6161. {
  6162. tempIndex = gun_index;
  6163. }
  6164. for (int index = 0; index < GB_QUANTITY; index++)
  6165. {
  6166. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6167. {
  6168. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6169. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  6170. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6171. }
  6172. }
  6173. }
  6174. else if(gunType[gun_index] == GUN_TYPE_DO)
  6175. {
  6176. tempIndex = gun_index;
  6177. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6178. {
  6179. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6180. {
  6181. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6182. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  6183. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6184. }
  6185. }
  6186. }
  6187. else
  6188. {
  6189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6190. {
  6191. tempIndex = 2;
  6192. }
  6193. else
  6194. {
  6195. tempIndex = gun_index;
  6196. }
  6197. for (int index = 0; index < AC_QUANTITY; index++)
  6198. {
  6199. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6200. {
  6201. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6202. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  6203. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6204. }
  6205. }
  6206. }
  6207. random_uuid(guid);
  6208. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  6209. {
  6210. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  6211. , gun_index +1
  6212. , MESSAGE_TYPE_CALL
  6213. , guid
  6214. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6215. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6216. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6217. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6218. }
  6219. else
  6220. {
  6221. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  6222. , gun_index +1
  6223. , MESSAGE_TYPE_CALL
  6224. , guid
  6225. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6226. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6227. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6228. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  6229. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6230. }
  6231. #if 1
  6232. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  6233. 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*/)
  6234. {
  6235. result = PASS;
  6236. }
  6237. #endif
  6238. strcpy(queuedata, message);
  6239. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6240. OCPP_insert_transaction_msg(YES, queuedata);
  6241. return result;
  6242. }
  6243. int sendConnector0StatusNotificationRequest()
  6244. {
  6245. mtrace();
  6246. int result = FAIL;
  6247. char message[600]={0};
  6248. char guid[37];
  6249. struct timeval tmnow;
  6250. struct tm *tm;
  6251. char buf[28];//, usec_buf[6];
  6252. char tempdata[65]={0};
  6253. DEBUG_INFO("sendConnector0StatusNotificationRequest...\n");
  6254. gettimeofday(&tmnow, NULL);
  6255. time_t t;
  6256. t = time(NULL);
  6257. /*UTC time and date*/
  6258. tm = gmtime(&t);
  6259. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6260. random_uuid(guid);
  6261. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":0,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6262. , MESSAGE_TYPE_CALL
  6263. , guid
  6264. , "NoError"
  6265. , ""
  6266. , (isConnector0Unavailable()==YES?"Unavailable":"Available")
  6267. , buf
  6268. , ShmSysConfigAndInfo->SysConfig.chargePointVendor
  6269. , "");
  6270. LWS_Send(message);
  6271. sprintf(tempdata, "StatusNotification,%d", 99);
  6272. 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*/)
  6273. {
  6274. //DEBUG_ERROR("statusNotification mapitem pass");
  6275. result = PASS;
  6276. }
  6277. return result;
  6278. }
  6279. int sendStatusNotificationRequest(int gun_index)
  6280. {
  6281. mtrace();
  6282. int result = FAIL;
  6283. char message[600]={0};
  6284. char guid[37];
  6285. int currentStatus = 0;
  6286. struct timeval tmnow;
  6287. struct tm *tm;
  6288. char buf[28];//, usec_buf[6];
  6289. char tempdata[65]={0};
  6290. int tempIndex = 0;
  6291. uint8_t isStateChanged = TRUE;
  6292. uint8_t isContentIllegal = TRUE;
  6293. DEBUG_INFO("sendStatusNotificationRequest...\n");
  6294. gettimeofday(&tmnow, NULL);
  6295. time_t t;
  6296. t = time(NULL);
  6297. /*UTC time and date*/
  6298. tm = gmtime(&t);
  6299. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6300. #if 0 // remove temporally
  6301. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6302. strcat(buf,".");
  6303. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6304. strcat(buf,usec_buf);
  6305. #endif
  6306. //printf("%s",buf);
  6307. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  6308. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  6309. // it's option
  6310. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  6311. /*
  6312. enum _SYSTEM_STATUS
  6313. {
  6314. S_BOOTING = 0,
  6315. S_IDLE, = 1
  6316. S_AUTHORIZING, =2
  6317. S_REASSIGN_CHECK, =3
  6318. S_REASSIGN, =4
  6319. S_PRECHARGE, =5
  6320. S_PREPARING_FOR_EV, =6
  6321. S_PREPARING_FOR_EVSE, =7
  6322. S_CHARGING, =8
  6323. S_TERMINATING, =9
  6324. S_COMPLETE, =10
  6325. S_ALARM, =11
  6326. S_FAULT =12
  6327. }
  6328. */
  6329. //check Transaction active
  6330. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6331. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6332. {
  6333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6334. {
  6335. tempIndex = ((gun_index==2) ? 1: 0);
  6336. }
  6337. else
  6338. {
  6339. tempIndex = gun_index;
  6340. }
  6341. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6342. {
  6343. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6344. {
  6345. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6346. {
  6347. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6348. {
  6349. currentStatus = Preparing; //OCPP Status: Preparing
  6350. }
  6351. else
  6352. {
  6353. currentStatus = Available; //OCPP Status: Available
  6354. }
  6355. }
  6356. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6357. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6358. ) //S_PRECHARGE
  6359. {
  6360. currentStatus = Preparing; //OCPP Status: Preparing
  6361. }
  6362. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6363. {
  6364. currentStatus = Charging; //OCPP Status: Charging
  6365. }
  6366. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6367. {
  6368. currentStatus = Finishing; //OCPP Status: Finishing
  6369. }
  6370. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6371. {
  6372. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6373. }
  6374. 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
  6375. {
  6376. currentStatus = Unavailable; //OCPP Status: Unavailable
  6377. }
  6378. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6379. {
  6380. currentStatus = Faulted; //OCPP Status: Faulted
  6381. }
  6382. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6383. {
  6384. currentStatus = Reserved; //OCPP Status: Reserved
  6385. }
  6386. } //end of the same index
  6387. }//end of for CHAdeMO_QUANTITY
  6388. }
  6389. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6390. {
  6391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6392. {
  6393. tempIndex = ((gun_index==2) ? 1: 0);
  6394. }
  6395. else
  6396. {
  6397. tempIndex = gun_index;
  6398. }
  6399. for (int index = 0; index < CCS_QUANTITY; index++)
  6400. {
  6401. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6402. {
  6403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6404. {
  6405. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  6406. {
  6407. currentStatus = Preparing; //OCPP Status: Preparing
  6408. }
  6409. else
  6410. {
  6411. currentStatus = Available; //OCPP Status: Available
  6412. }
  6413. }
  6414. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6415. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6416. ) //S_PRECHARGE
  6417. {
  6418. currentStatus = Preparing; //OCPP Status: Preparing
  6419. }
  6420. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6421. {
  6422. currentStatus = Charging; //OCPP Status: Charging
  6423. }
  6424. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6425. {
  6426. currentStatus = Finishing; //OCPP Status: Finishing
  6427. }
  6428. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6429. {
  6430. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6431. }
  6432. 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
  6433. {
  6434. currentStatus = Unavailable; //OCPP Status : Unavailable
  6435. }
  6436. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6437. {
  6438. currentStatus = Faulted; //OCPP Status: Faulted
  6439. }
  6440. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6441. {
  6442. currentStatus = Reserved; //OCPP Status: Reserved
  6443. }
  6444. } //end of the same index
  6445. } // end of for CCS_QUANTITY
  6446. }
  6447. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6448. {
  6449. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6450. {
  6451. tempIndex = ((gun_index==2) ? 1: 0);
  6452. }
  6453. else
  6454. {
  6455. tempIndex = gun_index;
  6456. }
  6457. for (int index = 0; index < GB_QUANTITY; index++)
  6458. {
  6459. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6460. {
  6461. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6462. {
  6463. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6464. {
  6465. currentStatus = Preparing; //OCPP Status: Preparing
  6466. }
  6467. else
  6468. {
  6469. currentStatus = Available; //OCPP Status: Available
  6470. }
  6471. }
  6472. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6473. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6474. ) //S_PRECHARGE
  6475. {
  6476. currentStatus = Preparing; //OCPP Status: Preparing
  6477. }
  6478. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6479. {
  6480. currentStatus = Charging; //OCPP Status: Charging
  6481. }
  6482. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6483. {
  6484. currentStatus = Finishing; //OCPP Status: Finishing
  6485. }
  6486. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6487. {
  6488. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6489. }
  6490. 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
  6491. {
  6492. currentStatus = Unavailable; //OCPP Status: Unavailable
  6493. }
  6494. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6495. {
  6496. currentStatus = Faulted; //OCPP Status: Faulted
  6497. }
  6498. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6499. {
  6500. currentStatus = Reserved; //OCPP Status: Reserved
  6501. }
  6502. } //end of the same index
  6503. } // end of for GB_QUANTITY
  6504. }
  6505. else if(gunType[gun_index] == GUN_TYPE_DO)
  6506. {
  6507. tempIndex = gun_index;
  6508. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6509. {
  6510. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6511. {
  6512. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6513. {
  6514. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6515. {
  6516. currentStatus = Preparing; //OCPP Status: Preparing
  6517. }
  6518. else
  6519. {
  6520. currentStatus = Available; //OCPP Status: Available
  6521. }
  6522. }
  6523. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6524. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6525. ) //S_PRECHARGE
  6526. {
  6527. currentStatus = Preparing; //OCPP Status: Preparing
  6528. }
  6529. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6530. {
  6531. currentStatus = Charging; //OCPP Status: Charging
  6532. }
  6533. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6534. {
  6535. currentStatus = Finishing; //OCPP Status: Finishing
  6536. }
  6537. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6538. {
  6539. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6540. }
  6541. 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
  6542. {
  6543. currentStatus = Unavailable; //OCPP Status: Unavailable
  6544. }
  6545. 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
  6546. {
  6547. currentStatus = Faulted; //OCPP Status: Faulted
  6548. }
  6549. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6550. {
  6551. currentStatus = Reserved; //OCPP Status: Reserved
  6552. }
  6553. } //end of the same index
  6554. }
  6555. }
  6556. else
  6557. {
  6558. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6559. {
  6560. tempIndex = 2;
  6561. }
  6562. else
  6563. {
  6564. tempIndex = gun_index;
  6565. }
  6566. for (int index = 0; index < AC_QUANTITY; index++)
  6567. {
  6568. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6569. {
  6570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6571. {
  6572. 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))
  6573. {
  6574. currentStatus = Preparing; //OCPP Status: Preparing
  6575. }
  6576. else
  6577. {
  6578. currentStatus = Available; //OCPP Status: Available
  6579. }
  6580. }
  6581. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6582. {
  6583. currentStatus = Preparing; //OCPP Status: Preparing
  6584. }
  6585. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6586. {
  6587. currentStatus = Charging; //OCPP Status: Charging
  6588. }
  6589. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6590. {
  6591. currentStatus = Finishing; //OCPP Status: Finishing
  6592. }
  6593. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6594. {
  6595. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6596. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6597. else
  6598. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6599. }
  6600. 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
  6601. {
  6602. currentStatus = Unavailable; //OCPP Status: Unavailable
  6603. }
  6604. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6605. {
  6606. currentStatus = Faulted; //OCPP Status: Faulted
  6607. }
  6608. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6609. {
  6610. currentStatus = Reserved; //OCPP Status: Reserved
  6611. }
  6612. }//end of the same index
  6613. }//end of for AC_QUANTITY
  6614. }
  6615. //it's option
  6616. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6617. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6618. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6619. {
  6620. isStateChanged = FALSE;
  6621. }
  6622. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6623. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6624. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6625. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6626. isContentIllegal = TRUE;
  6627. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6628. {
  6629. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6630. {
  6631. isContentIllegal = FALSE;
  6632. break;
  6633. }
  6634. }
  6635. if(isContentIllegal)
  6636. {
  6637. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6638. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6639. }
  6640. random_uuid(guid);
  6641. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6642. , MESSAGE_TYPE_CALL
  6643. , guid
  6644. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6645. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6646. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6647. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6648. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6649. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6650. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6651. if((server_sign == TRUE) && isStateChanged)
  6652. {
  6653. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6654. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6655. LWS_Send(message);
  6656. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6657. 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*/)
  6658. {
  6659. //DEBUG_ERROR("statusNotification mapitem pass");
  6660. result = PASS;
  6661. }
  6662. }
  6663. else
  6664. {
  6665. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6666. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6667. result = PASS;
  6668. }
  6669. return result;
  6670. }
  6671. int sendStopTransactionRequest(int gun_index)
  6672. {
  6673. mtrace();
  6674. int result = FAIL;
  6675. //char message[1500]={0};
  6676. char guid[37]={0};
  6677. char tempdata[65]={0};
  6678. int tempIndex = 0;
  6679. char TempStopTransaction[256];
  6680. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6681. DEBUG_INFO("sendStopTransactionRequest \n");
  6682. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6683. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6684. //=========================== Stop Transaction Time ===============================================
  6685. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  6686. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6687. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6688. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6689. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6690. {
  6691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6692. {
  6693. tempIndex = ((gun_index==2) ? 1: 0);
  6694. }
  6695. else
  6696. {
  6697. tempIndex = gun_index;
  6698. }
  6699. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6700. {
  6701. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6702. {
  6703. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6704. }
  6705. }// END OF CHAdeMO_QUANTITY
  6706. }
  6707. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6708. {
  6709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6710. {
  6711. tempIndex = ((gun_index==2) ? 1: 0);
  6712. }
  6713. else
  6714. {
  6715. tempIndex = gun_index;
  6716. }
  6717. for (int index = 0; index < CCS_QUANTITY; index++)
  6718. {
  6719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6720. {
  6721. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6722. }
  6723. }// END OF CCS_QUANTITY
  6724. }
  6725. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6726. {
  6727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6728. {
  6729. tempIndex = ((gun_index==2) ? 1: 0);
  6730. }
  6731. else
  6732. {
  6733. tempIndex = gun_index;
  6734. }
  6735. for (int index = 0; index < GB_QUANTITY; index++)
  6736. {
  6737. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6738. {
  6739. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6740. }
  6741. }// END OF GB_QUANTITY
  6742. }
  6743. else if(gunType[gun_index] == GUN_TYPE_DO)
  6744. {
  6745. tempIndex = gun_index;
  6746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6747. {
  6748. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6749. {
  6750. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6751. }
  6752. }// END OF GB_QUANTITY
  6753. }
  6754. else
  6755. {
  6756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6757. {
  6758. tempIndex = 2;
  6759. }
  6760. else
  6761. {
  6762. tempIndex = gun_index;
  6763. }
  6764. for (int index = 0; index < AC_QUANTITY; index++)
  6765. {
  6766. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6767. {
  6768. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6769. }
  6770. }// END OF AC_QUANTITY
  6771. }
  6772. //================================================ Message create ====================================================
  6773. json_object *StopTransaction = json_object_new_object();
  6774. json_object *transactionDatas = json_object_new_array();
  6775. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6776. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6777. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6778. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6779. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6780. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6781. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6782. meterValueBufferQuery(gun_index, transactionDatas);
  6783. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6784. random_uuid(guid);
  6785. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6786. ,MESSAGE_TYPE_CALL
  6787. ,guid
  6788. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6789. json_object_put(StopTransaction);
  6790. #if 1 // for TempStopTransaction
  6791. //Delete TempStopTransaction
  6792. if((access(TempStopTransaction,F_OK))!=-1)
  6793. {
  6794. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6795. }
  6796. #endif
  6797. #if 1
  6798. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6799. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6800. {
  6801. result = PASS;
  6802. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6803. }
  6804. #endif
  6805. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6806. OCPP_insert_transaction_msg(NO, queuedata);
  6807. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6808. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6809. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6810. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6811. {
  6812. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6813. }
  6814. //for test
  6815. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6816. return result;
  6817. }
  6818. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6819. {
  6820. mtrace();
  6821. int result = FAIL;
  6822. char guid[37]={0};
  6823. char tempdata[65]={0};
  6824. int tempIndex = 0;
  6825. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6826. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6827. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6828. //set value
  6829. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6830. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6831. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6832. -1);
  6833. random_uuid(guid);
  6834. //UTC Date time
  6835. struct timeval tmnow;
  6836. struct tm *tm;
  6837. char buf[28];//, usec_buf[6];
  6838. gettimeofday(&tmnow, NULL);
  6839. time_t t;
  6840. t = time(NULL);
  6841. /*UTC time and date*/
  6842. tm = gmtime(&t);
  6843. if(dataType == ReadingContext_Sample_Clock)
  6844. {
  6845. struct tm *tmTarget;
  6846. struct timeb tbTarget;
  6847. tbTarget.time = mktime(tm);
  6848. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6849. tmTarget = gmtime(&tbTarget.time);
  6850. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6851. }
  6852. else
  6853. {
  6854. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6855. }
  6856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6857. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6858. //********************************(1)Current.Import L1************************************************/
  6859. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6860. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6861. (dataType == ReadingContext_Trigger))
  6862. {
  6863. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6865. {
  6866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6867. {
  6868. tempIndex = ((gun_index==2) ? 1: 0);
  6869. }
  6870. else
  6871. {
  6872. tempIndex = gun_index;
  6873. }
  6874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6875. {
  6876. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6877. {
  6878. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6879. }
  6880. }
  6881. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6882. }
  6883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6884. {
  6885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6886. {
  6887. tempIndex = ((gun_index==2) ? 1: 0);
  6888. }
  6889. else
  6890. {
  6891. tempIndex = gun_index;
  6892. }
  6893. for (int index = 0; index < CCS_QUANTITY; index++)
  6894. {
  6895. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6896. {
  6897. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6898. }
  6899. }
  6900. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6901. }
  6902. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6903. {
  6904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6905. {
  6906. tempIndex = ((gun_index==2) ? 1: 0);
  6907. }
  6908. else
  6909. {
  6910. tempIndex = gun_index;
  6911. }
  6912. for (int index = 0; index < GB_QUANTITY; index++)
  6913. {
  6914. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6915. {
  6916. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6917. }
  6918. }
  6919. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6920. }
  6921. else if(gunType[gun_index] == GUN_TYPE_DO)
  6922. {
  6923. tempIndex = gun_index;
  6924. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6925. {
  6926. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6927. {
  6928. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6929. }
  6930. }
  6931. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6932. }
  6933. else
  6934. {
  6935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6936. {
  6937. tempIndex = 2;
  6938. }
  6939. else
  6940. {
  6941. tempIndex = gun_index;
  6942. }
  6943. for (int index = 0; index < AC_QUANTITY; index++)
  6944. {
  6945. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6946. {
  6947. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6948. }
  6949. }
  6950. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6951. }
  6952. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6953. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6954. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6955. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6956. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6957. }
  6958. //********************************(2)Energy.Active.Import.Register ************************************************/
  6959. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6960. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6961. (dataType == ReadingContext_Trigger))
  6962. {
  6963. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6964. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6965. {
  6966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6967. {
  6968. tempIndex = ((gun_index==2) ? 1: 0);
  6969. }
  6970. else
  6971. {
  6972. tempIndex = gun_index;
  6973. }
  6974. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6975. {
  6976. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6977. {
  6978. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6979. }
  6980. }
  6981. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6982. }
  6983. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6984. {
  6985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6986. {
  6987. tempIndex = ((gun_index==2) ? 1: 0);
  6988. }
  6989. else
  6990. {
  6991. tempIndex = gun_index;
  6992. }
  6993. for (int index = 0; index < CCS_QUANTITY; index++)
  6994. {
  6995. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6996. {
  6997. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6998. }
  6999. }
  7000. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7001. }
  7002. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7003. {
  7004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7005. {
  7006. tempIndex = ((gun_index==2) ? 1: 0);
  7007. }
  7008. else
  7009. {
  7010. tempIndex = gun_index;
  7011. }
  7012. for (int index = 0; index < GB_QUANTITY; index++)
  7013. {
  7014. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7015. {
  7016. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  7017. }
  7018. }
  7019. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7020. }
  7021. else if(gunType[gun_index] == GUN_TYPE_DO)
  7022. {
  7023. tempIndex = gun_index;
  7024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7025. {
  7026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7027. {
  7028. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  7029. }
  7030. }
  7031. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7032. }
  7033. else
  7034. {
  7035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7036. {
  7037. tempIndex = 2;
  7038. }
  7039. else
  7040. {
  7041. tempIndex = gun_index;
  7042. }
  7043. for (int index = 0; index < AC_QUANTITY; index++)
  7044. {
  7045. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7046. {
  7047. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7048. }
  7049. }
  7050. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7051. }
  7052. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7053. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7054. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7055. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7056. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7057. }
  7058. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7059. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7060. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7061. (dataType == ReadingContext_Trigger))
  7062. {
  7063. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7064. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7065. {
  7066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7067. {
  7068. tempIndex = ((gun_index==2) ? 1: 0);
  7069. }
  7070. else
  7071. {
  7072. tempIndex = gun_index;
  7073. }
  7074. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7075. {
  7076. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7077. {
  7078. if(dataType == ReadingContext_Sample_Clock)
  7079. {
  7080. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7081. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7082. }
  7083. else if(dataType == ReadingContext_Sample_Periodic)
  7084. {
  7085. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7086. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7087. }
  7088. else
  7089. {
  7090. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7091. }
  7092. }
  7093. } // END OF FOR CHAdeMO_QUANTITY
  7094. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7095. }
  7096. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7097. {
  7098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7099. {
  7100. tempIndex = ((gun_index==2) ? 1: 0);
  7101. }
  7102. else
  7103. {
  7104. tempIndex = gun_index;
  7105. }
  7106. for (int index = 0; index < CCS_QUANTITY; index++)
  7107. {
  7108. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7109. {
  7110. if(dataType == ReadingContext_Sample_Clock)
  7111. {
  7112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7113. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7114. }
  7115. else if(dataType == ReadingContext_Sample_Periodic)
  7116. {
  7117. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7118. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7119. }
  7120. else
  7121. {
  7122. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7123. }
  7124. }
  7125. } // END OF CCS_QUANTITY
  7126. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7127. }
  7128. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7129. {
  7130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7131. {
  7132. tempIndex = ((gun_index==2) ? 1: 0);
  7133. }
  7134. else
  7135. {
  7136. tempIndex = gun_index;
  7137. }
  7138. for (int index = 0; index < GB_QUANTITY; index++)
  7139. {
  7140. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7141. {
  7142. if(dataType == ReadingContext_Sample_Clock)
  7143. {
  7144. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7145. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7146. }
  7147. else if(dataType == ReadingContext_Sample_Periodic)
  7148. {
  7149. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7150. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7151. }
  7152. else
  7153. {
  7154. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7155. }
  7156. }
  7157. } // END OF GB_QUANTITY
  7158. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7159. }
  7160. else if(gunType[gun_index] == GUN_TYPE_DO)
  7161. {
  7162. tempIndex = gun_index;
  7163. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7164. {
  7165. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7166. {
  7167. if(dataType == ReadingContext_Sample_Clock)
  7168. {
  7169. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7170. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7171. }
  7172. else if(dataType == ReadingContext_Sample_Periodic)
  7173. {
  7174. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7175. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7176. }
  7177. else
  7178. {
  7179. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7180. }
  7181. }
  7182. }
  7183. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7184. }
  7185. else
  7186. {
  7187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7188. {
  7189. tempIndex = 2;
  7190. }
  7191. else
  7192. {
  7193. tempIndex = gun_index;
  7194. }
  7195. for (int index = 0; index < AC_QUANTITY; index++)
  7196. {
  7197. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7198. {
  7199. if(dataType == ReadingContext_Sample_Clock)
  7200. {
  7201. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7202. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7203. }
  7204. else if(dataType == ReadingContext_Sample_Periodic)
  7205. {
  7206. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7207. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7208. }
  7209. else
  7210. {
  7211. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7212. }
  7213. }
  7214. }
  7215. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7216. }
  7217. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7218. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7220. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7222. }
  7223. //********************************(4)Power.Active.Import************************************************/
  7224. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7225. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7226. (dataType == ReadingContext_Trigger))
  7227. {
  7228. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7229. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7230. {
  7231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7232. {
  7233. tempIndex = ((gun_index==2) ? 1: 0);
  7234. }
  7235. else
  7236. {
  7237. tempIndex = gun_index;
  7238. }
  7239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7240. {
  7241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7242. {
  7243. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7244. }
  7245. } // END OF FOR
  7246. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7247. }
  7248. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7249. {
  7250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7251. {
  7252. tempIndex = ((gun_index==2) ? 1: 0);
  7253. }
  7254. else
  7255. {
  7256. tempIndex = gun_index;
  7257. }
  7258. for (int index = 0; index < CCS_QUANTITY; index++)
  7259. {
  7260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7261. {
  7262. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7263. }
  7264. }
  7265. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7266. }
  7267. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7268. {
  7269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7270. {
  7271. tempIndex = ((gun_index==2) ? 1: 0);
  7272. }
  7273. else
  7274. {
  7275. tempIndex = gun_index;
  7276. }
  7277. for (int index = 0; index < GB_QUANTITY; index++)
  7278. {
  7279. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7280. {
  7281. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7282. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7283. }
  7284. }
  7285. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7286. }
  7287. else if(gunType[gun_index] == GUN_TYPE_DO)
  7288. {
  7289. tempIndex = gun_index;
  7290. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7291. {
  7292. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7293. {
  7294. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7295. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7296. }
  7297. }
  7298. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7299. }
  7300. else
  7301. {
  7302. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7303. {
  7304. tempIndex = 2;
  7305. }
  7306. else
  7307. {
  7308. tempIndex = gun_index;
  7309. }
  7310. for (int index = 0; index < AC_QUANTITY; index++)
  7311. {
  7312. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7313. {
  7314. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7315. }
  7316. }
  7317. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7318. }
  7319. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7320. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7322. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7324. }
  7325. //***********************************************(5)VOLTAGE L1******************************************************/
  7326. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7327. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7328. (dataType == ReadingContext_Trigger))
  7329. {
  7330. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7331. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7332. {
  7333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7334. {
  7335. tempIndex = ((gun_index==2) ? 1: 0);
  7336. }
  7337. else
  7338. {
  7339. tempIndex = gun_index;
  7340. }
  7341. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7342. {
  7343. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7344. {
  7345. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7346. }
  7347. }
  7348. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7349. }
  7350. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7351. {
  7352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7353. {
  7354. tempIndex = ((gun_index==2) ? 1: 0);
  7355. }
  7356. else
  7357. {
  7358. tempIndex = gun_index;
  7359. }
  7360. for (int index = 0; index < CCS_QUANTITY; index++)
  7361. {
  7362. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7363. {
  7364. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7365. }
  7366. }
  7367. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7368. }
  7369. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7370. {
  7371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7372. {
  7373. tempIndex = ((gun_index==2) ? 1: 0);
  7374. }
  7375. else
  7376. {
  7377. tempIndex = gun_index;
  7378. }
  7379. for (int index = 0; index < GB_QUANTITY; index++)
  7380. {
  7381. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7382. {
  7383. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7384. }
  7385. }
  7386. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7387. }
  7388. else if(gunType[gun_index] == GUN_TYPE_DO)
  7389. {
  7390. tempIndex = gun_index;
  7391. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7392. {
  7393. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7394. {
  7395. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7396. }
  7397. }
  7398. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7399. }
  7400. else
  7401. {
  7402. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7403. {
  7404. tempIndex = 2;
  7405. }
  7406. else
  7407. {
  7408. tempIndex = gun_index;
  7409. }
  7410. for (int index = 0; index < AC_QUANTITY; index++)
  7411. {
  7412. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7413. {
  7414. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7415. }
  7416. }
  7417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7418. }
  7419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7422. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7423. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7424. }
  7425. //***********************************************(6)SOC******************************************************/
  7426. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7427. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7428. (dataType == ReadingContext_Trigger))
  7429. {
  7430. 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))
  7431. {
  7432. //idx_sample=5;
  7433. //sampledValue = NULL;
  7434. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7435. {
  7436. tempIndex = ((gun_index==2) ? 1: 0);
  7437. }
  7438. else
  7439. {
  7440. tempIndex = gun_index;
  7441. }
  7442. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7443. {
  7444. //tempIndex = ((gun_index==2) ? 1: 0);
  7445. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7446. {
  7447. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7448. {
  7449. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7450. }
  7451. }
  7452. }
  7453. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7454. {
  7455. //tempIndex = ((gun_index==2) ? 1: 0);
  7456. for (int index = 0; index < CCS_QUANTITY; index++)
  7457. {
  7458. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7459. {
  7460. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7461. }
  7462. }
  7463. }
  7464. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7465. {
  7466. //tempIndex = ((gun_index==2) ? 1: 0);
  7467. for (int index = 0; index < GB_QUANTITY; index++)
  7468. {
  7469. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7470. {
  7471. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7472. }
  7473. }
  7474. }
  7475. else if(gunType[gun_index] == GUN_TYPE_DO)
  7476. {
  7477. //tempIndex = ((gun_index==2) ? 1: 0);
  7478. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7479. {
  7480. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7481. {
  7482. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7483. }
  7484. }
  7485. }
  7486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7489. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7492. }
  7493. }
  7494. //********************************(7)Current.Import L2************************************************/
  7495. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7496. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7497. (dataType == ReadingContext_Trigger))
  7498. {
  7499. // Only for AC 3 phase
  7500. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7501. {
  7502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7503. {
  7504. tempIndex = 2;
  7505. }
  7506. else
  7507. {
  7508. tempIndex = gun_index;
  7509. }
  7510. for (int index = 0; index < AC_QUANTITY; index++)
  7511. {
  7512. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7513. {
  7514. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7515. }
  7516. }
  7517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7518. }
  7519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7522. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7524. }
  7525. //********************************(8)Current.Import L3************************************************/
  7526. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7527. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7528. (dataType == ReadingContext_Trigger))
  7529. {
  7530. // Only for AC 3 phase
  7531. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7532. {
  7533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7534. {
  7535. tempIndex = 2;
  7536. }
  7537. else
  7538. {
  7539. tempIndex = gun_index;
  7540. }
  7541. for (int index = 0; index < AC_QUANTITY; index++)
  7542. {
  7543. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7544. {
  7545. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7546. }
  7547. }
  7548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7549. }
  7550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7553. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7554. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7555. }
  7556. //***********************************************(9)VOLTAGE L2******************************************************/
  7557. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7558. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7559. (dataType == ReadingContext_Trigger))
  7560. {
  7561. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7562. {
  7563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7564. {
  7565. tempIndex = 2;
  7566. }
  7567. else
  7568. {
  7569. tempIndex = gun_index;
  7570. }
  7571. for (int index = 0; index < AC_QUANTITY; index++)
  7572. {
  7573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7574. {
  7575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7576. }
  7577. }
  7578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7579. }
  7580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7585. }
  7586. //***********************************************(10)VOLTAGE L3******************************************************/
  7587. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7588. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7589. (dataType == ReadingContext_Trigger))
  7590. {
  7591. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7592. {
  7593. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7594. {
  7595. tempIndex = 2;
  7596. }
  7597. else
  7598. {
  7599. tempIndex = gun_index;
  7600. }
  7601. for (int index = 0; index < AC_QUANTITY; index++)
  7602. {
  7603. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7604. {
  7605. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7606. }
  7607. }
  7608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7609. }
  7610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7615. }
  7616. //***********************************************(11)Current.Offered******************************************************/
  7617. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7618. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7619. (dataType == ReadingContext_Trigger))
  7620. {
  7621. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7622. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7623. {
  7624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7625. {
  7626. tempIndex = ((gun_index==2) ? 1: 0);
  7627. }
  7628. else
  7629. {
  7630. tempIndex = gun_index;
  7631. }
  7632. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7633. {
  7634. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7635. {
  7636. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7637. }
  7638. } // END OF FOR CHAdeMO_QUANTITY
  7639. }
  7640. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7641. {
  7642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7643. {
  7644. tempIndex = ((gun_index==2) ? 1: 0);
  7645. }
  7646. else
  7647. {
  7648. tempIndex = gun_index;
  7649. }
  7650. for (int index = 0; index < CCS_QUANTITY; index++)
  7651. {
  7652. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7653. {
  7654. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7655. }
  7656. } // END OF CCS_QUANTITY
  7657. }
  7658. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7659. {
  7660. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7661. {
  7662. tempIndex = ((gun_index==2) ? 1: 0);
  7663. }
  7664. else
  7665. {
  7666. tempIndex = gun_index;
  7667. }
  7668. for (int index = 0; index < GB_QUANTITY; index++)
  7669. {
  7670. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7671. {
  7672. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7673. }
  7674. } // END OF GB_QUANTITY
  7675. }
  7676. else if(gunType[gun_index] == GUN_TYPE_DO)
  7677. {
  7678. tempIndex = gun_index;
  7679. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7680. {
  7681. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7682. {
  7683. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7684. }
  7685. }
  7686. }
  7687. else
  7688. {
  7689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7690. {
  7691. tempIndex = 2;
  7692. }
  7693. else
  7694. {
  7695. tempIndex = gun_index;
  7696. }
  7697. for (int index = 0; index < AC_QUANTITY; index++)
  7698. {
  7699. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7700. {
  7701. uint16_t currentOffer;
  7702. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7703. {
  7704. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7705. }
  7706. else
  7707. {
  7708. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7709. }
  7710. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7711. }
  7712. }
  7713. }
  7714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7715. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7716. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7718. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7719. }
  7720. //***********************************************(12)Power.Offered******************************************************/
  7721. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7722. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7723. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7724. {
  7725. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7726. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7727. {
  7728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7729. {
  7730. tempIndex = ((gun_index==2) ? 1: 0);
  7731. }
  7732. else
  7733. {
  7734. tempIndex = gun_index;
  7735. }
  7736. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7737. {
  7738. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7739. {
  7740. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7741. }
  7742. } // END OF FOR CHAdeMO_QUANTITY
  7743. }
  7744. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7745. {
  7746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7747. {
  7748. tempIndex = ((gun_index==2) ? 1: 0);
  7749. }
  7750. else
  7751. {
  7752. tempIndex = gun_index;
  7753. }
  7754. for (int index = 0; index < CCS_QUANTITY; index++)
  7755. {
  7756. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7757. {
  7758. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7759. }
  7760. } // END OF CCS_QUANTITY
  7761. }
  7762. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7763. {
  7764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7765. {
  7766. tempIndex = ((gun_index==2) ? 1: 0);
  7767. }
  7768. else
  7769. {
  7770. tempIndex = gun_index;
  7771. }
  7772. for (int index = 0; index < GB_QUANTITY; index++)
  7773. {
  7774. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7775. {
  7776. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7777. }
  7778. } // END OF GB_QUANTITY
  7779. }
  7780. else if(gunType[gun_index] == GUN_TYPE_DO)
  7781. {
  7782. tempIndex = gun_index;
  7783. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7784. {
  7785. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7786. {
  7787. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7788. }
  7789. }
  7790. }
  7791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7796. }
  7797. // Message create ====================================================================================================
  7798. if(TRUE)
  7799. {
  7800. json_object *MeterValueReq = json_object_new_object();
  7801. json_object *MeterValues = json_object_new_array();
  7802. json_object *sampledValues = json_object_new_array();
  7803. json_object *sampledValuesBuffer = json_object_new_array();
  7804. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7805. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7806. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7807. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7808. {
  7809. json_object *MeterValue = json_object_new_object();
  7810. json_object *MeterValueBuffer = json_object_new_object();
  7811. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7812. {
  7813. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7814. {
  7815. json_object *sampledValue = json_object_new_object();
  7816. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7817. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7818. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7819. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7820. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7821. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7822. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7823. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7824. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7825. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7826. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7827. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7828. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7829. json_object_array_add(sampledValues, sampledValue);
  7830. // For StopTxn data
  7831. 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)) ||
  7832. ((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)))
  7833. {
  7834. json_object *sampledValue = json_object_new_object();
  7835. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7836. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7837. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7838. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7839. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7840. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7841. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7842. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7843. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7844. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7845. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7846. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7847. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7848. json_object_array_add(sampledValuesBuffer, sampledValue);
  7849. }
  7850. }
  7851. }
  7852. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7853. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7854. json_object_array_add(MeterValues, MeterValue);
  7855. // For StopTxn data
  7856. if((dataType != ReadingContext_Trigger) &&
  7857. (json_object_array_length(sampledValuesBuffer) > 0))
  7858. {
  7859. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7860. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  7861. if(meterValueBufferDataQuantity(gun_index, dataType) < 200)
  7862. meterValueBufferInsert(gun_index, dataType, ShmOCPP16Data->MeterValues[gun_index].TransactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  7863. else
  7864. meterValueBufferReplace(200, gun_index, dataType, ShmOCPP16Data->MeterValues[gun_index].TransactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  7865. json_object_put(MeterValueBuffer);
  7866. }
  7867. else
  7868. {
  7869. json_object_put(sampledValuesBuffer);
  7870. json_object_put(MeterValueBuffer);
  7871. }
  7872. }
  7873. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7874. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7875. ,gun_index + 1
  7876. ,MESSAGE_TYPE_CALL
  7877. ,guid
  7878. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7879. json_object_put(MeterValueReq);
  7880. }
  7881. // Put request guid to hash map
  7882. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7883. 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*/)
  7884. {
  7885. result = PASS;
  7886. //DEBUG_INFO("MeterValues mapitem pass\n");
  7887. }
  7888. if((dataType != ReadingContext_Trigger) &&
  7889. (dataType != ReadingContext_Sample_Clock) &&
  7890. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7891. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7892. else
  7893. {
  7894. if(FirstHeartBeat)
  7895. LWS_Send(queuedata +2);
  7896. }
  7897. return result;
  7898. }
  7899. int sendLogStatusNotificationRequest(char *status)
  7900. {
  7901. mtrace();
  7902. int result = PASS;
  7903. char message[4096]={0};
  7904. char guid[37]={0};
  7905. char tempdata[128]={0};
  7906. json_object *LogStatusNotification = json_object_new_object();
  7907. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7908. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7909. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7910. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7911. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7912. random_uuid(guid);
  7913. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7914. json_object_put(LogStatusNotification);
  7915. LWS_Send(message);
  7916. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7917. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7918. {
  7919. result = PASS;
  7920. }
  7921. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7922. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7923. return result;
  7924. }
  7925. int sendSecurityEventNotificationRequest()
  7926. {
  7927. mtrace();
  7928. int result = PASS;
  7929. char message[4096]={0};
  7930. char guid[37]={0};
  7931. char tempdata[128]={0};
  7932. json_object *SecurityEventNotification = json_object_new_object();
  7933. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7934. //Stop Transaction Time
  7935. struct timeval tmnow;
  7936. struct tm *tm;
  7937. gettimeofday(&tmnow, NULL);
  7938. time_t t;
  7939. t = time(NULL);
  7940. /*UTC time and date*/
  7941. tm = gmtime(&t);
  7942. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7943. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7944. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7945. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7946. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7947. random_uuid(guid);
  7948. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7949. json_object_put(SecurityEventNotification);
  7950. LWS_Send(message);
  7951. sprintf(tempdata, "SecurityEventNotification,0");
  7952. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7953. {
  7954. result = PASS;
  7955. }
  7956. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7957. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7958. return result;
  7959. }
  7960. int sendSignCertificateRequest()
  7961. {
  7962. mtrace();
  7963. int result = PASS;
  7964. char message[4096]={0};
  7965. char guid[37]={0};
  7966. char tempdata[128]={0};
  7967. json_object *SignCertificate = json_object_new_object();
  7968. DEBUG_INFO("sendSignCertificateRequest...\n");
  7969. // Read csr file content
  7970. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7971. FILE *fp=fopen(CSR_CP,"r");
  7972. char *line = NULL;
  7973. size_t len = 0;
  7974. while(getline(&line, &len, fp) != -1)
  7975. {
  7976. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7977. {
  7978. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7979. }
  7980. }
  7981. fclose(fp);
  7982. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7983. random_uuid(guid);
  7984. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7985. json_object_put(SignCertificate);
  7986. LWS_Send(message);
  7987. sprintf(tempdata, "SignCertificate,0");
  7988. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7989. {
  7990. result = PASS;
  7991. }
  7992. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7993. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7994. return result;
  7995. }
  7996. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7997. {
  7998. mtrace();
  7999. int result = PASS;
  8000. char message[4096]={0};
  8001. char guid[37]={0};
  8002. char tempdata[128]={0};
  8003. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  8004. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  8005. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  8006. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  8007. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  8008. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  8009. random_uuid(guid);
  8010. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8011. json_object_put(SignedFirmwareStatusNotification);
  8012. LWS_Send(message);
  8013. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  8014. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8015. {
  8016. result = PASS;
  8017. }
  8018. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  8019. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  8020. return result;
  8021. }
  8022. //==========================================
  8023. // send confirm routine
  8024. //==========================================
  8025. int sendCancelReservationConfirmation(char *uuid,char *payload)
  8026. {
  8027. mtrace();
  8028. int result = FAIL;
  8029. char message[100]={0};
  8030. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8031. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8032. LWS_Send(message);
  8033. result = TRUE;
  8034. return result;
  8035. }
  8036. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  8037. {
  8038. mtrace();
  8039. int result = FAIL;
  8040. char message[100]={0};
  8041. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8042. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8043. LWS_Send(message);
  8044. result = TRUE;
  8045. return result;
  8046. }
  8047. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8048. {
  8049. mtrace();
  8050. int result = FAIL;
  8051. char message[100]={0};
  8052. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8053. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8054. LWS_Send(message);
  8055. result = TRUE;
  8056. return result;
  8057. }
  8058. int sendClearCacheConfirmation(char *uuid,char *payload)
  8059. {
  8060. mtrace();
  8061. int result = FAIL;
  8062. char message[500]={0};
  8063. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8064. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8065. LWS_Send(message);
  8066. return result;
  8067. }
  8068. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8069. {
  8070. mtrace();
  8071. int result = FAIL;
  8072. char message[500]={0};
  8073. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8074. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8075. LWS_Send(message);
  8076. return result;
  8077. }
  8078. int sendDataTransferConfirmation(char *uuid,char *payload)
  8079. {
  8080. mtrace();
  8081. char statusStr[20]={0};
  8082. char dataStr[10]={0};
  8083. char sstr[20]={0};
  8084. int c = 0;
  8085. char *loc;
  8086. int result = FAIL;
  8087. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8088. /**********************status**************************/
  8089. loc = strstr(payload, "status");
  8090. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8091. c = 0;
  8092. while (loc[3+strlen("status")+c] != '\"')
  8093. {
  8094. sstr[c] = loc[3+strlen("status")+c];
  8095. c++;
  8096. }
  8097. sstr[c] = '\0';
  8098. strcpy(statusStr, sstr);
  8099. /**********************data**************************/
  8100. loc = strstr(payload, "data");
  8101. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8102. c = 0;
  8103. while (loc[3+strlen("data")+c] != '\"')
  8104. {
  8105. sstr[c] = loc[3+strlen("data")+c];
  8106. c++;
  8107. }
  8108. sstr[c] = '\0';
  8109. strcpy(dataStr, sstr);
  8110. return result;
  8111. }
  8112. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8113. {
  8114. mtrace();
  8115. int result = FAIL;
  8116. char message[1000]={0};
  8117. int CompositeScheduleIndex = 0;
  8118. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8119. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8120. if(nPeriod == 0)
  8121. {
  8122. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8123. {
  8124. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8125. ,MESSAGE_TYPE_CALLRESULT
  8126. ,uuid
  8127. ,payload
  8128. ,connectorIdInt);
  8129. }
  8130. else
  8131. {
  8132. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8133. ,MESSAGE_TYPE_CALLRESULT
  8134. ,uuid
  8135. ,payload
  8136. ,connectorIdInt
  8137. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8138. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8139. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8140. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8141. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8142. }
  8143. }
  8144. else
  8145. {
  8146. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8147. ,MESSAGE_TYPE_CALLRESULT
  8148. ,uuid
  8149. ,payload
  8150. ,connectorIdInt
  8151. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8152. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8153. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8154. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8155. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8156. {
  8157. if (idx_sample == 0)
  8158. {
  8159. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8160. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8161. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8162. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8163. }
  8164. else
  8165. {
  8166. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8167. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8168. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8169. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8170. }
  8171. }
  8172. sprintf(message + strlen(message), "]}}]");
  8173. }
  8174. LWS_Send(message);
  8175. result = TRUE;
  8176. return result;
  8177. }
  8178. int sendGetConfigurationConfirmation(char *uuid)
  8179. {
  8180. mtrace();
  8181. int result = FAIL;
  8182. int MaxKeySupported = 0;
  8183. int sentConfigurationNumber= 0;
  8184. int sentunConfigurationNumber= 0;
  8185. char message[1024*10]={0};
  8186. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8187. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8188. //configuration key
  8189. json_object *GetConfiguration = json_object_new_object();
  8190. json_object *configurationKey = json_object_new_array();
  8191. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8192. {
  8193. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8194. {
  8195. json_object *keyValue = json_object_new_object();
  8196. json_object_object_add(keyValue, "key", json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key));
  8197. 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));
  8198. json_object_object_add(keyValue, "value", json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value));
  8199. json_object_array_add(configurationKey, keyValue);
  8200. sentConfigurationNumber = sentConfigurationNumber + 1;
  8201. }
  8202. }
  8203. json_object *unknownKey = json_object_new_array();
  8204. if(UnknownKeynum != 0)
  8205. {
  8206. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8207. {
  8208. DEBUG_INFO("unknown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8209. json_object_array_add(unknownKey, json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item));
  8210. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8211. }
  8212. }
  8213. if((sentConfigurationNumber>0) && (sentunConfigurationNumber>0))
  8214. {
  8215. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  8216. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  8217. }
  8218. else if(sentConfigurationNumber>0)
  8219. {
  8220. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  8221. json_object_put(unknownKey);
  8222. }
  8223. else
  8224. {
  8225. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  8226. json_object_put(configurationKey);
  8227. }
  8228. sprintf(message,"[%d,\"%s\",%s]"
  8229. ,MESSAGE_TYPE_CALLRESULT
  8230. ,uuid
  8231. ,json_object_to_json_string_ext(GetConfiguration, JSON_C_TO_STRING_PLAIN));
  8232. json_object_put(GetConfiguration);
  8233. LWS_Send(message);
  8234. return result;
  8235. }
  8236. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8237. {
  8238. mtrace();
  8239. int result = FAIL;
  8240. char message[400]={0};
  8241. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8242. if(strcmp(payload,"")==0)
  8243. {
  8244. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8245. }
  8246. else
  8247. {
  8248. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8249. }
  8250. LWS_Send(message);
  8251. result = TRUE;
  8252. return result;
  8253. }
  8254. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8255. {
  8256. mtrace();
  8257. int result = FAIL;
  8258. char message[80]={0};
  8259. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8260. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8261. LWS_Send(message);
  8262. result = TRUE;
  8263. return result;
  8264. }
  8265. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8266. {
  8267. mtrace();
  8268. int result = FAIL;
  8269. char message[80]={0};
  8270. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8271. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8272. LWS_Send(message);
  8273. result = TRUE;
  8274. return result;
  8275. }
  8276. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8277. {
  8278. mtrace();
  8279. int result = FAIL;
  8280. char message[80]={0};
  8281. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8282. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8283. LWS_Send(message);
  8284. result = TRUE;
  8285. return result;
  8286. }
  8287. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8288. {
  8289. mtrace();
  8290. int result = FAIL;
  8291. char message[80]={0};
  8292. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8293. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8294. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8295. LWS_Send(message);
  8296. result = TRUE;
  8297. return result;
  8298. }
  8299. int sendResetConfirmation(char *uuid,char *payload)
  8300. {
  8301. mtrace();
  8302. int result = FAIL;
  8303. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8304. char message[80]={0};
  8305. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8306. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8307. LWS_Send(message);
  8308. result = TRUE;
  8309. return result;
  8310. }
  8311. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8312. {
  8313. mtrace();
  8314. int result = FAIL;
  8315. char message[500]={0};
  8316. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8317. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8318. LWS_Send(message);
  8319. result = TRUE;
  8320. return result;
  8321. }
  8322. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8323. {
  8324. mtrace();
  8325. int result = FAIL;
  8326. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8327. char message[80]={0};
  8328. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8329. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8330. LWS_Send(message);
  8331. result = TRUE;
  8332. return result;
  8333. }
  8334. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8335. {
  8336. mtrace();
  8337. int result = FAIL;
  8338. char message[80]={0};
  8339. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8340. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8341. LWS_Send(message);
  8342. result = TRUE;
  8343. return result;
  8344. }
  8345. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8346. {
  8347. mtrace();
  8348. int result = FAIL;
  8349. char message[80]={0};
  8350. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8351. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8352. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8353. LWS_Send(message);
  8354. result = TRUE;
  8355. return result;
  8356. }
  8357. int sendUpdateFirmwareConfirmation(char *uuid)
  8358. {
  8359. mtrace();
  8360. int result = FAIL;
  8361. char message[60]={0};
  8362. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8363. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8364. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8365. LWS_Send(message);
  8366. result = TRUE;
  8367. return result;
  8368. }
  8369. int sendCertificateSignedConfirmation(char *uuid)
  8370. {
  8371. mtrace();
  8372. int result = PASS;
  8373. char message[4096]={0};
  8374. json_object *CertificateSigned = json_object_new_object();
  8375. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8376. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8377. sprintf(message,"[%d,\"%s\",%s]"
  8378. ,MESSAGE_TYPE_CALLRESULT
  8379. ,uuid
  8380. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8381. json_object_put(CertificateSigned);
  8382. LWS_Send(message);
  8383. return result;
  8384. }
  8385. int sendDeleteCertificateConfirmation(char *uuid)
  8386. {
  8387. mtrace();
  8388. int result = PASS;
  8389. char message[4096]={0};
  8390. json_object *DeleteCertificate = json_object_new_object();
  8391. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8392. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8393. sprintf(message,"[%d,\"%s\",%s]"
  8394. ,MESSAGE_TYPE_CALLRESULT
  8395. ,uuid
  8396. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8397. json_object_put(DeleteCertificate);
  8398. LWS_Send(message);
  8399. return result;
  8400. }
  8401. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8402. {
  8403. mtrace();
  8404. int result = PASS;
  8405. char message[4096]={0};
  8406. json_object *ExtendedTriggerMessage = json_object_new_object();
  8407. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8408. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8409. sprintf(message,"[%d,\"%s\",%s]"
  8410. ,MESSAGE_TYPE_CALLRESULT
  8411. ,uuid
  8412. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8413. json_object_put(ExtendedTriggerMessage);
  8414. LWS_Send(message);
  8415. return result;
  8416. }
  8417. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8418. {
  8419. mtrace();
  8420. int result = PASS;
  8421. char message[4096]={0};
  8422. json_object *GetInstalledCertificateIds = json_object_new_object();
  8423. json_object *certificateHashDataDatas = json_object_new_array();
  8424. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8425. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8426. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8427. {
  8428. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8429. {
  8430. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8431. {
  8432. json_object *certificateHashData = json_object_new_object();
  8433. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8434. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8435. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8436. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8437. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8438. }
  8439. }
  8440. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8441. }
  8442. else
  8443. {
  8444. json_object_put(certificateHashDataDatas);
  8445. }
  8446. sprintf(message,"[%d,\"%s\",%s]"
  8447. ,MESSAGE_TYPE_CALLRESULT
  8448. ,uuid
  8449. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8450. json_object_put(GetInstalledCertificateIds);
  8451. LWS_Send(message);
  8452. return result;
  8453. }
  8454. int sendGetLogConfirmation(char *uuid)
  8455. {
  8456. mtrace();
  8457. int result = PASS;
  8458. char message[4096]={0};
  8459. json_object *GetLog = json_object_new_object();
  8460. DEBUG_INFO("sendGetLogConfirmation...\n");
  8461. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8462. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8463. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8464. sprintf(message,"[%d,\"%s\",%s]"
  8465. ,MESSAGE_TYPE_CALLRESULT
  8466. ,uuid
  8467. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8468. json_object_put(GetLog);
  8469. LWS_Send(message);
  8470. return result;
  8471. }
  8472. int sendInstallCertificateConfirmation(char *uuid)
  8473. {
  8474. mtrace();
  8475. int result = PASS;
  8476. char message[4096]={0};
  8477. json_object *InstallCertificate = json_object_new_object();
  8478. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8479. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8480. sprintf(message,"[%d,\"%s\",%s]"
  8481. ,MESSAGE_TYPE_CALLRESULT
  8482. ,uuid
  8483. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8484. json_object_put(InstallCertificate);
  8485. LWS_Send(message);
  8486. return result;
  8487. }
  8488. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8489. {
  8490. mtrace();
  8491. int result = PASS;
  8492. char message[4096]={0};
  8493. json_object *SignedUpdateFirmware = json_object_new_object();
  8494. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8495. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8496. sprintf(message,"[%d,\"%s\",%s]"
  8497. ,MESSAGE_TYPE_CALLRESULT
  8498. ,uuid
  8499. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8500. json_object_put(SignedUpdateFirmware);
  8501. LWS_Send(message);
  8502. return result;
  8503. }
  8504. int sendUnknownConfirmation(char *uuid)
  8505. {
  8506. mtrace();
  8507. int result = PASS;
  8508. char message[256]={0};
  8509. DEBUG_INFO("sendUnknownConfirmation...\n");
  8510. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8511. LWS_Send(message);
  8512. return result;
  8513. }
  8514. //==========================================
  8515. // Handle server request routine Start
  8516. //==========================================
  8517. int handleCancelReservationRequest(char *uuid, char *payload)
  8518. {
  8519. mtrace();
  8520. int result = FAIL;
  8521. int gunNO = 0;
  8522. int reservationIdInt = -1;
  8523. char comfirmstr[20];
  8524. DEBUG_INFO("handleCancelReservationRequest...\n");
  8525. json_object *CancelReservation;
  8526. CancelReservation = json_tokener_parse(payload);
  8527. if(!is_error(CancelReservation))
  8528. {
  8529. // Required data
  8530. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8531. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8532. }
  8533. json_object_put(CancelReservation);
  8534. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8535. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8536. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8537. if(reservationIdInt != -1)
  8538. {
  8539. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8540. //check Transaction active
  8541. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8542. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8543. {
  8544. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8545. {
  8546. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8547. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8548. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8549. {
  8550. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8551. }
  8552. else
  8553. {
  8554. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8555. }
  8556. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8557. goto end;
  8558. }
  8559. }
  8560. for (int index = 0; index < CCS_QUANTITY; index++)
  8561. {
  8562. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8563. {
  8564. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8565. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8566. if(gunType[2] == GUN_TYPE_CCS)
  8567. {
  8568. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8569. }
  8570. else
  8571. {
  8572. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8573. }
  8574. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8575. goto end;
  8576. }
  8577. }
  8578. for (int index = 0; index < GB_QUANTITY; index++)
  8579. {
  8580. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8581. {
  8582. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8583. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8584. if(gunType[2] == GUN_TYPE_GBT)
  8585. {
  8586. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8587. }
  8588. else
  8589. {
  8590. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8591. }
  8592. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8593. goto end;
  8594. }
  8595. }
  8596. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8597. {
  8598. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8599. {
  8600. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8601. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8602. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8603. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8604. goto end;
  8605. }
  8606. }
  8607. for (int index = 0; index < AC_QUANTITY; index++)
  8608. {
  8609. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8610. {
  8611. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8612. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8613. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8614. {
  8615. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8616. }
  8617. else
  8618. {
  8619. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8620. }
  8621. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8622. goto end;
  8623. }
  8624. }
  8625. }
  8626. //The reservationId does NOT match the reservationId
  8627. sendCancelReservationConfirmation(uuid, comfirmstr);
  8628. end:
  8629. // Fill in ocpp packet uuid
  8630. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8631. return result;
  8632. }
  8633. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8634. {
  8635. mtrace();
  8636. int result = FAIL;
  8637. int gunIndex = -1;
  8638. char typeStr[16]={0};
  8639. char comfirmstr[20];
  8640. int specificId = FALSE;
  8641. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8642. json_object *ChangeAvailability;
  8643. ChangeAvailability = json_tokener_parse(payload);
  8644. if(!is_error(ChangeAvailability))
  8645. {
  8646. // Required data
  8647. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8648. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8649. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8650. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8651. }
  8652. json_object_put(ChangeAvailability);
  8653. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8654. {
  8655. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8656. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8657. }
  8658. else if(gunIndex == 0)
  8659. {
  8660. for(int i=0; i < gunTotalNumber; i++)
  8661. {
  8662. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8663. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8664. }
  8665. }
  8666. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8667. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8668. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8669. {
  8670. specificId = TRUE;
  8671. }
  8672. if(specificId == FALSE)
  8673. goto end;
  8674. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8675. {
  8676. //----------------------gunIndex is 0 ------------------------------------------------//
  8677. if(gunIndex == 0)
  8678. {
  8679. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8680. {
  8681. for(int i=0; i < gunTotalNumber; i++)
  8682. {
  8683. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8684. {
  8685. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8686. {
  8687. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8688. {
  8689. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8690. goto end;
  8691. }
  8692. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8693. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8694. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8695. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8696. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8697. {
  8698. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8699. goto end;
  8700. }
  8701. }
  8702. }//END FOR CHAdeMO_QUANTITY
  8703. for (int index = 0; index < CCS_QUANTITY; index++)
  8704. {
  8705. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8706. {
  8707. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8708. {
  8709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8710. goto end;
  8711. }
  8712. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8713. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8714. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8715. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8716. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8717. {
  8718. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8719. goto end;
  8720. }
  8721. }
  8722. }//END FOR CCS_QUANTITY
  8723. for (int index = 0; index < GB_QUANTITY; index++)
  8724. {
  8725. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8726. {
  8727. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8728. {
  8729. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8730. goto end;
  8731. }
  8732. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8733. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8734. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8735. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8736. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8737. {
  8738. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8739. goto end;
  8740. }
  8741. }
  8742. }// END FOR GB_QUANTITY
  8743. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8744. {
  8745. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8746. {
  8747. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8748. {
  8749. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8750. goto end;
  8751. }
  8752. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8753. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8754. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8755. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8756. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8757. {
  8758. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8759. goto end;
  8760. }
  8761. }
  8762. }// END FOR GENERAL_GUN_QUANTITY
  8763. for (int index = 0; index < AC_QUANTITY; index++)
  8764. {
  8765. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8766. {
  8767. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8768. {
  8769. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8770. goto end;
  8771. }
  8772. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8773. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8774. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8775. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8776. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8777. {
  8778. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8779. goto end;
  8780. }
  8781. }
  8782. }//END FOR AC_QUANTITY
  8783. }// END FOR gunTotalNumber
  8784. }
  8785. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8786. {
  8787. for(int i=0; i < gunTotalNumber; i++)
  8788. {
  8789. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8790. {
  8791. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8792. goto end;
  8793. }
  8794. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8795. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8796. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8797. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8798. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8799. {
  8800. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8801. goto end;
  8802. }
  8803. }
  8804. }
  8805. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8806. goto end;
  8807. }
  8808. //----------------------gunIndex is not 0 ------------------------------------------------//
  8809. //check Transaction active
  8810. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8811. {
  8812. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8813. {
  8814. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8815. {
  8816. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8817. goto end;
  8818. }
  8819. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8820. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8821. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8822. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8823. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8824. {
  8825. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8826. goto end;
  8827. }
  8828. else
  8829. {
  8830. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8831. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8832. goto end;
  8833. }
  8834. }
  8835. }//END FOR CHAdeMO_QUANTITY
  8836. for (int index = 0; index < CCS_QUANTITY; index++)
  8837. {
  8838. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8839. {
  8840. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8841. {
  8842. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8843. goto end;
  8844. }
  8845. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8846. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8847. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8848. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8849. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8850. {
  8851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8852. goto end;
  8853. }
  8854. else
  8855. {
  8856. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8857. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8858. goto end;
  8859. }
  8860. }
  8861. }//END FOR CCS_QUANTITY
  8862. for (int index = 0; index < GB_QUANTITY; index++)
  8863. {
  8864. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8865. {
  8866. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8867. {
  8868. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8869. goto end;
  8870. }
  8871. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8872. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8873. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8874. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8875. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8876. {
  8877. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8878. goto end;
  8879. }
  8880. else
  8881. {
  8882. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8883. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8884. goto end;
  8885. }
  8886. }
  8887. }// END FOR GB_QUANTITY
  8888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8889. {
  8890. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8891. {
  8892. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8893. {
  8894. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8895. goto end;
  8896. }
  8897. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8898. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8899. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8900. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8901. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8902. {
  8903. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8904. goto end;
  8905. }
  8906. else
  8907. {
  8908. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8909. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8910. goto end;
  8911. }
  8912. }
  8913. }// END FOR GENERAL_GUN_QUANTITY
  8914. for (int index = 0; index < AC_QUANTITY; index++)
  8915. {
  8916. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8917. {
  8918. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8919. {
  8920. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8921. goto end;
  8922. }
  8923. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8924. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8925. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8926. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8927. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8928. {
  8929. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8930. goto end;
  8931. }
  8932. else
  8933. {
  8934. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8935. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8936. goto end;
  8937. }
  8938. }
  8939. }//END FOR AC_QUANTITY
  8940. }//END FOR AvailabilityTypeStr[Inoperative]
  8941. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8942. {
  8943. //----------------------gunIndex is 0 ------------------------------------------------//
  8944. if(gunIndex == 0)
  8945. {
  8946. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8947. {
  8948. for(int i=0; i < gunTotalNumber; i++)
  8949. {
  8950. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8951. {
  8952. 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
  8953. {
  8954. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8955. goto end;
  8956. }
  8957. }//END FOR CHAdeMO_QUANTITY
  8958. for (int index = 0; index < CCS_QUANTITY; index++)
  8959. {
  8960. 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
  8961. {
  8962. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8963. goto end;
  8964. }
  8965. }//END FOR CCS_QUANTITY
  8966. for (int index = 0; index < GB_QUANTITY; index++)
  8967. {
  8968. 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
  8969. {
  8970. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8971. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8972. goto end;
  8973. }
  8974. }// END FOR GB_QUANTITY
  8975. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8976. {
  8977. 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
  8978. {
  8979. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8980. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8981. goto end;
  8982. }
  8983. }// END FOR GENERAL_GUN_QUANTITY
  8984. for (int index = 0; index < AC_QUANTITY; index++)
  8985. {
  8986. 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
  8987. {
  8988. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8989. goto end;
  8990. }
  8991. }//END FOR CHAdeMO_QUANTITY
  8992. }// END FOR gunTotalNumber
  8993. }
  8994. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8995. {
  8996. for(int i=0; i < gunTotalNumber; i++)
  8997. {
  8998. for (int index = 0; index < AC_QUANTITY; index++)
  8999. {
  9000. 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
  9001. {
  9002. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9003. goto end;
  9004. }
  9005. }//END FOR CHAdeMO_QUANTITY
  9006. } // END FOR gunTotalNumber
  9007. }
  9008. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9009. goto end;
  9010. }
  9011. //----------------------gunIndex is not 0 ------------------------------------------------//
  9012. //check Transaction active
  9013. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9014. {
  9015. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9016. {
  9017. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9018. goto end;
  9019. }
  9020. }//END FOR CHAdeMO_QUANTITY
  9021. for (int index = 0; index < CCS_QUANTITY; index++)
  9022. {
  9023. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9024. {
  9025. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9026. goto end;
  9027. }
  9028. }//END FOR CCS_QUANTITY
  9029. for (int index = 0; index < GB_QUANTITY; index++)
  9030. {
  9031. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9032. {
  9033. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9034. goto end;
  9035. }
  9036. }// END FOR GB_QUANTITY
  9037. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9038. {
  9039. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9040. {
  9041. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9042. goto end;
  9043. }
  9044. }// END FOR GENERAL_GUN_QUANTITY
  9045. for (int index = 0; index < AC_QUANTITY; index++)
  9046. {
  9047. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9048. {
  9049. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9050. goto end;
  9051. }
  9052. }//END FOR AC_QUANTITY
  9053. }//END FOR AvailabilityTypeStr[Operative]
  9054. end:
  9055. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9056. {
  9057. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9058. }
  9059. else
  9060. {
  9061. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9062. }
  9063. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9064. {
  9065. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9066. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9067. }
  9068. else if(gunIndex == 0)
  9069. {
  9070. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9071. {
  9072. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9073. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9074. }
  9075. }
  9076. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9077. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9078. return result;
  9079. }
  9080. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9081. {
  9082. mtrace();
  9083. int valueInvalid = NO;
  9084. int result = FAIL;
  9085. char keystr[40]={0};
  9086. char valuestr[501]={0}; //value should be limited in 500 bytes
  9087. char comfirmstr[20]={0};
  9088. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9089. json_object *ChangeConfiguration;
  9090. ChangeConfiguration = json_tokener_parse(payload);
  9091. if(!is_error(ChangeConfiguration))
  9092. {
  9093. // Required data
  9094. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9095. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9096. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9097. {
  9098. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9099. }
  9100. else
  9101. {
  9102. valueInvalid = YES;
  9103. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9104. }
  9105. }
  9106. json_object_put(ChangeConfiguration);
  9107. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9108. {
  9109. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9110. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9111. }
  9112. else
  9113. {
  9114. int status = setKeyValue(keystr, valuestr);
  9115. switch(status)
  9116. {
  9117. case ConfigurationStatus_Accepted:
  9118. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9119. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9120. StoreConfigurationTable();
  9121. break;
  9122. case RebootRequired:
  9123. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9124. StoreConfigurationTable();
  9125. break;
  9126. case NotSupported:
  9127. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9128. break;
  9129. case ConfigurationStatus_Rejected:
  9130. default:
  9131. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9132. break;
  9133. }
  9134. }
  9135. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9136. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9137. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9138. {
  9139. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9140. SetOcppConnStatus(FALSE);
  9141. }
  9142. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9143. {
  9144. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9145. }
  9146. return result;
  9147. }
  9148. int handleClearCacheRequest(char *uuid, char *payload)
  9149. {
  9150. mtrace();
  9151. int result = FAIL;
  9152. char comfirmstr[20];
  9153. char rmFileCmd[100]={0};
  9154. struct stat stats;
  9155. DEBUG_INFO("handleClearCacheRequest...\n");
  9156. stat("/Storage/OCPP", &stats);
  9157. // Check for directory existence
  9158. if (S_ISDIR(stats.st_mode) == 1)
  9159. {}
  9160. else
  9161. {
  9162. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9163. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9164. system(rmFileCmd);
  9165. }
  9166. if(OCPP_cleanLocalCache())
  9167. {
  9168. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9169. }
  9170. else
  9171. {
  9172. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9173. }
  9174. sendClearCacheConfirmation(uuid, comfirmstr);
  9175. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9176. return result;
  9177. }
  9178. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9179. {
  9180. mtrace();
  9181. int result = FAIL;
  9182. int resultRename;
  9183. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9184. char chargingProfilePurposeStr[26]={0};
  9185. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9186. char tempchargingProfilePurposeStr[26]={0};
  9187. char str[100]={0};
  9188. char fname[200]={0};
  9189. char comfirmstr[20]={0};
  9190. char word[1600]={0};
  9191. int clearflag = FALSE;
  9192. int chargingProfileIdIsNULL = FALSE;
  9193. int connectorIsNULL = FALSE;
  9194. int chargingProfilePurposeIsNULL = FALSE;
  9195. int stackLevelIsNULL = FALSE;
  9196. //int GotoEnd = FALSE;
  9197. FILE *fptr1, *fptr2;
  9198. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9199. int n_chargingProfile=0;
  9200. int isEmptyFile = FALSE;
  9201. char sLineWord[1600]={0};
  9202. char chargingProfiles[10][100]={0};
  9203. int ChargeProfileCount = 0;
  9204. int ch;
  9205. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9206. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9207. json_object *ClearChargingProfile;
  9208. ClearChargingProfile = json_tokener_parse(payload);
  9209. if(!is_error(ClearChargingProfile))
  9210. {
  9211. // Optional data
  9212. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9213. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9214. else
  9215. chargingProfileIdIsNULL = TRUE;
  9216. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9217. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9218. else
  9219. connectorIsNULL = TRUE;
  9220. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9221. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9222. else
  9223. chargingProfilePurposeIsNULL = TRUE;
  9224. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9225. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9226. else
  9227. stackLevelIsNULL = TRUE;
  9228. }
  9229. json_object_put(ClearChargingProfile);
  9230. if(connectorIdInt > 0)
  9231. {
  9232. if(chargingProfilePurposeIsNULL == TRUE)
  9233. {
  9234. int m = 0;
  9235. memset(fname, 0, ARRAY_SIZE(fname));
  9236. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9237. if((access(fname,F_OK))!=-1)
  9238. {
  9239. strcpy(chargingProfiles[m], fname);
  9240. m = m + 1;
  9241. }
  9242. memset(fname, 0, ARRAY_SIZE(fname));
  9243. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9244. if((access(fname,F_OK))!=-1)
  9245. {
  9246. strcpy(chargingProfiles[m], fname);
  9247. m = m + 1;
  9248. }
  9249. ChargeProfileCount = m;
  9250. }
  9251. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9252. {
  9253. //strcpy(fname, TxDefaultProfile_1_JSON);
  9254. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9255. if((access(fname,F_OK))!=-1)
  9256. {
  9257. strcpy(chargingProfiles[0], fname);
  9258. ChargeProfileCount = 1;
  9259. }
  9260. }
  9261. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9262. {
  9263. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9264. if((access(fname,F_OK))!=-1)
  9265. {
  9266. strcpy(chargingProfiles[0], fname);
  9267. ChargeProfileCount = 1;
  9268. }
  9269. //strcpy(fname, TxProfile_1_JSON);
  9270. }
  9271. }
  9272. else // Check all Charging Profiles
  9273. {
  9274. int i = 0;
  9275. char fnametemp[200]={0};
  9276. ChargeProfileCount = 0;
  9277. //Check ChargePointMaxProfile.json exit
  9278. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9279. {
  9280. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9281. i = i + 1;
  9282. }
  9283. //Check TxDefaultProfile_0.json exit
  9284. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9285. {
  9286. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9287. i = i + 1;
  9288. }
  9289. //Check TxDefaultProfile_%d.json
  9290. for(int j=1; j <= gunTotalNumber; j++)
  9291. {
  9292. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9293. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9294. if((access(fnametemp,F_OK))!=-1)
  9295. {
  9296. strcpy(chargingProfiles[i], fnametemp);
  9297. i = i + 1;
  9298. }
  9299. }
  9300. //Check TxProfile_%d.json
  9301. for(int j=1; j <= gunTotalNumber; j++)
  9302. {
  9303. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9304. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9305. if((access(fnametemp,F_OK))!=-1)
  9306. {
  9307. strcpy(chargingProfiles[i], fnametemp);
  9308. i = i + 1;
  9309. }
  9310. }
  9311. ChargeProfileCount = i;
  9312. }// End connectorIsNULL is TRUE
  9313. if(ChargeProfileCount == 0)
  9314. {
  9315. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9316. goto end;
  9317. }
  9318. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9319. {
  9320. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9321. goto end;
  9322. }
  9323. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9324. {
  9325. memset(str, 0, ARRAY_SIZE(str));
  9326. // clear temp file
  9327. sprintf(str,"rm -f %s",temp);
  9328. system(str);
  9329. for(int k=0; k < ChargeProfileCount; k++)
  9330. {
  9331. memset(str, 0, ARRAY_SIZE(str));
  9332. //clear file in C
  9333. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9334. system(str);
  9335. }
  9336. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9337. goto end;
  9338. }
  9339. else if(connectorIsNULL == TRUE)
  9340. {
  9341. for(int k=0; k < ChargeProfileCount; k++)
  9342. {
  9343. fptr1 = fopen(chargingProfiles[k], "r");
  9344. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9345. //Check Charging Profile Count
  9346. while(fscanf(fptr1, "%s", word) != EOF)
  9347. {
  9348. //DEBUG_INFO("word=%s\n",word);
  9349. if(strstr(word, "chargingProfileId")!= NULL)
  9350. {
  9351. //DEBUG_INFO("test chargingProfileId \n");
  9352. n_chargingProfile = n_chargingProfile + 1;
  9353. //DEBUG_INFO("chargingProfileId Found\n");
  9354. }
  9355. }
  9356. rewind(fptr1);
  9357. //search Charging Profile Element
  9358. //int i= 0;
  9359. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9360. {
  9361. json_object *tmpProfilee;
  9362. tmpProfilee = json_tokener_parse(sLineWord);
  9363. if(!is_error(tmpProfilee))
  9364. {
  9365. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9366. {
  9367. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9368. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9369. }
  9370. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9371. {
  9372. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9373. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9374. }
  9375. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9376. {
  9377. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9378. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9379. }
  9380. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9381. {
  9382. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9383. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9384. }
  9385. }
  9386. json_object_put(tmpProfilee);
  9387. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9388. {
  9389. //------- not write to fptr2-------//
  9390. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9391. //clearflag = TRUE;
  9392. }
  9393. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9394. {
  9395. //------- not write to fptr2-------//
  9396. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9397. }
  9398. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9399. {
  9400. //------- not write to fptr2-------//
  9401. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9402. }
  9403. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9404. {
  9405. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9406. }
  9407. else
  9408. {
  9409. fprintf(fptr2, sLineWord);//writing data into file
  9410. }
  9411. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9412. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9413. if(clearflag == TRUE)
  9414. {
  9415. fclose(fptr1);
  9416. fclose(fptr2);
  9417. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9418. system(str);
  9419. // clear temp file
  9420. sprintf(str,"rm -f %s",temp);
  9421. system(str);
  9422. }
  9423. else
  9424. {
  9425. fclose(fptr1);
  9426. fclose(fptr2);
  9427. memset(str, 0, ARRAY_SIZE(str));
  9428. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9429. system(str);
  9430. resultRename = rename(temp, chargingProfiles[k]);
  9431. if(resultRename == 0)
  9432. {
  9433. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9434. }
  9435. else
  9436. {
  9437. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9438. }
  9439. if(comfirmstr[0]== 0)
  9440. {
  9441. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9442. }
  9443. //Check chargingProfile is empty file
  9444. /*------ Read the file ----------------*/
  9445. fptr1=fopen(chargingProfiles[k],"r");
  9446. ch=fgetc(fptr1);
  9447. rewind(fptr1);
  9448. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9449. if(ch!=EOF)
  9450. {
  9451. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9452. {
  9453. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9454. if(sLineWord[0]=='\0')
  9455. {
  9456. isEmptyFile = TRUE;
  9457. break;
  9458. }
  9459. else
  9460. {
  9461. isEmptyFile = FALSE;
  9462. break;
  9463. }
  9464. }
  9465. }
  9466. else
  9467. isEmptyFile = TRUE;
  9468. fclose(fptr1);
  9469. if(isEmptyFile == TRUE)
  9470. {
  9471. memset(str, 0, ARRAY_SIZE(str));
  9472. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9473. system(str);
  9474. }
  9475. }
  9476. }// End of while(int k=0; k < ChargePointCount; k++)
  9477. }
  9478. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9479. {
  9480. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9481. for(int k=0; k < ChargeProfileCount; k++)
  9482. {
  9483. fptr1 = fopen(chargingProfiles[k], "r");
  9484. fptr2 = fopen(temp, "w+");
  9485. //Check Charging Profile Count
  9486. while(fscanf(fptr1, "%s", word) != EOF)
  9487. {
  9488. //DEBUG_INFO("word=%s\n",word);
  9489. if(strstr(word, "chargingProfileId")!= NULL)
  9490. {
  9491. n_chargingProfile = n_chargingProfile + 1;
  9492. }
  9493. }
  9494. rewind(fptr1);
  9495. //search Charging Profile Element
  9496. //int i= 0;
  9497. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9498. {
  9499. json_object *tmpProfilee;
  9500. tmpProfilee = json_tokener_parse(sLineWord);
  9501. if(!is_error(tmpProfilee))
  9502. {
  9503. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9504. {
  9505. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9506. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9507. }
  9508. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9509. {
  9510. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9511. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9512. }
  9513. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9514. {
  9515. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9516. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9517. }
  9518. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9519. {
  9520. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9521. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9522. }
  9523. }
  9524. json_object_put(tmpProfilee);
  9525. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9526. {
  9527. //------- not write to fptr2-------//
  9528. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9529. //clearflag = TRUE;
  9530. }
  9531. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9532. {
  9533. //------- not write to fptr2-------//
  9534. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9535. }
  9536. else if(stackLevelIsNULL == TRUE)
  9537. {
  9538. //Clear Whole File
  9539. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9540. clearflag = TRUE;
  9541. break;
  9542. }
  9543. else
  9544. {
  9545. fprintf(fptr2, sLineWord);//writing data into file
  9546. }
  9547. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9548. }
  9549. if(clearflag == TRUE)
  9550. {
  9551. fclose(fptr1);
  9552. fclose(fptr2);
  9553. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9554. system(str);
  9555. // clear temp file
  9556. sprintf(str,"rm -f %s",temp);
  9557. system(str);
  9558. }
  9559. else
  9560. {
  9561. fclose(fptr1);
  9562. fclose(fptr2);
  9563. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9564. system(str);
  9565. resultRename = rename(temp, chargingProfiles[k]);
  9566. if(resultRename == 0)
  9567. {
  9568. DEBUG_INFO("File ChargingProfile renamed successfully");
  9569. }
  9570. else
  9571. {
  9572. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9573. }
  9574. if(comfirmstr[0]== 0)
  9575. {
  9576. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9577. }
  9578. //Check chargingProfile is empty file
  9579. /*------ Read the file ----------------*/
  9580. fptr1=fopen(chargingProfiles[k],"r");
  9581. ch=fgetc(fptr1);
  9582. rewind(fptr1);
  9583. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9584. if(ch!=EOF)
  9585. {
  9586. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9587. {
  9588. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9589. if(sLineWord[0]=='\0')
  9590. {
  9591. isEmptyFile = TRUE;
  9592. break;
  9593. }
  9594. else
  9595. {
  9596. isEmptyFile = FALSE;
  9597. break;
  9598. }
  9599. }
  9600. }
  9601. else
  9602. isEmptyFile = TRUE;
  9603. fclose(fptr1);
  9604. if(isEmptyFile == TRUE)
  9605. {
  9606. memset(str, 0, ARRAY_SIZE(str));
  9607. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9608. system(str);
  9609. }
  9610. /*------- End of reading ---------------*/
  9611. }
  9612. } // while(int k=0; k < ChargeProfileCount; k++)
  9613. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9614. end:
  9615. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9616. {
  9617. if(connectorIdInt == 0)
  9618. {
  9619. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9620. {
  9621. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9622. }
  9623. }
  9624. else
  9625. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9626. }
  9627. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9628. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9629. return result;
  9630. }
  9631. void createFirmwareVersionByDataTransfer(void)
  9632. {
  9633. json_object *FirmwareDataTransfer = json_object_new_object();
  9634. // AC & DC model
  9635. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9636. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9637. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9638. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9639. // DC model
  9640. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9641. {
  9642. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9643. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9644. (gunType[3] != GUN_TYPE_UNKNOWN))
  9645. {
  9646. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9647. }
  9648. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='L') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='Z'))
  9649. {
  9650. // DS DM DW
  9651. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9652. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9653. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9654. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9655. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9656. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9657. }
  9658. else
  9659. {
  9660. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9661. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9662. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9663. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9664. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9665. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9666. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9667. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9668. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9669. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9670. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9671. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9672. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9673. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9674. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9675. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9676. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9677. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9678. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9679. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9680. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9681. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9682. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9683. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9684. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9685. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9686. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9687. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9688. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9689. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9690. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9691. }
  9692. }
  9693. // 4G model
  9694. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9695. {
  9696. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9697. }
  9698. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9699. json_object_put(FirmwareDataTransfer);
  9700. }
  9701. int handleDataTransferRequest(char *uuid, char *payload)
  9702. {
  9703. mtrace();
  9704. json_object *response = json_object_new_object();
  9705. int result = FAIL;
  9706. char tempvendorId[255]={0};
  9707. char tempmessageId[50]={0};
  9708. char tempdata[10240]={0};
  9709. char message[20480]={0};
  9710. DEBUG_INFO("handleDataTransferRequest...\n");
  9711. if((uuid != NULL) && (payload != NULL))
  9712. {
  9713. json_object *DataTransfer;
  9714. DataTransfer = json_tokener_parse(payload);
  9715. if(!is_error(DataTransfer))
  9716. {
  9717. // Required data
  9718. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9719. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9720. // Optional data
  9721. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9722. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9723. if(json_object_object_get(DataTransfer, "data") != NULL)
  9724. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9725. result = PASS;
  9726. }
  9727. json_object_put(DataTransfer);
  9728. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9729. {
  9730. // Send all moudle firmware version on EVSE
  9731. createFirmwareVersionByDataTransfer();
  9732. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9733. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9734. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9735. json_object_put(response);
  9736. }
  9737. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9738. {
  9739. system("/usr/bin/run_tmate_restart.sh &");
  9740. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9741. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9742. json_object_put(response);
  9743. }
  9744. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9745. {
  9746. json_object *data;
  9747. data = json_tokener_parse(tempdata);
  9748. if(!is_error(data))
  9749. {
  9750. 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))
  9751. {
  9752. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9753. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9754. if(json_object_object_get(data, "SOC") != NULL)
  9755. {
  9756. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9757. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9758. }
  9759. if(json_object_object_get(data, "Energy") != NULL)
  9760. {
  9761. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9762. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9763. }
  9764. if(json_object_object_get(data, "Duration") != NULL)
  9765. {
  9766. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9767. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9768. }
  9769. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9770. }
  9771. else
  9772. {
  9773. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9774. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9775. }
  9776. }
  9777. else
  9778. {
  9779. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9780. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9781. }
  9782. json_object_put(data);
  9783. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9784. json_object_put(response);
  9785. }
  9786. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9787. {
  9788. json_object *data;
  9789. data = json_tokener_parse(tempdata);
  9790. if(!is_error(data))
  9791. {
  9792. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9793. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9794. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9795. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9796. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9797. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9798. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9799. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9800. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9801. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9802. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9803. }
  9804. else
  9805. {
  9806. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9807. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9808. }
  9809. json_object_put(data);
  9810. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9811. json_object_put(response);
  9812. }
  9813. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9814. {
  9815. json_object *data;
  9816. data = json_tokener_parse(tempdata);
  9817. if(!is_error(data))
  9818. {
  9819. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9820. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9821. if(json_object_object_get(data, "idToken") != NULL)
  9822. {
  9823. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9824. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9825. }
  9826. else
  9827. {
  9828. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9829. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9830. }
  9831. if(json_object_object_get(data, "price") != NULL) //v1.0
  9832. {
  9833. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9834. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9835. }
  9836. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9837. {
  9838. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9839. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9840. }
  9841. else
  9842. {
  9843. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9844. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9845. }
  9846. }
  9847. else
  9848. {
  9849. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9850. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9851. }
  9852. json_object_put(data);
  9853. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9854. json_object_put(response);
  9855. }
  9856. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9857. {
  9858. json_object *data;
  9859. data = json_tokener_parse(tempdata);
  9860. if(!is_error(data))
  9861. {
  9862. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9863. if(json_object_object_get(data, "txId") != NULL)
  9864. {
  9865. // California pricing V1.0
  9866. DEBUG_INFO("California pricing V1.0\n");
  9867. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9868. sprintf((char*)dmsVersion, "1.0");
  9869. for(int idx = 0;idx<gunTotalNumber;idx++)
  9870. {
  9871. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9872. {
  9873. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9874. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9875. if(json_object_object_get(data, "description") != NULL)
  9876. {
  9877. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9878. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9879. }
  9880. else
  9881. {
  9882. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9883. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9884. }
  9885. }
  9886. }
  9887. }
  9888. else if(json_object_object_get(data, "transactionId") != NULL)
  9889. {
  9890. // California pricing V2.0
  9891. DEBUG_INFO("California pricing V2.0\n");
  9892. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9893. sprintf((char*)dmsVersion, "2.0");
  9894. for(int idx=0;idx<gunTotalNumber;idx++)
  9895. {
  9896. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9897. {
  9898. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9899. if(json_object_object_get(data, "timestamp") != NULL)
  9900. {
  9901. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9902. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9903. }
  9904. else
  9905. {
  9906. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9907. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9908. }
  9909. if(json_object_object_get(data, "meterValue") != NULL)
  9910. {
  9911. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9912. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9913. }
  9914. else
  9915. {
  9916. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9917. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9918. }
  9919. if(json_object_object_get(data, "cost") != NULL)
  9920. {
  9921. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9922. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9923. }
  9924. else
  9925. {
  9926. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9927. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9928. }
  9929. if(json_object_object_get(data, "state") != NULL)
  9930. {
  9931. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9932. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9933. }
  9934. else
  9935. {
  9936. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9937. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9938. }
  9939. if(json_object_object_get(data, "chargingPrice") != NULL)
  9940. {
  9941. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9942. {
  9943. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9944. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9945. }
  9946. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9947. {
  9948. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9949. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9950. }
  9951. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9952. {
  9953. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9954. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9955. }
  9956. }
  9957. else
  9958. {
  9959. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9960. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9961. }
  9962. if(json_object_object_get(data, "idlePrice") != NULL)
  9963. {
  9964. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9965. {
  9966. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9967. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9968. }
  9969. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9970. {
  9971. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9972. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9973. }
  9974. }
  9975. if(json_object_object_get(data, "nextPeriod") != NULL)
  9976. {
  9977. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9978. {
  9979. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9980. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9981. }
  9982. else
  9983. {
  9984. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9985. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9986. }
  9987. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9988. {
  9989. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9990. {
  9991. 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")));
  9992. 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"));
  9993. }
  9994. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9995. {
  9996. 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")));
  9997. 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"));
  9998. }
  9999. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  10000. {
  10001. 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")));
  10002. 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"));
  10003. }
  10004. }
  10005. else
  10006. {
  10007. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10008. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10009. }
  10010. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10011. {
  10012. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10013. {
  10014. 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")));
  10015. 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"));
  10016. }
  10017. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10018. {
  10019. 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")));
  10020. 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"));
  10021. }
  10022. }
  10023. }
  10024. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10025. {
  10026. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10027. {
  10028. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10029. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10030. }
  10031. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10032. {
  10033. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10034. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10035. }
  10036. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10037. {
  10038. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10039. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10040. }
  10041. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10042. {
  10043. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10044. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10045. }
  10046. }
  10047. }
  10048. }
  10049. }
  10050. else
  10051. {
  10052. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10053. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10054. }
  10055. }
  10056. else
  10057. {
  10058. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10059. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10060. }
  10061. json_object_put(data);
  10062. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10063. json_object_put(response);
  10064. }
  10065. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10066. {
  10067. json_object *data;
  10068. data = json_tokener_parse(tempdata);
  10069. if(!is_error(data))
  10070. {
  10071. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10072. if(json_object_object_get(data, "txId") != NULL)
  10073. {
  10074. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10075. for(int idx = 0;idx<gunTotalNumber;idx++)
  10076. {
  10077. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10078. {
  10079. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10080. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10081. if(json_object_object_get(data, "description") != NULL)
  10082. {
  10083. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10084. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10085. }
  10086. else
  10087. {
  10088. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10089. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10090. }
  10091. }
  10092. }
  10093. }
  10094. else if(json_object_object_get(data, "transactionId") != NULL)
  10095. {
  10096. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10097. for(int idx = 0;idx<gunTotalNumber;idx++)
  10098. {
  10099. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10100. {
  10101. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10102. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10103. if(json_object_object_get(data, "cost") != NULL)
  10104. {
  10105. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10106. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10107. }
  10108. else
  10109. {
  10110. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10111. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10112. }
  10113. if(json_object_object_get(data, "priceText") != NULL)
  10114. {
  10115. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10116. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10117. }
  10118. else
  10119. {
  10120. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10121. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10122. }
  10123. if(json_object_object_get(data, "qrCodeText") != NULL)
  10124. {
  10125. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10126. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10127. }
  10128. }
  10129. }
  10130. }
  10131. else
  10132. {
  10133. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10134. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10135. }
  10136. }
  10137. else
  10138. {
  10139. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10140. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10141. }
  10142. json_object_put(data);
  10143. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10144. json_object_put(response);
  10145. }
  10146. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10147. {
  10148. json_object *data;
  10149. data = json_tokener_parse(tempdata);
  10150. if(!is_error(data))
  10151. {
  10152. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10153. if(json_object_object_get(data, "Content_Type") != NULL)
  10154. {
  10155. 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))
  10156. {
  10157. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10158. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10159. {
  10160. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10161. }
  10162. }
  10163. else
  10164. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10165. }
  10166. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10167. }
  10168. else
  10169. {
  10170. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10171. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10172. }
  10173. json_object_put(data);
  10174. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10175. json_object_put(response);
  10176. }
  10177. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10178. {
  10179. json_object *data;
  10180. data = json_tokener_parse(tempdata);
  10181. if(!is_error(data))
  10182. {
  10183. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10184. if(json_object_object_get(data, "ConnectorId") != NULL)
  10185. {
  10186. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10187. }
  10188. if(json_object_object_get(data, "SerialNo") != NULL)
  10189. {
  10190. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10191. }
  10192. if(json_object_object_get(data, "Page_Index") != NULL)
  10193. {
  10194. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10195. }
  10196. if(json_object_object_get(data, "Duration") != NULL)
  10197. {
  10198. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10199. }
  10200. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10201. }
  10202. else
  10203. {
  10204. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10205. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10206. }
  10207. json_object_put(data);
  10208. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10209. json_object_put(response);
  10210. }
  10211. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10212. {
  10213. json_object *data;
  10214. data = json_tokener_parse(tempdata);
  10215. if(!is_error(data))
  10216. {
  10217. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10218. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10219. {
  10220. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10221. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10222. else
  10223. {
  10224. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10225. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10226. }
  10227. }
  10228. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10229. {
  10230. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10231. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10232. else
  10233. {
  10234. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10235. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10236. }
  10237. }
  10238. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10239. {
  10240. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10241. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10242. else
  10243. {
  10244. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10245. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10246. }
  10247. }
  10248. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10249. {
  10250. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10251. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10252. else
  10253. {
  10254. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10255. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10256. }
  10257. }
  10258. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10259. {
  10260. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10261. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10262. else
  10263. {
  10264. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10265. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10266. }
  10267. }
  10268. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10269. {
  10270. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10271. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10272. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10273. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10274. else
  10275. {
  10276. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10277. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10278. }
  10279. }
  10280. if(json_object_object_get(data, "isAuthentication") != NULL)
  10281. {
  10282. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10283. {
  10284. case 0:
  10285. case 1:
  10286. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10287. break;
  10288. default:
  10289. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10290. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10291. break;
  10292. }
  10293. }
  10294. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10295. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10296. }
  10297. else
  10298. {
  10299. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10300. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10301. }
  10302. json_object_put(data);
  10303. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10304. json_object_put(response);
  10305. }
  10306. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10307. {
  10308. json_object *data;
  10309. data = json_tokener_parse(tempdata);
  10310. if(!is_error(data))
  10311. {
  10312. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10313. {
  10314. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10315. {
  10316. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10317. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10318. }
  10319. else
  10320. {
  10321. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10322. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10323. }
  10324. }
  10325. else
  10326. {
  10327. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10328. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10329. }
  10330. }
  10331. else
  10332. {
  10333. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10334. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10335. }
  10336. json_object_put(data);
  10337. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10338. json_object_put(response);
  10339. }
  10340. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10341. {
  10342. json_object *data;
  10343. data = json_tokener_parse(tempdata);
  10344. if(!is_error(data))
  10345. {
  10346. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10347. if(json_object_object_get(data, "stationName") != NULL)
  10348. {
  10349. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10350. }
  10351. else
  10352. {
  10353. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10354. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10355. }
  10356. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10357. {
  10358. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10359. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10360. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10361. }
  10362. }
  10363. else
  10364. {
  10365. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10366. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10367. }
  10368. json_object_put(data);
  10369. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10370. json_object_put(response);
  10371. }
  10372. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10373. {
  10374. json_object *data;
  10375. data = json_tokener_parse(tempdata);
  10376. if(!is_error(data))
  10377. {
  10378. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10379. if(json_object_object_get(data, "weatherId") != NULL)
  10380. {
  10381. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10382. }
  10383. else
  10384. {
  10385. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10386. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10387. }
  10388. if(json_object_object_get(data, "Temperature") != NULL)
  10389. {
  10390. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10391. }
  10392. else
  10393. {
  10394. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10395. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10396. }
  10397. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10398. {
  10399. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10400. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10401. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10402. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10403. );
  10404. }
  10405. }
  10406. else
  10407. {
  10408. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10409. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10410. }
  10411. json_object_put(data);
  10412. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10413. json_object_put(response);
  10414. }
  10415. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10416. {
  10417. json_object *data;
  10418. data = json_tokener_parse(tempdata);
  10419. if(!is_error(data))
  10420. {
  10421. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10422. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10423. {
  10424. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10425. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10426. }
  10427. else
  10428. {
  10429. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10430. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10431. }
  10432. }
  10433. else
  10434. {
  10435. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10436. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10437. }
  10438. json_object_put(data);
  10439. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10440. json_object_put(response);
  10441. }
  10442. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10443. {
  10444. json_object *data;
  10445. data = json_tokener_parse(tempdata);
  10446. if(!is_error(data))
  10447. {
  10448. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10449. {
  10450. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10451. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10452. if(gun_index < gunTotalNumber)
  10453. {
  10454. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10455. {
  10456. json_object *responsedata = json_object_new_object();
  10457. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10458. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10459. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10460. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10461. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10462. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10463. }
  10464. else
  10465. {
  10466. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10467. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10468. }
  10469. }
  10470. else
  10471. {
  10472. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10473. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10474. }
  10475. }
  10476. else
  10477. {
  10478. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10479. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10480. }
  10481. }
  10482. else
  10483. {
  10484. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10485. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10486. }
  10487. json_object_put(data);
  10488. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10489. json_object_put(response);
  10490. }
  10491. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10492. {
  10493. json_object *data;
  10494. data = json_tokener_parse(tempdata);
  10495. if(!is_error(data))
  10496. {
  10497. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10498. int gun_index = 0;
  10499. if(json_object_object_get(data, "ConnectorId") != NULL)
  10500. {
  10501. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10502. if(json_object_object_get(data, "occupancySN") != NULL)
  10503. {
  10504. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  10505. }
  10506. else
  10507. {
  10508. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10509. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  10510. }
  10511. if(json_object_object_get(data, "actionId") != NULL)
  10512. {
  10513. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  10514. }
  10515. else
  10516. {
  10517. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10518. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  10519. }
  10520. }
  10521. else
  10522. {
  10523. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10524. json_object_object_add(response, "data", json_object_new_string("ConnectorId data can not get."));
  10525. }
  10526. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10527. {
  10528. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  10529. }
  10530. }
  10531. else
  10532. {
  10533. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10534. json_object_object_add(response, "data", json_object_new_string("OccupancyFeeDisplay content got something wrong."));
  10535. }
  10536. json_object_put(data);
  10537. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10538. json_object_put(response);
  10539. }
  10540. else if(strstr(tempmessageId, "ID_SetOccupancyPrice") != NULL)
  10541. {
  10542. json_object *data;
  10543. data = json_tokener_parse(tempdata);
  10544. if(!is_error(data))
  10545. {
  10546. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10547. if(json_object_object_get(data, "price") != NULL)
  10548. {
  10549. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  10550. }
  10551. else
  10552. {
  10553. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10554. json_object_object_add(response, "data", json_object_new_string("price data can not get."));
  10555. }
  10556. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10557. {
  10558. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  10559. }
  10560. }
  10561. else
  10562. {
  10563. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10564. json_object_object_add(response, "data", json_object_new_string("SetOccupancyPrice content got something wrong."));
  10565. }
  10566. json_object_put(data);
  10567. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10568. json_object_put(response);
  10569. }
  10570. // Support ISO-15118 related message
  10571. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10572. {
  10573. char cmdBuf[1024]={0};
  10574. 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);
  10575. system(cmdBuf);
  10576. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10577. json_object *responsedata = json_object_new_object();
  10578. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10579. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10580. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10581. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10582. json_object_put(response);
  10583. }
  10584. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10585. {
  10586. json_object *data;
  10587. data = json_tokener_parse(tempdata);
  10588. if(!is_error(data))
  10589. {
  10590. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10591. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10592. fclose(fp);
  10593. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10594. json_object *responsedata = json_object_new_object();
  10595. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10596. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10597. else
  10598. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10599. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10600. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10601. }
  10602. else
  10603. {
  10604. json_object *responsedata = json_object_new_object();
  10605. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10606. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10607. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10608. }
  10609. json_object_put(data);
  10610. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10611. json_object_put(response);
  10612. }
  10613. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10614. {
  10615. json_object *data;
  10616. data = json_tokener_parse(tempdata);
  10617. DEBUG_INFO("DeleteCertificate processing...\n");
  10618. if(!is_error(data))
  10619. {
  10620. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10621. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10622. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10623. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10624. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10625. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10626. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10627. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10628. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10629. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10630. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10631. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10632. char temp[256] = {0};
  10633. char compareData[256] = {0};
  10634. int isMatch = TRUE;
  10635. // Check certV2G
  10636. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10637. {
  10638. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10639. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10640. isMatch = FALSE;
  10641. if(isMatch == TRUE)
  10642. {
  10643. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10644. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10645. isMatch = FALSE;
  10646. }
  10647. if(isMatch == TRUE)
  10648. {
  10649. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10650. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10651. isMatch = FALSE;
  10652. }
  10653. if(isMatch == TRUE)
  10654. {
  10655. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10656. system(temp);
  10657. json_object *responsedata = json_object_new_object();
  10658. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10659. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10660. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10661. }
  10662. else
  10663. {
  10664. json_object *responsedata = json_object_new_object();
  10665. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10666. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10667. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10668. }
  10669. }
  10670. else
  10671. {
  10672. json_object *responsedata = json_object_new_object();
  10673. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10674. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10675. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10676. }
  10677. }
  10678. else
  10679. {
  10680. json_object *responsedata = json_object_new_object();
  10681. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10682. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10683. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10684. }
  10685. json_object_put(data);
  10686. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10687. json_object_put(response);
  10688. }
  10689. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10690. {
  10691. json_object *data;
  10692. data = json_tokener_parse(tempdata);
  10693. if(!is_error(data))
  10694. {
  10695. /*
  10696. * TODO:
  10697. * 1. Query certificate to response
  10698. */
  10699. json_object *responsedata = json_object_new_object();
  10700. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10701. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10702. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10703. }
  10704. else
  10705. {
  10706. json_object *responsedata = json_object_new_object();
  10707. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10708. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10709. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10710. }
  10711. json_object_put(data);
  10712. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10713. json_object_put(response);
  10714. }
  10715. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10716. {
  10717. json_object *data;
  10718. data = json_tokener_parse(tempdata);
  10719. if(!is_error(data))
  10720. {
  10721. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10722. if(json_object_object_get(data, "certificateType") != NULL)
  10723. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10724. if(json_object_object_get(data, "certificate") != NULL)
  10725. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10726. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10727. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10728. char temp[1024];
  10729. FILE *fp = fopen(tempCert, "w");
  10730. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10731. fclose(fp);
  10732. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10733. char strExpDate[30];
  10734. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10735. fp = popen(temp, "r");
  10736. if(fp)
  10737. {
  10738. while(fgets(temp, sizeof(temp), fp) != NULL)
  10739. {
  10740. if(strstr(temp, "notAfter=") != NULL)
  10741. {
  10742. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10743. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10744. break;
  10745. }
  10746. }
  10747. }
  10748. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10749. struct tm tmExpDate;
  10750. struct timeb tbExpDate;
  10751. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10752. tbExpDate.time = mktime(&tmExpDate);
  10753. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10754. {
  10755. DEBUG_INFO("The enddate is already expired...\n");
  10756. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10757. }
  10758. else
  10759. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10760. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10761. {
  10762. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10763. {
  10764. if(access(ROOTCA_V2G,F_OK) != -1)
  10765. {
  10766. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10767. rename(ROOTCA_V2G, "/Storage/rootCaV2g_fallback.pem");
  10768. rename(tempCert, ROOTCA_V2G);
  10769. }
  10770. else
  10771. {
  10772. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10773. rename(tempCert, ROOTCA_V2G);
  10774. }
  10775. json_object *responsedata = json_object_new_object();
  10776. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10777. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10778. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10779. }
  10780. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10781. {
  10782. if(access(ROOTCA_MO,F_OK) != -1)
  10783. {
  10784. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10785. rename(ROOTCA_MO, "/Storage/rootCaMo_fallback.pem");
  10786. rename(tempCert, ROOTCA_MO);
  10787. }
  10788. else
  10789. {
  10790. DEBUG_INFO("No existed MORootCertificate. Creating...\n");
  10791. rename(tempCert, ROOTCA_MO);
  10792. }
  10793. json_object *responsedata = json_object_new_object();
  10794. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10795. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10796. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10797. }
  10798. else
  10799. {
  10800. json_object *responsedata = json_object_new_object();
  10801. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10802. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10803. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10804. }
  10805. }
  10806. else
  10807. {
  10808. json_object *responsedata = json_object_new_object();
  10809. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10810. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10811. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10812. }
  10813. }
  10814. else
  10815. {
  10816. json_object *responsedata = json_object_new_object();
  10817. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10818. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10819. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10820. }
  10821. json_object_put(data);
  10822. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10823. json_object_put(response);
  10824. }
  10825. else
  10826. {
  10827. // Can not find valid message id
  10828. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10829. }
  10830. }
  10831. else
  10832. {
  10833. // Payload is null
  10834. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10835. }
  10836. LWS_Send(message);
  10837. return result;
  10838. }
  10839. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10840. {
  10841. mtrace();
  10842. int result = FAIL;
  10843. int connectorIdInt, durationInt;
  10844. char chargingRateUnitStr[4]={0};
  10845. char comfirmstr[20];
  10846. int confirmPeriods = 0;
  10847. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10848. json_object *GetCompositeSchedule;
  10849. GetCompositeSchedule = json_tokener_parse(payload);
  10850. if(!is_error(GetCompositeSchedule))
  10851. {
  10852. // Required data
  10853. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10854. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10855. else
  10856. connectorIdInt = -1;
  10857. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10858. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10859. else
  10860. durationInt = 86400;
  10861. // Optional data
  10862. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10863. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10864. }
  10865. json_object_put(GetCompositeSchedule);
  10866. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10867. if((connectorIdInt == 0) ||
  10868. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10869. {
  10870. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10871. struct StructChargingProfile tmpProfile[1];
  10872. if(strstr(chargingRateUnitStr, "W") != NULL)
  10873. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10874. else
  10875. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10876. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10877. {
  10878. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10879. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10880. }
  10881. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10882. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10883. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10884. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10885. {
  10886. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10887. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10888. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10889. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10890. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10891. {
  10892. confirmPeriods = idx;
  10893. break;
  10894. }
  10895. }
  10896. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10897. {
  10898. confirmPeriods += 1;
  10899. }
  10900. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10901. }
  10902. else
  10903. {
  10904. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10905. }
  10906. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10907. return result;
  10908. }
  10909. int handleGetConfigurationRequest(char *uuid, char *payload)
  10910. {
  10911. mtrace();
  10912. int result = FAIL;
  10913. int MaxKeySupported = 0;
  10914. int n_keys = 0;
  10915. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10916. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10917. json_object *GetConfiguration;
  10918. GetConfiguration = json_tokener_parse(payload);
  10919. if(!is_error(GetConfiguration))
  10920. {
  10921. // Optional data
  10922. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10923. {
  10924. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10925. {
  10926. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10927. n_keys = idx + 1;
  10928. }
  10929. }
  10930. }
  10931. json_object_put(GetConfiguration);
  10932. UnknownKeynum = 0;
  10933. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10934. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10935. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10936. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10937. if(n_keys != 0)
  10938. {
  10939. for(int i=0;i<n_keys;i++)
  10940. {
  10941. getKeyValue(requestKey[i]);
  10942. }
  10943. }
  10944. else
  10945. {
  10946. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10947. getKeyValue("");
  10948. }
  10949. processUnkownKey();
  10950. sendGetConfigurationConfirmation(uuid);
  10951. return result;
  10952. }
  10953. static char fnamePlusPath[100]={0};
  10954. static char fnamePWithNoPath[60]={0};
  10955. void checkUploadLog(void)
  10956. {
  10957. FILE *fp;
  10958. /* Open the command for reading. */
  10959. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10960. if (fp == NULL) {
  10961. DEBUG_WARN("Failed to run command\n" );
  10962. exit(1);
  10963. }
  10964. int ftppathlen = 0;
  10965. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10966. int i = 0;
  10967. /* Read the output a line at a time - output it. */
  10968. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10969. if(i==0)
  10970. {
  10971. ftppathlen = strlen(fnamePlusPath);
  10972. DEBUG_INFO("%s\n", fnamePlusPath);
  10973. fnamePlusPath[ftppathlen]='\0';
  10974. break;
  10975. }
  10976. i= i+1;
  10977. }
  10978. /* close */
  10979. pclose(fp);
  10980. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10981. {
  10982. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10983. {
  10984. fnamePlusPath[k]='\0';
  10985. }
  10986. }
  10987. i=1;
  10988. //char fname[60]={0};
  10989. while(i < ftppathlen)
  10990. {
  10991. int len=ftppathlen-i;
  10992. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10993. {
  10994. DEBUG_INFO("compare '/' all right\n");
  10995. break;
  10996. }
  10997. i=i+1;
  10998. }
  10999. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  11000. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11001. fnamePWithNoPath[i+1] = '\0';
  11002. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11003. {
  11004. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11005. {
  11006. fnamePWithNoPath[j]='\0';
  11007. }
  11008. }
  11009. FILE* fp1 = fopen(fnamePlusPath, "r");
  11010. if (fp1)
  11011. {
  11012. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11013. // file exists
  11014. fclose(fp1);
  11015. }
  11016. else
  11017. {
  11018. // file doesn't exist
  11019. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11020. }
  11021. }
  11022. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11023. {
  11024. mtrace();
  11025. int result = FAIL;
  11026. time_t CurrentTime;
  11027. struct tm *tm;
  11028. pthread_t th_Status;
  11029. CurrentTime = time(NULL);
  11030. tm = localtime(&CurrentTime);
  11031. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11032. 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);
  11033. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11034. if(!interLock.isGetDiagnosticGoing)
  11035. {
  11036. interLock.isGetDiagnosticGoing = 1;
  11037. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11038. sleep(1);
  11039. }
  11040. else
  11041. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11042. return result;
  11043. }
  11044. void* GetDiagnosticsProcess(void* data)
  11045. {
  11046. pthread_detach(pthread_self());
  11047. mtrace();
  11048. int retriesInt=0, retryIntervalInt=0;
  11049. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11050. 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};
  11051. int port=0;
  11052. int isSuccess = FALSE;
  11053. char cmdBuf[2048];
  11054. struct tm *tmNow;
  11055. time_t CurrentTime;
  11056. struct tm tmStart;
  11057. struct tm tmStop;
  11058. CurrentTime = time(NULL);
  11059. tmNow=localtime(&CurrentTime);
  11060. uint16_t targetYear, targetMonth;
  11061. json_object *GetDiagnostics;
  11062. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11063. GetDiagnostics = json_tokener_parse(data);
  11064. if(!is_error(GetDiagnostics))
  11065. {
  11066. // Required data
  11067. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11068. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11069. // Optional data
  11070. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11071. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11072. else
  11073. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11074. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11075. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11076. else
  11077. retryIntervalInt = 30;
  11078. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11079. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11080. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11081. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11082. }
  11083. json_object_put(GetDiagnostics);
  11084. // Notify CSU to get log of dispensers.
  11085. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  11086. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  11087. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  11088. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  11089. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  11090. )
  11091. {
  11092. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StartTime,"%s",startTimestr);
  11093. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StopTime,"%s",stopTimestr);
  11094. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = TRUE;
  11095. struct timespec timerGetDiagnostics;
  11096. refreshStartTimer(&timerGetDiagnostics);
  11097. while(ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq != FALSE)
  11098. {
  11099. if(getDiffSecNow(timerGetDiagnostics)>=180)
  11100. {
  11101. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = FALSE;
  11102. DEBUG_INFO("Waiting log of dispenser timeout.");
  11103. }
  11104. }
  11105. }
  11106. // Pack log to compress file
  11107. 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) &&
  11108. (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))
  11109. {
  11110. // Pack system log
  11111. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11112. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11113. targetYear = tmStart.tm_year;
  11114. targetMonth = tmStart.tm_mon;
  11115. do
  11116. {
  11117. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11118. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11119. if(targetMonth+1>=13)
  11120. {
  11121. targetYear += 1;
  11122. targetMonth = 1;
  11123. }
  11124. else
  11125. {
  11126. targetMonth += 1;
  11127. }
  11128. }while((targetYear < (tmNow->tm_year+1900)) ||
  11129. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11130. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11131. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11132. sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
  11133. sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
  11134. sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
  11135. sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
  11136. system(cmdBuf);
  11137. // Pack charging & event log
  11138. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11139. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11140. targetYear = tmStart.tm_year;
  11141. targetMonth = tmStart.tm_mon;
  11142. do
  11143. {
  11144. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11145. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  11146. if(targetMonth+1>=13)
  11147. {
  11148. targetYear += 1;
  11149. targetMonth = 1;
  11150. }
  11151. else
  11152. {
  11153. targetMonth += 1;
  11154. }
  11155. }while((targetYear < (tmNow->tm_year+1900)) ||
  11156. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11157. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11158. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11159. system(cmdBuf);
  11160. // Combine log file
  11161. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11162. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11163. }
  11164. else
  11165. {
  11166. system("exec /root/logPackTools 'log' 6");
  11167. }
  11168. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11169. system(cmdBuf);
  11170. checkUploadLog();
  11171. //****************location*******************/
  11172. if(strcmp(locationstr,"")==0)
  11173. {
  11174. DEBUG_INFO("location is <Empty>!\n");
  11175. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11176. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11177. goto end;
  11178. }
  11179. memset(protocol, 0, ARRAY_SIZE(protocol));
  11180. memset(user, 0, ARRAY_SIZE(user) );
  11181. memset(password, 0, ARRAY_SIZE(password));
  11182. memset(host, 0, ARRAY_SIZE(host));
  11183. memset(path, 0, ARRAY_SIZE(path));
  11184. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11185. memset(host1, 0, ARRAY_SIZE(host1));
  11186. memset(path1, 0, ARRAY_SIZE(path1));
  11187. /*location: ftp://user:password@host:port/path*/
  11188. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11189. if((access(fnamePlusPath,F_OK))!=-1)
  11190. {
  11191. DEBUG_INFO("fnamePlusPath exist.\n");
  11192. }
  11193. else
  11194. {
  11195. DEBUG_INFO("fnamePlusPath not exist!\n");
  11196. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11197. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11198. goto end;
  11199. }
  11200. if(strchr(locationstr,'@')==NULL)
  11201. {
  11202. sscanf(locationstr,
  11203. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11204. protocol, host, &port, path);
  11205. strcpy(user,"anonymous");
  11206. strcpy(password,"");
  11207. }
  11208. else
  11209. {
  11210. //DEBUG_INFO("pch=%s\n", pch);
  11211. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11212. protocol, user, password, host, &port, path);
  11213. }
  11214. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11215. {
  11216. DEBUG_INFO("protocol is not ftp/http ! \n");
  11217. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11218. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11219. goto end;
  11220. }
  11221. if(strncmp(locationstr,"http", 4) == 0)
  11222. {
  11223. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11224. sprintf(ftppath,"/%s", path);
  11225. do
  11226. {
  11227. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11228. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11229. sleep(3);
  11230. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11231. if(!isSuccess)
  11232. {
  11233. DEBUG_INFO("Diagnostics fail.\n");
  11234. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11235. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11236. sleep(retryIntervalInt);
  11237. }
  11238. else
  11239. {
  11240. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11241. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11242. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11243. }
  11244. retriesInt--;
  11245. }while((isSuccess == 0)&&(retriesInt >= 0));
  11246. }
  11247. else
  11248. {
  11249. sscanf(host,"%[^/]%s",host1, path1);
  11250. if(strlen(path) > 0)
  11251. sprintf(ftppath,"/%s", path);
  11252. else
  11253. sprintf(ftppath,"/%s", path1);
  11254. int ftppathlen=strlen(ftppath);
  11255. int i=1;
  11256. char filenametemp[50];
  11257. while(i < ftppathlen)
  11258. {
  11259. int len=ftppathlen-i;
  11260. if(ftppath[len]== 47) // '/' ascll code: 47
  11261. {
  11262. DEBUG_INFO("find '/' all right\n");
  11263. break;
  11264. }
  11265. i=i+1;
  11266. }
  11267. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11268. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11269. filenametemp[i+1] = 0;
  11270. if(port == 0)
  11271. port = 21;
  11272. do
  11273. {
  11274. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11275. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11276. sleep(3);
  11277. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11278. if(!isSuccess)
  11279. {
  11280. DEBUG_INFO("Diagnostics fail.\n");
  11281. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11282. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11283. sleep(retryIntervalInt);
  11284. }
  11285. else
  11286. {
  11287. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11288. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11289. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11290. }
  11291. retriesInt--;
  11292. }while((!isSuccess)&&(retriesInt >= 0));
  11293. }
  11294. end:
  11295. system("rm -f /mnt/*");
  11296. system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
  11297. sleep(5);
  11298. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11299. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11300. interLock.isGetDiagnosticGoing = 0;
  11301. pthread_exit(NULL);
  11302. }
  11303. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11304. {
  11305. mtrace();
  11306. int result = FAIL;
  11307. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11308. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11309. {
  11310. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11311. locallistVersion = -1;
  11312. }
  11313. else
  11314. {
  11315. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11316. locallistVersion = 0;
  11317. OCPP_getListVerion();
  11318. }
  11319. //from db.OCPP_getListVerion
  11320. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11321. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11322. sendGetLocalListVersionConfirmation(uuid,"");
  11323. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11324. return result;
  11325. }
  11326. int handleRemoteStartRequest(char *uuid, char *payload)
  11327. {
  11328. mtrace();
  11329. int result = PASS;
  11330. int connectorIdInt=-1;
  11331. int tempIndex = 0;
  11332. char comfirmstr[20]={0};
  11333. char cmdBuf[512];
  11334. json_object *RemoteStartTransaction;
  11335. FILE *fp;
  11336. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11337. if(server_pending == TRUE)
  11338. {
  11339. result = FAIL;
  11340. }
  11341. RemoteStartTransaction = json_tokener_parse(payload);
  11342. if(!is_error(RemoteStartTransaction))
  11343. {
  11344. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11345. {
  11346. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11347. }
  11348. else
  11349. {
  11350. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11351. {
  11352. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11353. {
  11354. connectorIdInt = (gun_index+1);
  11355. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11356. break;
  11357. }
  11358. }
  11359. }
  11360. if(connectorIdInt == 0)
  11361. {
  11362. DEBUG_WARN("Connector id shall not equal 0.\n");
  11363. result = FAIL;
  11364. }
  11365. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11366. {
  11367. DEBUG_WARN("idTag should not be NULL.\n");
  11368. result = FAIL;
  11369. }
  11370. else if(connectorIdInt == -1)
  11371. {
  11372. DEBUG_INFO("Connector id does not specific.\n");
  11373. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11374. {
  11375. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11376. // Required data
  11377. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11378. // Optional data
  11379. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11380. {
  11381. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11382. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11383. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11384. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11385. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11386. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11387. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11388. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11389. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11390. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11391. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11392. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11393. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11394. {
  11395. 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")));
  11396. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11397. 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"));
  11398. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11399. 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"));
  11400. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11401. 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")));
  11402. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11403. {
  11404. 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++)
  11405. {
  11406. 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"));
  11407. 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"));
  11408. 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)
  11409. 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"));
  11410. }
  11411. }
  11412. }
  11413. }
  11414. else
  11415. {
  11416. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11417. }
  11418. }
  11419. }
  11420. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11421. {
  11422. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11423. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11424. // Required data
  11425. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11426. // Optional data
  11427. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11428. {
  11429. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11430. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11431. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11432. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11433. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11434. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11435. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11436. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11437. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11438. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11439. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11440. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11441. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11442. {
  11443. 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")));
  11444. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11445. 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"));
  11446. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11447. 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"));
  11448. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11449. 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")));
  11450. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11451. {
  11452. 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++)
  11453. {
  11454. 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"));
  11455. 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"));
  11456. 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)
  11457. 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"));
  11458. }
  11459. }
  11460. }
  11461. }
  11462. else
  11463. {
  11464. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11465. }
  11466. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') && (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W'))
  11467. {
  11468. DEBUG_INFO("Checking charging status for DW series...\n");
  11469. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11470. {
  11471. if(cpinitateMsg.bits[gun_index].isOnCharging ||
  11472. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL) ||
  11473. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing") != NULL))
  11474. {
  11475. DEBUG_INFO("Found gun-%d is in charging.\n", gun_index);
  11476. if(connectorIdInt != (gun_index+1))
  11477. {
  11478. DEBUG_WARN("DWseries--> Other connector is in charging.\n");
  11479. result = FAIL;
  11480. break;
  11481. }
  11482. }
  11483. }
  11484. }
  11485. }
  11486. else
  11487. {
  11488. DEBUG_WARN("Connector id is over maximun value.\n");
  11489. result = FAIL;
  11490. }
  11491. }
  11492. if(result == PASS)
  11493. {
  11494. if(connectorIdInt > 0)
  11495. {
  11496. DEBUG_INFO("Specified gun-%d type: %d\n", (connectorIdInt -1), gunType[connectorIdInt -1]);
  11497. //check Transaction active
  11498. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11499. {
  11500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11501. {
  11502. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11503. }
  11504. else
  11505. {
  11506. tempIndex = connectorIdInt -1;
  11507. }
  11508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11509. {
  11510. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11511. {
  11512. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11513. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11514. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11515. {
  11516. //Reserved
  11517. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11518. }
  11519. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11520. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11521. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11522. {
  11523. //Reserved
  11524. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11525. {
  11526. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11527. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11528. goto end;
  11529. }
  11530. }
  11531. else
  11532. {
  11533. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11534. {
  11535. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11536. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11537. goto end;
  11538. }
  11539. }//END FOR ELSE
  11540. }
  11541. }// END FOR CHAdeMO_QUANTITY
  11542. }
  11543. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11544. {
  11545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11546. {
  11547. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11548. }
  11549. else
  11550. {
  11551. tempIndex = connectorIdInt -1;
  11552. }
  11553. for (int index = 0; index < CCS_QUANTITY; index++)
  11554. {
  11555. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11556. {
  11557. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11558. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11559. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11560. {
  11561. //Reserved
  11562. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11563. }
  11564. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11565. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11566. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11567. {
  11568. //Reserved
  11569. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11570. {
  11571. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11572. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11573. goto end;
  11574. }
  11575. }
  11576. else
  11577. {
  11578. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11579. {
  11580. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11581. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11582. goto end;
  11583. }
  11584. }// END FOR ELSE
  11585. }
  11586. }// END FOR CCS_QUANTITY
  11587. }
  11588. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11589. {
  11590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11591. {
  11592. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11593. }
  11594. else
  11595. {
  11596. tempIndex = connectorIdInt -1;
  11597. }
  11598. for (int index = 0; index < GB_QUANTITY; index++)
  11599. {
  11600. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11601. {
  11602. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11603. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11604. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11605. {
  11606. //Reserved
  11607. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11608. }
  11609. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11610. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11611. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11612. {
  11613. //Reserved
  11614. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11615. {
  11616. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11617. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11618. goto end;
  11619. }
  11620. }
  11621. else
  11622. {
  11623. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11624. {
  11625. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11626. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11627. goto end;
  11628. }
  11629. }// END FOR ELSE
  11630. }
  11631. } // END FOR GB_QUANTITY
  11632. }
  11633. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11634. {
  11635. tempIndex = connectorIdInt -1;
  11636. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11637. {
  11638. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11639. {
  11640. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11641. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11642. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11643. {
  11644. //Reserved
  11645. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11646. }
  11647. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11648. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11649. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11650. {
  11651. //Reserved
  11652. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11653. {
  11654. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11655. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11656. goto end;
  11657. }
  11658. }
  11659. else
  11660. {
  11661. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11662. {
  11663. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11664. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11665. goto end;
  11666. }
  11667. }// END FOR ELSE
  11668. }
  11669. } // END FOR GB_QUANTITY
  11670. }
  11671. else
  11672. {
  11673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11674. {
  11675. tempIndex = 2;
  11676. }
  11677. else
  11678. {
  11679. tempIndex = connectorIdInt -1;
  11680. }
  11681. for (int index = 0; index < AC_QUANTITY; index++)
  11682. {
  11683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11684. {
  11685. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11686. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11687. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11688. {
  11689. //Reserved
  11690. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11691. }
  11692. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11693. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11694. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11695. {
  11696. //Reserved
  11697. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11698. {
  11699. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11700. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11701. goto end;
  11702. }
  11703. }
  11704. else
  11705. {
  11706. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11707. {
  11708. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11709. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11710. goto end;
  11711. }
  11712. }//END FOR ELSE
  11713. }
  11714. }// END FOR AC_QUANTITY
  11715. }
  11716. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11717. {
  11718. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11719. {
  11720. // Save profile to file
  11721. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11722. system(cmdBuf);
  11723. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11724. fp = fopen(cmdBuf, "w");
  11725. 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));
  11726. fclose(fp);
  11727. }
  11728. else
  11729. {
  11730. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11731. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11732. goto end;
  11733. }
  11734. }
  11735. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11736. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11737. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11738. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11739. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11740. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11741. }
  11742. else
  11743. {
  11744. uint8_t isHasIdleConnector = FALSE;
  11745. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11746. {
  11747. DEBUG_INFO("Check not specified gun-%d type: %d\n", gun_index, gunType[gun_index]);
  11748. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11749. {
  11750. isHasIdleConnector = TRUE;
  11751. break;
  11752. }
  11753. }
  11754. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11755. {
  11756. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11757. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11758. {
  11759. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11760. {
  11761. // Save profile to file
  11762. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11763. system(cmdBuf);
  11764. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11765. fp = fopen(cmdBuf, "w");
  11766. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11767. fclose(fp);
  11768. refreshStartTimer(&clientTime.RemoteStartWait);
  11769. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11770. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11771. }
  11772. else
  11773. {
  11774. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11775. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11776. }
  11777. }
  11778. else
  11779. {
  11780. refreshStartTimer(&clientTime.RemoteStartWait);
  11781. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11782. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11783. }
  11784. }
  11785. else
  11786. {
  11787. DEBUG_INFO("There is not any connector is idle.\n");
  11788. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11789. }
  11790. }
  11791. }
  11792. else
  11793. {
  11794. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11795. }
  11796. end:
  11797. json_object_put(RemoteStartTransaction);
  11798. sendRemoteStartConfirmation(uuid, comfirmstr);
  11799. return result;
  11800. }
  11801. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11802. {
  11803. mtrace();
  11804. int result = FAIL;
  11805. int match = FALSE;
  11806. int GunNO = 0;
  11807. int tempIndex = 0;
  11808. int transactionIdInt=0;
  11809. int transactionIdIsNULL= TRUE;
  11810. char comfirmstr[20];
  11811. json_object *RemoteStopTransaction;
  11812. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11813. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11814. if(server_pending == TRUE)
  11815. {
  11816. return 0;
  11817. }
  11818. RemoteStopTransaction = json_tokener_parse(payload);
  11819. if(!is_error(RemoteStopTransaction))
  11820. {
  11821. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11822. {
  11823. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11824. transactionIdIsNULL = FALSE;
  11825. }
  11826. }
  11827. json_object_put(RemoteStopTransaction);
  11828. if(transactionIdIsNULL == FALSE)
  11829. {
  11830. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11831. {
  11832. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11833. {
  11834. //check Transaction active
  11835. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11836. {
  11837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11838. {
  11839. tempIndex = ((gun_index==2) ? 1: 0);
  11840. }
  11841. else
  11842. {
  11843. tempIndex = gun_index;
  11844. }
  11845. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11846. {
  11847. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11848. {
  11849. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11850. {
  11851. match = TRUE;
  11852. GunNO = gun_index;
  11853. }
  11854. }
  11855. }// END FOR CHAdeMO_QUANTITY
  11856. }
  11857. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11858. {
  11859. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11860. {
  11861. tempIndex = ((gun_index==2) ? 1: 0);
  11862. }
  11863. else
  11864. {
  11865. tempIndex = gun_index;
  11866. }
  11867. for (int index = 0; index < CCS_QUANTITY; index++)
  11868. {
  11869. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11870. {
  11871. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11872. {
  11873. match = TRUE;
  11874. GunNO = gun_index;
  11875. }
  11876. }
  11877. }// END FOR CCS_QUANTITY
  11878. }
  11879. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11880. {
  11881. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11882. {
  11883. tempIndex = ((gun_index==2) ? 1: 0);
  11884. }
  11885. else
  11886. {
  11887. tempIndex = gun_index;
  11888. }
  11889. for (int index = 0; index < GB_QUANTITY; index++)
  11890. {
  11891. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11892. {
  11893. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11894. {
  11895. match = TRUE;
  11896. GunNO = gun_index;
  11897. }
  11898. }
  11899. }// END FOR GB_QUANTITY
  11900. }
  11901. else if(gunType[gun_index] == GUN_TYPE_DO)
  11902. {
  11903. tempIndex = gun_index;
  11904. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11905. {
  11906. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11907. {
  11908. 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
  11909. {
  11910. match = TRUE;
  11911. GunNO = gun_index;
  11912. }
  11913. }
  11914. }// END FOR GB_QUANTITY
  11915. }
  11916. else
  11917. {
  11918. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11919. {
  11920. tempIndex = 2;
  11921. }
  11922. else
  11923. {
  11924. tempIndex = gun_index;
  11925. }
  11926. for (int index = 0; index < AC_QUANTITY; index++)
  11927. {
  11928. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11929. {
  11930. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11931. {
  11932. match = TRUE;
  11933. GunNO = gun_index;
  11934. }
  11935. }
  11936. }// END FOR CHAdeMO_QUANTITY
  11937. } // END FOR AC ELSE
  11938. }// CHECK IF ResponseTransactionId == transactionIdInt
  11939. }//END FOR
  11940. if( match == TRUE)
  11941. {
  11942. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11943. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11944. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11945. }
  11946. else
  11947. {
  11948. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11949. }
  11950. }
  11951. else
  11952. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11953. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11954. return result;
  11955. }
  11956. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11957. {
  11958. mtrace();
  11959. int result = FAIL;
  11960. int connectorIdInt=0, reservationIdInt=0;
  11961. int tempIndex = 0;
  11962. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11963. char comfirmstr[20]={0};
  11964. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11965. int c = 0;
  11966. char *loc;
  11967. //char *ptr;
  11968. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11969. strcpy(sstrtemp, stringtrimspace(payload));
  11970. //***(1)connectorId ****/
  11971. c=0;
  11972. loc = strstr(sstrtemp, "connectorId");
  11973. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11974. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11975. {
  11976. sstr[c] = loc[strlen("connectorId")+2+c];
  11977. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11978. c++;
  11979. }
  11980. sstr[c] = '\0';
  11981. connectorIdInt = atoi(sstr);
  11982. //***(2)expiryDate ****/
  11983. loc = strstr(sstrtemp, "expiryDate");
  11984. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11985. c = 0;
  11986. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11987. {
  11988. sstr[c] = loc[3+strlen("expiryDate")+c];
  11989. c++;
  11990. }
  11991. sstr[c] = '\0';
  11992. strcpy(expiryDatestr, sstr);
  11993. //***(3)idTag ****/
  11994. loc = strstr(sstrtemp, "idTag");
  11995. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11996. c = 0;
  11997. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11998. {
  11999. sstr[c] = loc[3+strlen("idTag")+c];
  12000. c++;
  12001. }
  12002. sstr[c] = '\0';
  12003. strcpy(idTagstr, sstr);
  12004. //***(4)parentIdTag ****/
  12005. loc = strstr(sstrtemp, "parentIdTag");
  12006. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12007. c = 0;
  12008. if(loc == NULL)
  12009. {
  12010. strcpy(parentIdTagstr, "");
  12011. }
  12012. else
  12013. {
  12014. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  12015. {
  12016. sstr[c] = loc[3+strlen("parentIdTag")+c];
  12017. c++;
  12018. }
  12019. sstr[c] = '\0';
  12020. strcpy(parentIdTagstr, sstr);
  12021. }
  12022. //***(5)reservationId ****/
  12023. c=0;
  12024. loc = strstr(sstrtemp, "reservationId");
  12025. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12026. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  12027. {
  12028. sstr[c] = loc[strlen("reservationId")+2+c];
  12029. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12030. c++;
  12031. }
  12032. sstr[c] = '\0';
  12033. reservationIdInt = atoi(sstr);
  12034. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12035. /*
  12036. enum SYSTEM_STATUS
  12037. {
  12038. SYS_MODE_BOOTING = 0,
  12039. SYS_MODE_IDLE = 1,
  12040. SYS_MODE_AUTHORIZING = 2,
  12041. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12042. SYS_MODE_REASSIGN = 4,
  12043. SYS_MODE_PREPARING = 5,
  12044. SYS_MODE_PREPARE_FOR_EV = 6,
  12045. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12046. SYS_MODE_CHARGING = 8,
  12047. SYS_MODE_TERMINATING = 9,
  12048. SYS_MODE_COMPLETE = 10,
  12049. SYS_MODE_ALARM = 11,
  12050. SYS_MODE_FAULT = 12,
  12051. SYS_MODE_RESERVATION = 13,
  12052. SYS_MODE_BOOKING = 14,
  12053. SYS_MODE_MAINTAIN = 15,
  12054. SYS_MODE_DEBUG = 16,
  12055. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12056. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12057. SYS_MODE_UPDATE = 19
  12058. };
  12059. */
  12060. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12061. {
  12062. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12063. goto end;
  12064. }
  12065. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12066. {
  12067. //check Transaction active
  12068. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12069. {
  12070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12071. {
  12072. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12073. }
  12074. else
  12075. {
  12076. tempIndex = connectorIdInt -1;
  12077. }
  12078. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12079. {
  12080. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12081. {
  12082. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12083. {
  12084. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12085. {
  12086. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12087. {
  12088. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12089. {
  12090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12091. }
  12092. else
  12093. {
  12094. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12096. }
  12097. }
  12098. 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'))
  12099. {
  12100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12101. }
  12102. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12103. {
  12104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12105. }
  12106. else
  12107. {
  12108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12109. }
  12110. }
  12111. 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
  12112. {
  12113. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12114. }
  12115. }
  12116. else
  12117. {
  12118. //replace reservation
  12119. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12121. }
  12122. }
  12123. } // END FOR CHAdeMO_QUANTITY
  12124. }
  12125. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12126. {
  12127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12128. {
  12129. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12130. }
  12131. else
  12132. {
  12133. tempIndex = connectorIdInt -1;
  12134. }
  12135. for (int index = 0; index < CCS_QUANTITY; index++)
  12136. {
  12137. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12138. {
  12139. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12140. {
  12141. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12142. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12143. {
  12144. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12145. {
  12146. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12147. {
  12148. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12149. }
  12150. else
  12151. {
  12152. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12153. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12154. }
  12155. }
  12156. 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'))
  12157. {
  12158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12159. }
  12160. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12161. {
  12162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12163. }
  12164. else
  12165. {
  12166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12167. }
  12168. }
  12169. 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
  12170. {
  12171. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12172. }
  12173. }
  12174. else
  12175. {
  12176. //replace reservation
  12177. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12178. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12179. }
  12180. }
  12181. } // END FOR CCS_QUANTITY
  12182. }
  12183. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12184. {
  12185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12186. {
  12187. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12188. }
  12189. else
  12190. {
  12191. tempIndex = connectorIdInt -1;
  12192. }
  12193. for (int index = 0; index < GB_QUANTITY; index++)
  12194. {
  12195. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12196. {
  12197. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12198. {
  12199. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12200. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12201. {
  12202. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12203. {
  12204. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12205. {
  12206. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12207. }
  12208. else
  12209. {
  12210. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12211. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12212. }
  12213. }
  12214. 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'))
  12215. {
  12216. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12217. }
  12218. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12219. {
  12220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12221. }
  12222. else
  12223. {
  12224. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12225. }
  12226. }
  12227. 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
  12228. {
  12229. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12230. }
  12231. }
  12232. else
  12233. {
  12234. //replace reservation
  12235. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12236. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12237. }
  12238. }
  12239. }// END FOR GB_QUANTITY
  12240. }
  12241. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12242. {
  12243. tempIndex = connectorIdInt -1;
  12244. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12245. {
  12246. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12247. {
  12248. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12249. {
  12250. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12251. 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
  12252. {
  12253. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12254. {
  12255. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12256. {
  12257. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12258. }
  12259. else
  12260. {
  12261. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12262. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12263. }
  12264. }
  12265. 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'))
  12266. {
  12267. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12268. }
  12269. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12270. {
  12271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12272. }
  12273. else
  12274. {
  12275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12276. }
  12277. }
  12278. 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
  12279. {
  12280. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12281. }
  12282. }
  12283. else
  12284. {
  12285. //replace reservation
  12286. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12287. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12288. }
  12289. }
  12290. }// END FOR GB_QUANTITY
  12291. }
  12292. else
  12293. {
  12294. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12295. {
  12296. tempIndex = 2;
  12297. }
  12298. else
  12299. {
  12300. tempIndex = (connectorIdInt -1);
  12301. }
  12302. for (int index = 0; index < AC_QUANTITY; index++)
  12303. {
  12304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12305. {
  12306. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12307. {
  12308. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12309. {
  12310. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12311. {
  12312. 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))
  12313. {
  12314. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12315. }
  12316. else
  12317. {
  12318. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12319. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12320. }
  12321. }
  12322. 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'))
  12323. {
  12324. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12325. }
  12326. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12327. {
  12328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12329. }
  12330. else
  12331. {
  12332. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12333. }
  12334. }
  12335. 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
  12336. {
  12337. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12338. }
  12339. }
  12340. else
  12341. {
  12342. //replace reservation
  12343. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12344. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12345. }
  12346. }
  12347. } // END FOR AC_QUANTITY
  12348. }
  12349. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12350. }
  12351. else if(connectorIdInt == 0)
  12352. {
  12353. //check Transaction active
  12354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12355. {
  12356. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12357. {
  12358. 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'))
  12359. {
  12360. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12361. goto end;
  12362. }
  12363. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12364. {
  12365. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12366. goto end;
  12367. }
  12368. 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
  12369. {
  12370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12371. goto end;
  12372. }
  12373. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12374. {
  12375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12376. goto end;
  12377. }
  12378. }
  12379. }// END FOR CHAdeMO_QUANTITY
  12380. for (int index = 0; index < CCS_QUANTITY; index++)
  12381. {
  12382. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12383. {
  12384. 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'))
  12385. {
  12386. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12387. goto end;
  12388. }
  12389. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12390. {
  12391. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12392. goto end;
  12393. }
  12394. 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
  12395. {
  12396. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12397. goto end;
  12398. }
  12399. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12400. {
  12401. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12402. goto end;
  12403. }
  12404. }
  12405. } // END FOR CCS_QUANTITY
  12406. for (int index = 0; index < GB_QUANTITY; index++)
  12407. {
  12408. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12409. {
  12410. 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'))
  12411. {
  12412. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12413. goto end;
  12414. }
  12415. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12416. {
  12417. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12418. goto end;
  12419. }
  12420. 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
  12421. {
  12422. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12423. goto end;
  12424. }
  12425. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12426. {
  12427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12428. goto end;
  12429. }
  12430. }
  12431. } // END FOR GB_QUANTITY
  12432. for (int index = 0; index < AC_QUANTITY; index++)
  12433. {
  12434. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12435. {
  12436. 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'))
  12437. {
  12438. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12439. goto end;
  12440. }
  12441. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12442. {
  12443. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12444. goto end;
  12445. }
  12446. 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
  12447. {
  12448. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12449. goto end;
  12450. }
  12451. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12452. {
  12453. 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))
  12454. {
  12455. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12456. goto end;
  12457. }
  12458. }
  12459. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12460. {
  12461. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12462. goto end;
  12463. }
  12464. }
  12465. }// END FOR AC_QUANTITY
  12466. //The connectorId is 0
  12467. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12469. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12470. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12471. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12472. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12473. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12474. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12475. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12476. result = TRUE;
  12477. return result;
  12478. }
  12479. else
  12480. {
  12481. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12482. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12483. }
  12484. if(strcmp(comfirmstr,"Accepted") == 0)
  12485. {
  12486. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12487. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12488. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12489. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12490. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12491. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12492. result = TRUE;
  12493. return result;
  12494. }
  12495. end:
  12496. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12497. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12498. return result;
  12499. }
  12500. int handleResetRequest(char *uuid, char *payload)
  12501. {
  12502. mtrace();
  12503. int result = FAIL;
  12504. char sstr[10]={0},sstrtemp[30]={ 0 };
  12505. char typestr[10]={0};
  12506. char comfirmstr[20]={0};
  12507. int c = 0;
  12508. char *loc;
  12509. DEBUG_INFO("handleResetRequest...\n");
  12510. strcpy(sstrtemp, stringtrimspace(payload));
  12511. loc = strstr(sstrtemp, "type");
  12512. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12513. c = 0;
  12514. while (loc[3+strlen("type")+c] != '\"')
  12515. {
  12516. sstr[c] = loc[3+strlen("type")+c];
  12517. c++;
  12518. }
  12519. sstr[c] = '\0';
  12520. strcpy(typestr,sstr);
  12521. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12522. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12523. {
  12524. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12525. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12526. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12527. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12528. }
  12529. else
  12530. {
  12531. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12532. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12533. result = PASS;
  12534. }
  12535. sendResetConfirmation(uuid, comfirmstr);
  12536. return result;
  12537. }
  12538. int handleSendLocalListRequest(char *uuid, char *payload)
  12539. {
  12540. mtrace();
  12541. int result = FAIL;
  12542. char comfirmstr[20];
  12543. int checkState_Faulted = FALSE;
  12544. json_object *SendLocalList;
  12545. DEBUG_INFO("handleSendLocalListRequest...\n");
  12546. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12547. {
  12548. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12549. goto end;
  12550. }
  12551. //check Charge Point state
  12552. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12553. {
  12554. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12555. {
  12556. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12557. }
  12558. }
  12559. for (int index = 0; index < CCS_QUANTITY; index++)
  12560. {
  12561. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12562. {
  12563. checkState_Faulted = TRUE; //OCPP Status
  12564. }
  12565. }
  12566. for (int index = 0; index < GB_QUANTITY; index++)
  12567. {
  12568. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12569. {
  12570. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12571. }
  12572. }
  12573. //check Charge Point state
  12574. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12575. {
  12576. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12577. {
  12578. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12579. }
  12580. }
  12581. //check Charge Point state
  12582. for (int index = 0; index < AC_QUANTITY; index++)
  12583. {
  12584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12585. {
  12586. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12587. }
  12588. }
  12589. if(checkState_Faulted == TRUE)
  12590. {
  12591. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12592. goto end;
  12593. }
  12594. // Parsing payload
  12595. SendLocalList = json_tokener_parse(payload);
  12596. if(!is_error(SendLocalList))
  12597. {
  12598. // Required data
  12599. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12600. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12601. // Optional data
  12602. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12603. {
  12604. //Check UpdateType
  12605. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12606. {
  12607. //Local list full update
  12608. DEBUG_INFO("Local list full update.\n");
  12609. locallistVersion = 0;
  12610. OCPP_getListVerion();
  12611. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12612. {
  12613. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12614. goto end;
  12615. }
  12616. OCPP_cleanLocalList();
  12617. }
  12618. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12619. {
  12620. //Local list different update
  12621. DEBUG_INFO("Local list different update.\n");
  12622. locallistVersion = 0;
  12623. OCPP_getListVerion();
  12624. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12625. {
  12626. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12627. goto end;
  12628. }
  12629. }
  12630. else
  12631. {
  12632. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12633. goto end;
  12634. }
  12635. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12636. {
  12637. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12638. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12639. goto end;
  12640. }
  12641. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12642. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12643. {
  12644. 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"))));
  12645. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12646. {
  12647. 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"))));
  12648. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12649. 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"))));
  12650. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12651. 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"))));
  12652. }
  12653. // Add to db
  12654. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12655. {
  12656. //Local list full update
  12657. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12658. idx,
  12659. ShmOCPP16Data->SendLocalList.ListVersion,
  12660. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12661. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12662. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12663. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12664. // update list
  12665. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12666. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12667. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12668. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12669. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12670. }
  12671. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12672. {
  12673. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12674. idx,
  12675. ShmOCPP16Data->SendLocalList.ListVersion,
  12676. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12677. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12678. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12679. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12680. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12681. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12682. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12683. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12684. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12685. }
  12686. }
  12687. }
  12688. else
  12689. {
  12690. //Check UpdateType
  12691. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12692. {
  12693. //Local list full update
  12694. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12695. OCPP_cleanLocalList();
  12696. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12697. goto end;
  12698. }
  12699. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12700. {
  12701. //Local list different update
  12702. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12703. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12704. goto end;
  12705. }
  12706. }
  12707. result = PASS;
  12708. }
  12709. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12710. end:
  12711. json_object_put(SendLocalList);
  12712. sendSendLocalListConfirmation(uuid, comfirmstr);
  12713. return result;
  12714. }
  12715. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12716. {
  12717. mtrace();
  12718. int result = FAIL;
  12719. struct StructSetChargingProfile SetProfileReq = {0};
  12720. int tempchargingProfileIdInt;
  12721. int tempstackLevelInt;
  12722. int chargingSchedulePeriodCount = 0;
  12723. char comfirmstr[20]={0};
  12724. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12725. char rmFileCmd[128]={0};
  12726. int profileQuantity = 0;
  12727. int replaceableProfileCnt = 0;
  12728. json_object *SetChargingProfile;
  12729. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12730. SetChargingProfile = json_tokener_parse(payload);
  12731. if(!is_error(SetChargingProfile))
  12732. {
  12733. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12734. {
  12735. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12736. }
  12737. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12738. {
  12739. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12740. {
  12741. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12742. }
  12743. else
  12744. {
  12745. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12746. DEBUG_WARN("Cannot find chargingProfileId field.");
  12747. goto end;
  12748. }
  12749. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12750. {
  12751. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12752. }
  12753. else
  12754. {
  12755. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12756. DEBUG_WARN("Cannot find stackLevel field.");
  12757. goto end;
  12758. }
  12759. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12760. {
  12761. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12762. }
  12763. else
  12764. {
  12765. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12766. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12767. goto end;
  12768. }
  12769. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12770. {
  12771. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12772. }
  12773. else
  12774. {
  12775. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12776. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12777. goto end;
  12778. }
  12779. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12780. {
  12781. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12782. }
  12783. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12784. {
  12785. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12786. }
  12787. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12788. {
  12789. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12790. }
  12791. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12792. {
  12793. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12794. }
  12795. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12796. {
  12797. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12798. {
  12799. 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")));
  12800. }
  12801. else
  12802. {
  12803. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12804. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12805. goto end;
  12806. }
  12807. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12808. {
  12809. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12810. }
  12811. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12812. {
  12813. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12814. }
  12815. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12816. {
  12817. 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")));
  12818. }
  12819. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12820. {
  12821. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12822. if(chargingSchedulePeriodCount <= 10)
  12823. {
  12824. 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++)
  12825. {
  12826. 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)
  12827. {
  12828. 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"));
  12829. }
  12830. else
  12831. {
  12832. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12833. DEBUG_WARN("Cannot find startPeriod field.");
  12834. goto end;
  12835. }
  12836. 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)
  12837. {
  12838. 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"));
  12839. }
  12840. else
  12841. {
  12842. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12843. DEBUG_WARN("Cannot find limit field.");
  12844. goto end;
  12845. }
  12846. 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)
  12847. {
  12848. 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"));
  12849. }
  12850. }
  12851. }
  12852. }
  12853. else
  12854. {
  12855. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12856. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12857. goto end;
  12858. }
  12859. }
  12860. else
  12861. {
  12862. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12863. DEBUG_WARN("Cannot find chargingSchedule field.");
  12864. goto end;
  12865. }
  12866. }
  12867. }
  12868. // Profile periods quantity check
  12869. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12870. {
  12871. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12872. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12873. goto end;
  12874. }
  12875. // Check invalid limit
  12876. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12877. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12878. {
  12879. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12880. {
  12881. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12882. {
  12883. 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)))) ||
  12884. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12885. {
  12886. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12887. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12888. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12889. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12890. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12891. goto end;
  12892. }
  12893. }
  12894. }
  12895. else
  12896. {
  12897. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12898. {
  12899. 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) ||
  12900. (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)))
  12901. {
  12902. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12903. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12904. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12905. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12906. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12907. goto end;
  12908. }
  12909. }
  12910. }
  12911. }
  12912. // Profile purpose info check
  12913. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12914. {
  12915. FILE *fp;
  12916. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12917. if(SetProfileReq.ConnectorId != 0)
  12918. {
  12919. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12920. DEBUG_WARN("Profile connector id is not 0.\n");
  12921. goto end;
  12922. }
  12923. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12924. if (!fp)
  12925. {
  12926. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12927. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12928. }
  12929. else
  12930. {
  12931. char *line = NULL;
  12932. size_t len = 0;
  12933. while(getline(&line, &len, fp) != -1)
  12934. {
  12935. json_object *obj = NULL;
  12936. obj = json_tokener_parse(line);
  12937. if(is_error(obj))
  12938. {
  12939. DEBUG_ERROR("Parse txProfile from file error.\n");
  12940. }
  12941. else
  12942. {
  12943. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12944. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12945. {
  12946. profileQuantity += 1;
  12947. }
  12948. else
  12949. replaceableProfileCnt += 1;
  12950. }
  12951. }
  12952. }
  12953. fclose(fp);
  12954. }
  12955. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12956. {
  12957. FILE *fp;
  12958. char filename[128]={0};
  12959. int tmpProfileQuantity;
  12960. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12961. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12962. {
  12963. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12964. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12965. goto end;
  12966. }
  12967. if(SetProfileReq.ConnectorId == 0)
  12968. {
  12969. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12970. {
  12971. tmpProfileQuantity = 0;
  12972. memset(filename, 0, ARRAY_SIZE(filename));
  12973. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12974. fp = fopen(filename, "r");
  12975. if (!fp)
  12976. {
  12977. DEBUG_INFO("%s does not create.\n", filename);
  12978. fp = fopen(filename, "w+");
  12979. }
  12980. else
  12981. {
  12982. char *line = NULL;
  12983. size_t len = 0;
  12984. while(getline(&line, &len, fp) != -1)
  12985. {
  12986. json_object *obj = NULL;
  12987. obj = json_tokener_parse(line);
  12988. if(is_error(obj))
  12989. {
  12990. DEBUG_ERROR("Parse txProfile from file error.\n");
  12991. }
  12992. else
  12993. {
  12994. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12995. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12996. {
  12997. tmpProfileQuantity += 1;
  12998. }
  12999. else
  13000. replaceableProfileCnt += 1;
  13001. }
  13002. }
  13003. }
  13004. fclose(fp);
  13005. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  13006. }
  13007. }
  13008. else
  13009. {
  13010. memset(filename, 0, ARRAY_SIZE(filename));
  13011. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13012. fp = fopen(filename, "r");
  13013. if (!fp)
  13014. {
  13015. DEBUG_INFO("%s does not create.\n", filename);
  13016. fp = fopen(filename, "w+");
  13017. }
  13018. else
  13019. {
  13020. char *line = NULL;
  13021. size_t len = 0;
  13022. while(getline(&line, &len, fp) != -1)
  13023. {
  13024. json_object *obj = NULL;
  13025. obj = json_tokener_parse(line);
  13026. if(is_error(obj))
  13027. {
  13028. DEBUG_ERROR("Parse txProfile from file error.\n");
  13029. }
  13030. else
  13031. {
  13032. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13033. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13034. {
  13035. profileQuantity += 1;
  13036. }
  13037. else
  13038. replaceableProfileCnt += 1;
  13039. }
  13040. }
  13041. }
  13042. fclose(fp);
  13043. }
  13044. }
  13045. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13046. {
  13047. int isMatchTransactiodId= FALSE;
  13048. FILE *fp;
  13049. char filename[128]={0};
  13050. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13051. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13052. if(SetProfileReq.ConnectorId == 0)
  13053. {
  13054. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13055. DEBUG_WARN("Profile connector id is 0.\n");
  13056. goto end;
  13057. }
  13058. int tempIndex = 0;
  13059. //check Transaction active
  13060. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13061. {
  13062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13063. {
  13064. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13065. }
  13066. else
  13067. {
  13068. tempIndex = SetProfileReq.ConnectorId -1;
  13069. }
  13070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13071. {
  13072. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13073. {
  13074. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13075. {
  13076. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13077. {
  13078. isMatchTransactiodId = TRUE;
  13079. break;
  13080. }
  13081. }
  13082. }
  13083. }
  13084. }
  13085. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13086. {
  13087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13088. {
  13089. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13090. }
  13091. else
  13092. {
  13093. tempIndex = SetProfileReq.ConnectorId -1;
  13094. }
  13095. for (int index = 0; index < CCS_QUANTITY; index++)
  13096. {
  13097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13098. {
  13099. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13100. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13101. {
  13102. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13103. {
  13104. isMatchTransactiodId = TRUE;
  13105. break;
  13106. }
  13107. }
  13108. }
  13109. }
  13110. }
  13111. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13112. {
  13113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13114. {
  13115. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13116. }
  13117. else
  13118. {
  13119. tempIndex = SetProfileReq.ConnectorId -1;
  13120. }
  13121. for (int index = 0; index < GB_QUANTITY; index++)
  13122. {
  13123. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13124. {
  13125. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13126. {
  13127. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13128. {
  13129. isMatchTransactiodId = TRUE;
  13130. break;
  13131. }
  13132. }
  13133. }
  13134. }
  13135. }
  13136. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13137. {
  13138. tempIndex = SetProfileReq.ConnectorId -1;
  13139. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13140. {
  13141. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13142. {
  13143. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13144. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13145. {
  13146. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13147. {
  13148. isMatchTransactiodId = TRUE;
  13149. break;
  13150. }
  13151. }
  13152. }
  13153. }
  13154. }
  13155. else
  13156. {
  13157. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13158. {
  13159. tempIndex = 2;
  13160. }
  13161. else
  13162. {
  13163. tempIndex = (SetProfileReq.ConnectorId -1);
  13164. }
  13165. for (int index = 0; index < AC_QUANTITY; index++)
  13166. {
  13167. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13168. {
  13169. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13170. {
  13171. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13172. {
  13173. isMatchTransactiodId = TRUE;
  13174. break;
  13175. }
  13176. }
  13177. }
  13178. }
  13179. }
  13180. //check Transaction active
  13181. if(isMatchTransactiodId == FALSE)
  13182. {
  13183. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13184. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13185. goto end;
  13186. }
  13187. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13188. {
  13189. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13190. DEBUG_WARN("Connector id is over max gun number.\n");
  13191. goto end;
  13192. }
  13193. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13194. fp = fopen(filename, "r");
  13195. if (!fp)
  13196. {
  13197. DEBUG_INFO("%s does not create.\n", filename);
  13198. fp = fopen(filename, "w+");
  13199. }
  13200. else
  13201. {
  13202. char *line = NULL;
  13203. size_t len = 0;
  13204. while(getline(&line, &len, fp) != -1)
  13205. {
  13206. json_object *obj = NULL;
  13207. obj = json_tokener_parse(line);
  13208. if(is_error(obj))
  13209. {
  13210. DEBUG_ERROR("Parse txProfile from file error.\n");
  13211. }
  13212. else
  13213. {
  13214. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13215. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13216. {
  13217. profileQuantity += 1;
  13218. }
  13219. else
  13220. replaceableProfileCnt += 1;
  13221. }
  13222. }
  13223. }
  13224. fclose(fp);
  13225. }
  13226. // Check ChargeProfileMaxStackLevel
  13227. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13228. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13229. {
  13230. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13231. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13232. goto end;
  13233. }
  13234. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13235. {
  13236. FILE *fp;
  13237. char dataLine[4096]={0};
  13238. char fnametemp[128]={0};
  13239. int tmpProfileQuantity;
  13240. //Check ChargePointMaxProfile.json exit
  13241. profileQuantity = 0;
  13242. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13243. {
  13244. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13245. //Check Charging Profile Count
  13246. tmpProfileQuantity = 0;
  13247. while(fscanf(fp, "%s", dataLine) != EOF)
  13248. {
  13249. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13250. {
  13251. profileQuantity += 1;
  13252. tmpProfileQuantity += 1;
  13253. }
  13254. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13255. }
  13256. fclose(fp);
  13257. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13258. }
  13259. //Check TxDefaultProfile_%d.json
  13260. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13261. {
  13262. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13263. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13264. if((access(fnametemp,F_OK))!=-1)
  13265. {
  13266. fp = fopen(fnametemp, "r");
  13267. //Check Charging Profile Count
  13268. tmpProfileQuantity = 0;
  13269. while(fscanf(fp, "%s", dataLine) != EOF)
  13270. {
  13271. //DEBUG_INFO("word=%s\n",word);
  13272. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13273. {
  13274. profileQuantity += 1;
  13275. tmpProfileQuantity += 1;
  13276. }
  13277. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13278. }
  13279. fclose(fp);
  13280. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13281. }
  13282. }
  13283. //Check TxProfile_%d.json
  13284. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13285. {
  13286. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13287. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13288. if((access(fnametemp,F_OK))!=-1)
  13289. {
  13290. fp = fopen(fnametemp, "r");
  13291. //Check Charging Profile Count
  13292. tmpProfileQuantity = 0;
  13293. while(fscanf(fp, "%s", dataLine) != EOF)
  13294. {
  13295. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13296. {
  13297. profileQuantity += 1;
  13298. tmpProfileQuantity += 1;
  13299. }
  13300. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13301. }
  13302. fclose(fp);
  13303. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13304. }
  13305. }
  13306. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13307. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13308. // To check total Profile quantity
  13309. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13310. {
  13311. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13312. {
  13313. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13314. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13315. goto end;
  13316. }
  13317. }
  13318. else
  13319. {
  13320. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13321. {
  13322. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13323. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13324. goto end;
  13325. }
  13326. }
  13327. }
  13328. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13329. //**********************************Write to File********************************************************/
  13330. {
  13331. FILE *infile;
  13332. FILE *outfile;
  13333. char dataLine[4096]={0};
  13334. char filename[128]={0};
  13335. int chkChar=0;
  13336. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13337. {
  13338. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13339. {
  13340. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13341. }
  13342. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13343. {
  13344. if(SetProfileReq.ConnectorId==0)
  13345. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13346. else
  13347. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13348. }
  13349. else
  13350. {
  13351. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13352. }
  13353. infile = fopen (filename, "r");
  13354. outfile = fopen (tempfile, "w");
  13355. chkChar = fgetc(infile);
  13356. rewind(infile);
  13357. if(chkChar == EOF)
  13358. {
  13359. // Profile is empty
  13360. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13361. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13362. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13363. fclose(infile);
  13364. fclose(outfile);
  13365. sprintf(rmFileCmd,"rm -f %s",filename);
  13366. system(rmFileCmd);
  13367. rename(tempfile, filename);
  13368. }
  13369. else
  13370. {
  13371. // Profile is not empty
  13372. int ChargingProfileAdded = FALSE;
  13373. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13374. {
  13375. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13376. json_object *tmpChargingProfile;
  13377. tmpChargingProfile = json_tokener_parse(dataLine);
  13378. if(!is_error(SetChargingProfile))
  13379. {
  13380. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13381. {
  13382. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13383. {
  13384. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13385. }
  13386. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13387. {
  13388. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13389. }
  13390. }
  13391. }
  13392. json_object_put(tmpChargingProfile);
  13393. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13394. {
  13395. if(ChargingProfileAdded == FALSE)
  13396. {
  13397. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13398. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13399. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13400. ChargingProfileAdded = TRUE;
  13401. }
  13402. }
  13403. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13404. {
  13405. if(ChargingProfileAdded == FALSE)
  13406. {
  13407. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13408. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13409. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13410. ChargingProfileAdded = TRUE;
  13411. }
  13412. }
  13413. else
  13414. {
  13415. fprintf(outfile,"%s\n",dataLine);
  13416. if(ChargingProfileAdded == FALSE)
  13417. {
  13418. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13419. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13420. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13421. ChargingProfileAdded = TRUE;
  13422. }
  13423. }
  13424. } // end of while loop
  13425. fclose(infile);
  13426. fclose(outfile);
  13427. sprintf(rmFileCmd,"rm -f %s",filename);
  13428. system(rmFileCmd);
  13429. rename(tempfile, filename);
  13430. }
  13431. }
  13432. sleep(1);
  13433. result = TRUE;
  13434. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13435. }
  13436. end:
  13437. json_object_put(SetChargingProfile);
  13438. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13439. {
  13440. if(SetProfileReq.ConnectorId == 0)
  13441. {
  13442. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13443. {
  13444. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13445. }
  13446. }
  13447. else
  13448. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13449. }
  13450. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13451. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13452. return result;
  13453. }
  13454. int handleTriggerMessageRequest(char *uuid, char *payload)
  13455. {
  13456. mtrace();
  13457. int result = FAIL;
  13458. int connectorIdIsNULL = FALSE;
  13459. int connectorIdInt =0;
  13460. char sstr[40]={0},sstrtemp[100]={ 0 };
  13461. char requestedMessagestr[40]={0};
  13462. char comfirmstr[20]={0};
  13463. int c = 0;
  13464. char *loc;
  13465. DEBUG_INFO("handleTriggerMessageRequest\n");
  13466. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13467. strcpy(sstrtemp, stringtrimspace(payload));
  13468. c = 0;
  13469. loc = strstr(sstrtemp, "requestedMessage");
  13470. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13471. {
  13472. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13473. c++;
  13474. }
  13475. sstr[c] = '\0';
  13476. strcpy(requestedMessagestr, sstr);
  13477. c = 0;
  13478. loc = strstr(sstrtemp, "connectorId");
  13479. if(loc == NULL)
  13480. {
  13481. connectorIdIsNULL = TRUE;
  13482. }
  13483. else
  13484. {
  13485. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13486. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13487. {
  13488. sstr[c] = loc[strlen("connectorId")+2+c];
  13489. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13490. c++;
  13491. }
  13492. sstr[c] = '\0';
  13493. connectorIdInt = atoi(sstr);
  13494. }
  13495. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13496. {
  13497. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13498. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13499. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13500. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13501. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13502. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13503. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13504. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13505. {
  13506. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13507. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13508. return TRUE;
  13509. }
  13510. else
  13511. {
  13512. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13513. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13514. }
  13515. }
  13516. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13517. {
  13518. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13519. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13520. return TRUE;
  13521. }
  13522. //==========================
  13523. // Trigger message
  13524. //==========================
  13525. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13526. {
  13527. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13528. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13529. {
  13530. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13531. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13532. }
  13533. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13534. }
  13535. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13536. {
  13537. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13538. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13539. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13540. }
  13541. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13542. {
  13543. //sendBootNotificationRequest();
  13544. server_sign = FALSE;
  13545. }
  13546. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13547. {
  13548. refreshStartTimer(&clientTime.Heartbeat);
  13549. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13550. }
  13551. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13552. {
  13553. if(connectorIdIsNULL == FALSE)
  13554. {
  13555. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13556. {
  13557. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13558. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13559. }
  13560. }
  13561. else
  13562. {
  13563. for(int idx=0;idx< gunTotalNumber;idx++)
  13564. {
  13565. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13566. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13567. }
  13568. }
  13569. }
  13570. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13571. {
  13572. if(connectorIdIsNULL == FALSE)
  13573. {
  13574. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13575. {
  13576. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13577. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13578. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13579. }
  13580. }
  13581. else
  13582. {
  13583. for(int idx=0;idx< gunTotalNumber;idx++)
  13584. {
  13585. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13586. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13587. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13588. }
  13589. }
  13590. }
  13591. return result;
  13592. }
  13593. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13594. {
  13595. mtrace();
  13596. int result = FAIL;
  13597. int connectorIdInt =0;
  13598. char comfirmstr[20]={0};
  13599. int tempIndex = 0;
  13600. json_object *UnlockConnector;
  13601. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13602. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13603. UnlockConnector = json_tokener_parse(payload);
  13604. if(!is_error(UnlockConnector))
  13605. {
  13606. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13607. {
  13608. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13609. }
  13610. }
  13611. json_object_put(UnlockConnector);
  13612. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13613. if(gunTotalNumber == 0)
  13614. {
  13615. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13616. goto end;
  13617. }
  13618. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13619. {
  13620. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13621. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13622. goto end;
  13623. }
  13624. else
  13625. {
  13626. //check Transaction active
  13627. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13628. {
  13629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13630. {
  13631. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13632. }
  13633. else
  13634. {
  13635. tempIndex = connectorIdInt -1;
  13636. }
  13637. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13638. {
  13639. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13640. {
  13641. //stop Transaction
  13642. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13643. }
  13644. }
  13645. }
  13646. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13647. {
  13648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13649. {
  13650. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13651. }
  13652. else
  13653. {
  13654. tempIndex = connectorIdInt -1;
  13655. }
  13656. for (int index = 0; index < CCS_QUANTITY; index++)
  13657. {
  13658. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13659. {
  13660. //stop Transaction
  13661. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13662. }
  13663. }
  13664. }
  13665. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13666. {
  13667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13668. {
  13669. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13670. }
  13671. else
  13672. {
  13673. tempIndex = connectorIdInt -1;
  13674. }
  13675. for (int index = 0; index < GB_QUANTITY; index++)
  13676. {
  13677. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13678. {
  13679. //stop Transaction
  13680. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13681. }
  13682. }
  13683. }
  13684. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13685. {
  13686. tempIndex = connectorIdInt -1;
  13687. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13688. {
  13689. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13690. {
  13691. //stop Transaction
  13692. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13693. }
  13694. }
  13695. }
  13696. else
  13697. {
  13698. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13699. {
  13700. tempIndex = 2;
  13701. }
  13702. else
  13703. {
  13704. tempIndex = connectorIdInt-1;
  13705. }
  13706. for (int index = 0; index < AC_QUANTITY; index++)
  13707. {
  13708. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13709. {
  13710. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13711. }
  13712. }
  13713. }
  13714. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13715. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13716. result = TRUE;
  13717. return result;
  13718. }
  13719. end:
  13720. //json_object_put(obj); --- remove temporally
  13721. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13722. return result;
  13723. }
  13724. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13725. {
  13726. mtrace();
  13727. int result = FAIL;
  13728. pthread_t t;
  13729. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13730. sendUpdateFirmwareConfirmation(uuid);
  13731. if(!interLock.isUpdateFirmwareGoing)
  13732. {
  13733. interLock.isUpdateFirmwareGoing = 1;
  13734. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13735. sleep(1);
  13736. }
  13737. else
  13738. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13739. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13740. return result;
  13741. }
  13742. void *UpdateFirmwareProcess(void *data)
  13743. {
  13744. pthread_detach(pthread_self());
  13745. mtrace();
  13746. int retriesInt =0, retryIntervalInt=0;
  13747. char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
  13748. int port=0;
  13749. char locationstr[2048]={0}, retrieveDatestr[36]={0};
  13750. int isSuccess = 0;
  13751. char ftpbuf[2048];
  13752. char temp[2048];
  13753. char * pch;
  13754. char filenametemp[256];
  13755. json_object *UpdateFirmware;
  13756. UpdateFirmware = json_tokener_parse(data);
  13757. if(!is_error(UpdateFirmware))
  13758. {
  13759. // Required data
  13760. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13761. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13762. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13763. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13764. // Optional data
  13765. if(json_object_object_get(UpdateFirmware, "retries"))
  13766. {
  13767. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13768. }
  13769. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13770. {
  13771. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13772. }
  13773. }
  13774. json_object_put(UpdateFirmware);
  13775. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13776. memset(path, 0, ARRAY_SIZE(path));
  13777. // Wait retrieveData
  13778. if(strlen(retrieveDatestr) > 10)
  13779. {
  13780. do
  13781. {
  13782. sleep(1);
  13783. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13784. }
  13785. // Ready to download
  13786. system("rm -f /mnt/*");
  13787. if(strncmp(locationstr,"http", 4) == 0)
  13788. {
  13789. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13790. sprintf(ftppath,"/%s", path);
  13791. DEBUG_INFO("locationstr: %s\n", locationstr);
  13792. DEBUG_INFO("protocol: %s\n",protocol);
  13793. DEBUG_INFO("host: %s\n",host);
  13794. DEBUG_INFO("path: %s\n",path);
  13795. DEBUG_INFO("ftppath: %s\n",ftppath);
  13796. int ftppathlen=strlen(ftppath);
  13797. int i=1;
  13798. while(i < ftppathlen)
  13799. {
  13800. int len=ftppathlen-i;
  13801. if(ftppath[len]== 47) // '/' ascll code: 47
  13802. {
  13803. DEBUG_INFO("compare '/' all right\n");
  13804. break;
  13805. }
  13806. i=i+1;
  13807. }
  13808. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13809. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13810. filenametemp[i+1] = 0;
  13811. do
  13812. {
  13813. sleep(1);
  13814. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13815. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13816. sleep(1);
  13817. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13818. if(!isSuccess)
  13819. {
  13820. sleep(1);
  13821. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13822. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13823. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13824. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13825. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13826. }
  13827. else
  13828. {
  13829. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13830. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13831. }
  13832. retriesInt--;
  13833. }while((isSuccess == 0)&&(retriesInt >= 0));
  13834. }
  13835. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13836. {
  13837. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13838. memset(temp, 0, ARRAY_SIZE(temp));
  13839. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13840. strcpy(ftpbuf, locationstr);
  13841. int ftppathlen=strlen(ftpbuf);
  13842. int i=1;
  13843. while(i < ftppathlen)
  13844. {
  13845. int len=ftppathlen-i;
  13846. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13847. {
  13848. DEBUG_INFO(" compare '/' all right\n");
  13849. break;
  13850. }
  13851. i=i+1;
  13852. }
  13853. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13854. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13855. filenametemp[i+1] = 0;
  13856. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13857. pch=strchr(temp,'@');
  13858. if(pch==NULL)
  13859. {
  13860. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13861. protocol, host, &port, path);
  13862. strcpy(user,"anonymous");
  13863. strcpy(password,"");
  13864. }
  13865. else
  13866. {
  13867. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13868. protocol, user, host, &port, path);
  13869. }
  13870. sscanf(host,"%[^/]%s",host1, path1);
  13871. sprintf(ftppath,"%s:/%s", host,path);
  13872. if(port == 0)
  13873. {
  13874. port = 21;
  13875. }
  13876. do
  13877. {
  13878. sleep(1);
  13879. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13880. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13881. sleep(1);
  13882. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13883. if(!isSuccess)
  13884. {
  13885. //BulldogUtil.sleepMs(interval*1000);
  13886. DEBUG_INFO("Update firmware request and download file fail.\n");
  13887. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13888. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13889. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13890. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13891. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13892. }
  13893. else
  13894. {
  13895. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13896. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13897. }
  13898. retriesInt--;
  13899. }while((!isSuccess)&&(retriesInt >= 0));
  13900. }
  13901. else if((strncmp(locationstr,"ftp", 3) == 0) || (strncmp(locationstr,"ftps", 4) == 0)) // ftp/ftps
  13902. {
  13903. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13904. memset(temp, 0, ARRAY_SIZE(temp));
  13905. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13906. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13907. int ftppathlen=strlen(ftpbuf);
  13908. int i=1;
  13909. while(i < ftppathlen)
  13910. {
  13911. int len=ftppathlen-i;
  13912. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13913. {
  13914. DEBUG_INFO(" compare '/' all right\n");
  13915. break;
  13916. }
  13917. i=i+1;
  13918. }
  13919. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13920. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13921. filenametemp[i+1] = 0;
  13922. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13923. pch=strchr(temp,'@');
  13924. if(pch==NULL)
  13925. {
  13926. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13927. protocol, host, &port, path);
  13928. strcpy(user,"anonymous");
  13929. strcpy(password,"");
  13930. }
  13931. else
  13932. {
  13933. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13934. protocol, user, password, host, &port, path);
  13935. }
  13936. sscanf(host,"%[^/]%s",host1, path1);
  13937. sprintf(ftppath,"%s", path1);
  13938. //DEBUG_INFO("protocol =%s\n",protocol);
  13939. //DEBUG_INFO("user =%s\n",user);
  13940. //DEBUG_INFO("password =%s\n",password);
  13941. //DEBUG_INFO("host1 =%s\n",host1);
  13942. //DEBUG_INFO("port =%d\n",port);
  13943. //DEBUG_INFO("path1 =%s\n",path1);
  13944. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13945. //ftpFile(host, user, password, port, ftppath, fname);
  13946. //download firmware pthred
  13947. if(port == 0)
  13948. {
  13949. port = 21;
  13950. }
  13951. do
  13952. {
  13953. sleep(1);
  13954. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13955. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13956. sleep(1);
  13957. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13958. if(!isSuccess)
  13959. {
  13960. //BulldogUtil.sleepMs(interval*1000);
  13961. DEBUG_INFO("Update firmware request and download file fail.\n");
  13962. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13963. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13964. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13965. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13966. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13967. }
  13968. else
  13969. {
  13970. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13971. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13972. }
  13973. retriesInt--;
  13974. }while((!isSuccess)&&(retriesInt >= 0));
  13975. }
  13976. else
  13977. {
  13978. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13979. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13980. sleep(1);
  13981. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13982. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13983. }
  13984. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13985. {
  13986. sleep(3);
  13987. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13988. }
  13989. interLock.isUpdateFirmwareGoing = 0;
  13990. pthread_exit(NULL);
  13991. }
  13992. int handleCertificateSignedRequest(char *uuid, char *payload)
  13993. {
  13994. mtrace();
  13995. int result = PASS;
  13996. json_object *CertificateSigned;
  13997. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13998. CertificateSigned = json_tokener_parse(payload);
  13999. if(!is_error(CertificateSigned))
  14000. {
  14001. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  14002. }
  14003. json_object_put(CertificateSigned);
  14004. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  14005. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  14006. fclose(fp);
  14007. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14008. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  14009. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  14010. {
  14011. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  14012. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  14013. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  14014. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  14015. }
  14016. else
  14017. {
  14018. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  14019. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  14020. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14021. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14022. }
  14023. sendCertificateSignedConfirmation(uuid);
  14024. return result;
  14025. }
  14026. int handleDeleteCertificateRequest(char *uuid, char *payload)
  14027. {
  14028. mtrace();
  14029. int result = PASS;
  14030. json_object *DeleteCertificate;
  14031. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  14032. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  14033. DeleteCertificate = json_tokener_parse(payload);
  14034. if(!is_error(DeleteCertificate))
  14035. {
  14036. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14037. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14038. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14039. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14040. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14041. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14042. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14043. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14044. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  14045. {
  14046. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  14047. }
  14048. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  14049. {
  14050. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  14051. }
  14052. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  14053. {
  14054. ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  14055. }
  14056. char temp[256] = {0};
  14057. char compareData[256] = {0};
  14058. int isMatch = TRUE;
  14059. // Check CentralSystemRootCertificate
  14060. if(access(ROOTCA_CS,F_OK) != -1)
  14061. {
  14062. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14063. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14064. for(int i = 0; compareData[i]; i++)
  14065. {
  14066. compareData[i] = tolower(compareData[i]);
  14067. }
  14068. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14069. isMatch = FALSE;
  14070. if(isMatch == TRUE)
  14071. {
  14072. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14073. for(int i = 0; compareData[i]; i++)
  14074. {
  14075. compareData[i] = tolower(compareData[i]);
  14076. }
  14077. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14078. isMatch = FALSE;
  14079. }
  14080. if(isMatch == TRUE)
  14081. {
  14082. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14083. for(int i = 0; compareData[i]; i++)
  14084. {
  14085. compareData[i] = tolower(compareData[i]);
  14086. }
  14087. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14088. isMatch = FALSE;
  14089. }
  14090. if(isMatch == TRUE)
  14091. {
  14092. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  14093. sprintf(temp, "rm -f %s", ROOTCA_CS);
  14094. system(temp);
  14095. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14096. goto End;
  14097. }
  14098. }
  14099. // Check ManufacturerRootCertificate
  14100. if(access(ROOTCA_MF,F_OK) != -1)
  14101. {
  14102. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  14103. isMatch = TRUE;
  14104. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  14105. for(int i = 0; compareData[i]; i++)
  14106. {
  14107. compareData[i] = tolower(compareData[i]);
  14108. }
  14109. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14110. isMatch = FALSE;
  14111. if(isMatch == TRUE)
  14112. {
  14113. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  14114. for(int i = 0; compareData[i]; i++)
  14115. {
  14116. compareData[i] = tolower(compareData[i]);
  14117. }
  14118. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14119. isMatch = FALSE;
  14120. }
  14121. if(isMatch == TRUE)
  14122. {
  14123. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  14124. for(int i = 0; compareData[i]; i++)
  14125. {
  14126. compareData[i] = tolower(compareData[i]);
  14127. }
  14128. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14129. isMatch = FALSE;
  14130. }
  14131. if(isMatch == TRUE)
  14132. {
  14133. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  14134. sprintf(temp, "rm -f %s", ROOTCA_MF);
  14135. system(temp);
  14136. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14137. goto End;
  14138. }
  14139. }
  14140. // Check certCP
  14141. if(access(CERTIFICATE_CP,F_OK) != -1)
  14142. {
  14143. DEBUG_INFO("Checking certCP...\n");
  14144. isMatch = TRUE;
  14145. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  14146. for(int i = 0; compareData[i]; i++)
  14147. {
  14148. compareData[i] = tolower(compareData[i]);
  14149. }
  14150. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14151. isMatch = FALSE;
  14152. if(isMatch == TRUE)
  14153. {
  14154. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  14155. for(int i = 0; compareData[i]; i++)
  14156. {
  14157. compareData[i] = tolower(compareData[i]);
  14158. }
  14159. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14160. isMatch = FALSE;
  14161. }
  14162. if(isMatch == TRUE)
  14163. {
  14164. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  14165. for(int i = 0; compareData[i]; i++)
  14166. {
  14167. compareData[i] = tolower(compareData[i]);
  14168. }
  14169. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14170. isMatch = FALSE;
  14171. }
  14172. if(isMatch == TRUE)
  14173. {
  14174. DEBUG_INFO("Deleting certCP...\n");
  14175. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14176. system(temp);
  14177. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14178. goto End;
  14179. }
  14180. }
  14181. }
  14182. End:
  14183. json_object_put(DeleteCertificate);
  14184. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14185. sendDeleteCertificateConfirmation(uuid);
  14186. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14187. return result;
  14188. }
  14189. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14190. {
  14191. mtrace();
  14192. int result = PASS;
  14193. json_object *ExtendedTriggerMessage;
  14194. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14195. ExtendedTriggerMessage = json_tokener_parse(payload);
  14196. if(!is_error(ExtendedTriggerMessage))
  14197. {
  14198. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14199. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14200. {
  14201. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14202. }
  14203. else
  14204. {
  14205. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14206. }
  14207. }
  14208. json_object_put(ExtendedTriggerMessage);
  14209. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14210. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14211. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14212. {
  14213. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14214. }
  14215. else
  14216. {
  14217. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14218. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14219. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14220. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14221. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14222. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14223. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14224. {
  14225. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14226. }
  14227. else
  14228. {
  14229. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14230. }
  14231. }
  14232. sendExtendedTriggerMessageConfirmation(uuid);
  14233. //==========================
  14234. // Trigger message
  14235. //==========================
  14236. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14237. {
  14238. //sendBootNotificationRequest();
  14239. server_sign = FALSE;
  14240. }
  14241. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14242. {
  14243. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14244. }
  14245. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14246. {
  14247. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14248. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14249. {
  14250. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14251. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14252. }
  14253. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14254. }
  14255. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14256. {
  14257. refreshStartTimer(&clientTime.Heartbeat);
  14258. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14259. }
  14260. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14261. {
  14262. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14263. {
  14264. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14265. }
  14266. else
  14267. {
  14268. for(int idx=0;idx< gunTotalNumber;idx++)
  14269. {
  14270. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14271. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14272. }
  14273. }
  14274. }
  14275. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14276. {
  14277. char cmdBuf[1024]={0};
  14278. 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);
  14279. system(cmdBuf);
  14280. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14281. }
  14282. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14283. {
  14284. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14285. {
  14286. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14287. }
  14288. else
  14289. {
  14290. for(int idx=0;idx< gunTotalNumber;idx++)
  14291. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14292. }
  14293. }
  14294. return result;
  14295. }
  14296. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14297. {
  14298. mtrace();
  14299. int result = PASS;
  14300. json_object *GetInstalledCertificateIds;
  14301. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14302. GetInstalledCertificateIds = json_tokener_parse(payload);
  14303. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14304. if(!is_error(GetInstalledCertificateIds))
  14305. {
  14306. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14307. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14308. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14309. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  14310. // Check CentralSystemRootCertificate
  14311. if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL)
  14312. {
  14313. if(access(ROOTCA_CS,F_OK) != -1)
  14314. {
  14315. char parseData[512] = {0};
  14316. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14317. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14318. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  14319. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14320. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14321. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14322. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14323. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14324. }
  14325. else
  14326. {
  14327. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  14328. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14329. }
  14330. }
  14331. // Check ManufacturerRootCertificate
  14332. else if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL)
  14333. {
  14334. if(access(ROOTCA_MF,F_OK) != -1)
  14335. {
  14336. char parseData[512] = {0};
  14337. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14338. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14339. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  14340. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14341. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14342. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14343. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14344. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14345. }
  14346. else
  14347. {
  14348. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  14349. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14350. }
  14351. }
  14352. else
  14353. {
  14354. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14355. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14356. }
  14357. }
  14358. json_object_put(GetInstalledCertificateIds);
  14359. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14360. sendGetInstalledCertificateIdsConfirmation(uuid);
  14361. return result;
  14362. }
  14363. void* GetLogProcess(void* data)
  14364. {
  14365. pthread_detach(pthread_self());
  14366. mtrace();
  14367. 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};
  14368. int port=0;
  14369. int isSuccess = FALSE;
  14370. char cmdBuf[2048];
  14371. struct tm *tmNow;
  14372. time_t CurrentTime;
  14373. struct tm tmStart;
  14374. struct tm tmStop;
  14375. CurrentTime = time(NULL);
  14376. tmNow=localtime(&CurrentTime);
  14377. uint16_t targetYear, targetMonth;
  14378. json_object *GetLog;
  14379. DEBUG_INFO("GetLogProcess...\n");
  14380. GetLog = json_tokener_parse(data);
  14381. if(!is_error(GetLog))
  14382. {
  14383. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14384. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14385. if(json_object_object_get(GetLog, "retries") != NULL)
  14386. {
  14387. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14388. }
  14389. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14390. {
  14391. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14392. }
  14393. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14394. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14395. {
  14396. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14397. }
  14398. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14399. {
  14400. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14401. }
  14402. }
  14403. json_object_put(GetLog);
  14404. // Pack log to compress file
  14405. 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) &&
  14406. (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))
  14407. {
  14408. // Pack system log
  14409. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14410. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14411. targetYear = tmStart.tm_year;
  14412. targetMonth = tmStart.tm_mon;
  14413. do
  14414. {
  14415. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14416. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14417. if(targetMonth+1>=13)
  14418. {
  14419. targetYear += 1;
  14420. targetMonth = 1;
  14421. }
  14422. else
  14423. {
  14424. targetMonth += 1;
  14425. }
  14426. }while((targetYear < (tmNow->tm_year+1900)) ||
  14427. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14428. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14429. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14430. sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
  14431. system(cmdBuf);
  14432. // Pack charging & event log
  14433. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14434. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14435. targetYear = tmStart.tm_year;
  14436. targetMonth = tmStart.tm_mon;
  14437. do
  14438. {
  14439. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14440. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14441. if(targetMonth+1>=13)
  14442. {
  14443. targetYear += 1;
  14444. targetMonth = 1;
  14445. }
  14446. else
  14447. {
  14448. targetMonth += 1;
  14449. }
  14450. }while((targetYear < (tmNow->tm_year+1900)) ||
  14451. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14452. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14453. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14454. system(cmdBuf);
  14455. // Combine log file
  14456. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14457. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14458. }
  14459. else
  14460. {
  14461. system("exec /root/logPackTools 'log' 6");
  14462. }
  14463. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14464. system(cmdBuf);
  14465. checkUploadLog();
  14466. //****************location*******************/
  14467. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14468. {
  14469. DEBUG_INFO("location is <Empty>!\n");
  14470. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14471. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14472. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14473. goto end;
  14474. }
  14475. memset(protocol, 0, ARRAY_SIZE(protocol));
  14476. memset(user, 0, ARRAY_SIZE(user) );
  14477. memset(password, 0, ARRAY_SIZE(password));
  14478. memset(host, 0, ARRAY_SIZE(host));
  14479. memset(path, 0, ARRAY_SIZE(path));
  14480. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14481. memset(host1, 0, ARRAY_SIZE(host1));
  14482. memset(path1, 0, ARRAY_SIZE(path1));
  14483. /*location: ftp://user:password@host:port/path*/
  14484. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14485. if((access(fnamePlusPath,F_OK))!=-1)
  14486. {
  14487. DEBUG_INFO("fnamePlusPath exist.\n");
  14488. }
  14489. else
  14490. {
  14491. DEBUG_INFO("fnamePlusPath not exist!\n");
  14492. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14493. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14494. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14495. goto end;
  14496. }
  14497. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14498. {
  14499. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14500. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14501. protocol, host, &port, path);
  14502. strcpy(user,"anonymous");
  14503. strcpy(password,"");
  14504. }
  14505. else
  14506. {
  14507. //DEBUG_INFO("pch=%s\n", pch);
  14508. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14509. protocol, user, password, host, &port, path);
  14510. }
  14511. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14512. {
  14513. DEBUG_INFO("protocol is not ftp/http ! \n");
  14514. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14515. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14516. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14517. goto end;
  14518. }
  14519. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14520. {
  14521. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14522. sprintf(ftppath,"/%s", path);
  14523. do
  14524. {
  14525. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14526. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14527. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14528. sleep(3);
  14529. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14530. if(!isSuccess)
  14531. {
  14532. DEBUG_INFO("Diagnostics fail.\n");
  14533. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14534. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14535. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14536. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14537. }
  14538. else
  14539. {
  14540. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14541. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14542. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14543. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14544. }
  14545. ShmOCPP16Data->GetLog.retries--;
  14546. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14547. }
  14548. else
  14549. {
  14550. sscanf(host,"%[^/]%s",host1, path1);
  14551. if(strlen(path) > 0)
  14552. sprintf(ftppath,"/%s", path);
  14553. else
  14554. sprintf(ftppath,"/%s", path1);
  14555. int ftppathlen=strlen(ftppath);
  14556. int i=1;
  14557. char filenametemp[50];
  14558. while(i < ftppathlen)
  14559. {
  14560. int len=ftppathlen-i;
  14561. if(ftppath[len]== 47) // '/' ascll code: 47
  14562. {
  14563. DEBUG_INFO("find '/' all right\n");
  14564. break;
  14565. }
  14566. i=i+1;
  14567. }
  14568. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14569. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14570. filenametemp[i+1] = 0;
  14571. if(port == 0)
  14572. port = 21;
  14573. do
  14574. {
  14575. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14576. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14577. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14578. sleep(3);
  14579. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14580. if(!isSuccess)
  14581. {
  14582. DEBUG_INFO("Diagnostics fail.\n");
  14583. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14584. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14585. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14586. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14587. }
  14588. else
  14589. {
  14590. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14591. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14592. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14593. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14594. }
  14595. ShmOCPP16Data->GetLog.retries--;
  14596. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14597. }
  14598. end:
  14599. system("rm -f /mnt/*");
  14600. system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
  14601. sleep(5);
  14602. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14603. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14604. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14605. interLock.isGetDiagnosticGoing = 0;
  14606. pthread_exit(NULL);
  14607. }
  14608. int handleGetLogRequest(char *uuid, char *payload)
  14609. {
  14610. mtrace();
  14611. int result = PASS;
  14612. time_t CurrentTime;
  14613. struct tm *tm;
  14614. DEBUG_INFO("handleGetLogRequest...\n");
  14615. pthread_t th_Status;
  14616. CurrentTime = time(NULL);
  14617. tm = localtime(&CurrentTime);
  14618. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14619. 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);
  14620. if(!interLock.isGetDiagnosticGoing)
  14621. {
  14622. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14623. interLock.isGetDiagnosticGoing = 1;
  14624. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14625. sleep(1);
  14626. }
  14627. else
  14628. {
  14629. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14630. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14631. }
  14632. sendGetLogConfirmation(uuid);
  14633. return result;
  14634. }
  14635. int handleInstallCertificateRequest(char *uuid, char *payload)
  14636. {
  14637. mtrace();
  14638. int result = PASS;
  14639. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14640. json_object *InstallCertificate;
  14641. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14642. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14643. InstallCertificate = json_tokener_parse(payload);
  14644. if(!is_error(InstallCertificate))
  14645. {
  14646. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14647. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14648. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14649. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14650. char temp[1024];
  14651. FILE *fp = fopen(tempCert, "w");
  14652. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14653. fclose(fp);
  14654. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14655. char strExpDate[30];
  14656. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14657. fp = popen(temp, "r");
  14658. if(fp)
  14659. {
  14660. while(fgets(temp, sizeof(temp), fp) != NULL)
  14661. {
  14662. if(strstr(temp, "notAfter=") != NULL)
  14663. {
  14664. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14665. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14666. break;
  14667. }
  14668. }
  14669. }
  14670. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14671. struct tm tmExpDate;
  14672. struct timeb tbExpDate;
  14673. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14674. tbExpDate.time = mktime(&tmExpDate);
  14675. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14676. {
  14677. DEBUG_INFO("The enddate is already expired...\n");
  14678. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14679. goto End;
  14680. }
  14681. // Verify certificate with rootCA
  14682. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14683. fp = popen(temp, "r");
  14684. if(fp)
  14685. {
  14686. while(fgets(temp, sizeof(temp), fp) != NULL)
  14687. {
  14688. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14689. {
  14690. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14691. break;
  14692. }
  14693. else
  14694. {
  14695. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14696. }
  14697. }
  14698. }
  14699. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14700. {
  14701. //=====================================================
  14702. // Verify if the certificate is valid or not. (OCSP?)
  14703. //=====================================================
  14704. /*
  14705. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14706. // Get ocsp url
  14707. char ocspUrl[512];
  14708. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14709. fp = popen(temp, "r");
  14710. if(fp)
  14711. {
  14712. while(fgets(temp, sizeof(temp), fp) != NULL)
  14713. {
  14714. if(strstr(temp, "://") != NULL)
  14715. {
  14716. strcpy(ocspUrl, temp);
  14717. break;
  14718. }
  14719. }
  14720. }
  14721. // Get certificate chain for issuer
  14722. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14723. *
  14724. // Execute OCSP
  14725. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14726. fp = popen(temp, "r");
  14727. if(fp)
  14728. {
  14729. while(fgets(temp, sizeof(temp), fp) != NULL)
  14730. {
  14731. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14732. {
  14733. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14734. break;
  14735. }
  14736. }
  14737. }
  14738. system("rm -f /Storage/OCPP/tempChain.pem");
  14739. pclose(fp);
  14740. */
  14741. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14742. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14743. {
  14744. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14745. goto End;
  14746. }
  14747. else
  14748. DEBUG_INFO("OCSP verifying...PASS.\n");
  14749. }
  14750. else
  14751. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14752. }
  14753. End:
  14754. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14755. {
  14756. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14757. {
  14758. if(access(ROOTCA_CS,F_OK) != -1)
  14759. {
  14760. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14761. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14762. rename(tempCert, ROOTCA_CS);
  14763. }
  14764. else
  14765. {
  14766. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14767. rename(tempCert, ROOTCA_CS);
  14768. }
  14769. }
  14770. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14771. {
  14772. if(access(ROOTCA_MF,F_OK) != -1)
  14773. {
  14774. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14775. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14776. rename(tempCert, ROOTCA_MF);
  14777. }
  14778. else
  14779. {
  14780. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14781. rename(tempCert, ROOTCA_MF);
  14782. }
  14783. }
  14784. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14785. }
  14786. sendInstallCertificateConfirmation(uuid);
  14787. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14788. {
  14789. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14790. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14791. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14792. }
  14793. json_object_put(InstallCertificate);
  14794. return result;
  14795. }
  14796. void *SignedUpdateFirmwareProcess(void *data)
  14797. {
  14798. pthread_detach(pthread_self());
  14799. mtrace();
  14800. char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
  14801. int port=0;
  14802. int isSuccess = 0;
  14803. char ftpbuf[2048];
  14804. char temp[2048];
  14805. char * pch;
  14806. char firmwareFileName[256];
  14807. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14808. json_object *SignedUpdateFirmware;
  14809. SignedUpdateFirmware = json_tokener_parse(data);
  14810. if(!is_error(SignedUpdateFirmware))
  14811. {
  14812. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14813. {
  14814. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14815. }
  14816. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14817. {
  14818. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14819. }
  14820. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14821. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14822. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14823. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14824. {
  14825. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14826. }
  14827. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14828. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14829. }
  14830. json_object_put(SignedUpdateFirmware);
  14831. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14832. memset(path, 0, ARRAY_SIZE(path));
  14833. // Wait retrieveData
  14834. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14835. {
  14836. do
  14837. {
  14838. sleep(1);
  14839. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14840. }
  14841. // Ready to download
  14842. system("rm -f /mnt/*");
  14843. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14844. {
  14845. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14846. sprintf(ftppath,"/%s", path);
  14847. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14848. DEBUG_INFO("protocol: %s\n",protocol);
  14849. DEBUG_INFO("host: %s\n",host);
  14850. DEBUG_INFO("path: %s\n",path);
  14851. DEBUG_INFO("ftppath: %s\n",ftppath);
  14852. int ftppathlen=strlen(ftppath);
  14853. int i=1;
  14854. while(i < ftppathlen)
  14855. {
  14856. int len=ftppathlen-i;
  14857. if(ftppath[len]== 47) // '/' ascll code: 47
  14858. {
  14859. DEBUG_INFO("compare '/' all right\n");
  14860. break;
  14861. }
  14862. i=i+1;
  14863. }
  14864. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14865. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14866. firmwareFileName[i+1] = 0;
  14867. do
  14868. {
  14869. sleep(1);
  14870. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14871. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14872. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14873. sleep(1);
  14874. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14875. if(!isSuccess)
  14876. {
  14877. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14878. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14879. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14880. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14881. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14882. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14883. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14884. }
  14885. else
  14886. {
  14887. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14888. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14889. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14890. }
  14891. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14892. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14893. }
  14894. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14895. {
  14896. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14897. memset(temp, 0, ARRAY_SIZE(temp));
  14898. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14899. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14900. int ftppathlen=strlen(ftpbuf);
  14901. int i=1;
  14902. while(i < ftppathlen)
  14903. {
  14904. int len=ftppathlen-i;
  14905. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14906. {
  14907. DEBUG_INFO(" compare '/' all right\n");
  14908. break;
  14909. }
  14910. i=i+1;
  14911. }
  14912. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14913. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14914. firmwareFileName[i+1] = 0;
  14915. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14916. pch=strchr(temp,'@');
  14917. if(pch==NULL)
  14918. {
  14919. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14920. protocol, host, &port, path);
  14921. strcpy(user,"anonymous");
  14922. strcpy(password,"");
  14923. }
  14924. else
  14925. {
  14926. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14927. protocol, user, host, &port, path);
  14928. }
  14929. sscanf(host,"%[^/]%s",host1, path1);
  14930. sprintf(ftppath,"%s:/%s", host,path);
  14931. if(port == 0)
  14932. {
  14933. port = 21;
  14934. }
  14935. do
  14936. {
  14937. sleep(1);
  14938. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14939. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14940. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14941. sleep(1);
  14942. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14943. if(!isSuccess)
  14944. {
  14945. sleep(1);
  14946. DEBUG_INFO("Update firmware request and download file fail.\n");
  14947. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14948. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14949. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14950. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14951. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14952. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14953. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14954. }
  14955. else
  14956. {
  14957. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14958. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14959. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14960. }
  14961. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14962. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14963. }
  14964. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14965. {
  14966. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14967. memset(temp, 0, ARRAY_SIZE(temp));
  14968. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14969. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14970. int ftppathlen=strlen(ftpbuf);
  14971. int i=1;
  14972. while(i < ftppathlen)
  14973. {
  14974. int len=ftppathlen-i;
  14975. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14976. {
  14977. DEBUG_INFO(" compare '/' all right\n");
  14978. break;
  14979. }
  14980. i=i+1;
  14981. }
  14982. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14983. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14984. firmwareFileName[i+1] = 0;
  14985. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14986. pch=strchr(temp,'@');
  14987. if(pch==NULL)
  14988. {
  14989. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14990. protocol, host, &port, path);
  14991. strcpy(user,"anonymous");
  14992. strcpy(password,"");
  14993. }
  14994. else
  14995. {
  14996. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14997. protocol, user, password, host, &port, path);
  14998. }
  14999. sscanf(host,"%[^/]%s",host1, path1);
  15000. sprintf(ftppath,"%s", path1);
  15001. //DEBUG_INFO("protocol =%s\n",protocol);
  15002. //DEBUG_INFO("user =%s\n",user);
  15003. //DEBUG_INFO("password =%s\n",password);
  15004. //DEBUG_INFO("host1 =%s\n",host1);
  15005. //DEBUG_INFO("port =%d\n",port);
  15006. //DEBUG_INFO("path1 =%s\n",path1);
  15007. //DEBUG_INFO("ftppath=%s\n",ftppath);
  15008. //ftpFile(host, user, password, port, ftppath, fname);
  15009. //download firmware pthred
  15010. if(port == 0)
  15011. {
  15012. port = 21;
  15013. }
  15014. do
  15015. {
  15016. sleep(1);
  15017. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15018. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15019. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15020. sleep(1);
  15021. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15022. if(!isSuccess)
  15023. {
  15024. //BulldogUtil.sleepMs(interval*1000);
  15025. DEBUG_INFO("Update firmware request and download file fail.\n");
  15026. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15027. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15028. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15029. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15030. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15031. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15032. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15033. }
  15034. else
  15035. {
  15036. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15037. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15038. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15039. }
  15040. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15041. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15042. }
  15043. else
  15044. {
  15045. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15046. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15047. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15048. sleep(1);
  15049. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15050. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15051. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15052. }
  15053. // Verify firmware image signature
  15054. struct stat st;
  15055. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15056. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15057. fclose(fp);
  15058. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15059. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15060. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15061. fclose(fp);
  15062. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15063. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15064. if(st.st_size == 0)
  15065. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15066. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15067. {
  15068. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15069. fp = popen(temp, "r");
  15070. if(fp)
  15071. {
  15072. while(fgets(temp, sizeof(temp), fp) != NULL)
  15073. {
  15074. if(strstr(temp, "Verified OK") != NULL)
  15075. {
  15076. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15077. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15078. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15079. }
  15080. else
  15081. {
  15082. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15083. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15084. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15085. sleep(1);
  15086. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15087. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15088. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15089. sleep(1);
  15090. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15091. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15092. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15093. }
  15094. break;
  15095. }
  15096. }
  15097. pclose(fp);
  15098. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15099. }
  15100. interLock.isUpdateFirmwareGoing = 0;
  15101. pthread_exit(NULL);
  15102. }
  15103. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15104. {
  15105. mtrace();
  15106. int result = PASS;
  15107. pthread_t t;
  15108. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15109. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15110. sendSignedUpdateFirmwareConfirmation(uuid);
  15111. if(!interLock.isUpdateFirmwareGoing)
  15112. {
  15113. interLock.isUpdateFirmwareGoing = 1;
  15114. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15115. sleep(1);
  15116. }
  15117. else
  15118. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15119. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15120. return result;
  15121. }
  15122. int handleUnknownRequest(char *uuid, char *payload)
  15123. {
  15124. mtrace();
  15125. int result = PASS;
  15126. DEBUG_INFO("handleUnknownRequest...\n");
  15127. sendUnknownConfirmation(uuid);
  15128. return result;
  15129. }
  15130. //==========================================
  15131. // Handle server response routine
  15132. //==========================================
  15133. void handleAuthorizeResponse(char *payload, int gun_index)
  15134. {
  15135. mtrace();
  15136. char expiryDatestr[36]={0};
  15137. char parentIdTagstr[21]={0};
  15138. char statusstr[20]={0};
  15139. int expiryDateISNULL=FALSE;
  15140. int parentIdTagISNULL=FALSE;
  15141. DEBUG_INFO("handleAuthorizeResponse...\n");
  15142. json_object *Authorize;
  15143. Authorize = json_tokener_parse(payload);
  15144. if(!is_error(Authorize))
  15145. {
  15146. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15147. {
  15148. // Required data
  15149. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15150. // Optional data
  15151. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15152. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15153. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15154. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15155. }
  15156. }
  15157. json_object_put(Authorize);
  15158. if(expiryDateISNULL == FALSE)
  15159. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15160. if(parentIdTagISNULL == FALSE)
  15161. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15162. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15163. //Update idTag information to authorization cache if supproted
  15164. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15165. {
  15166. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15167. }
  15168. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15169. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15170. authorizeRetryTimes = 0;
  15171. }
  15172. void handleBootNotificationResponse(char *payload, int gun_index)
  15173. {
  15174. mtrace();
  15175. char statusStr[12]={0};
  15176. char currentTimeStr[30]={0};
  15177. int intervalInt = 0;
  15178. DEBUG_INFO("handleBootNotificationResponse...\n");
  15179. json_object *BootNotification;
  15180. BootNotification = json_tokener_parse(payload);
  15181. if(!is_error(BootNotification))
  15182. {
  15183. // Required data
  15184. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15185. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15186. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15187. }
  15188. json_object_put(BootNotification);
  15189. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15190. BootNotificationInterval = intervalInt;
  15191. //write back to ShmOCPP16Data->BootNotification
  15192. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15193. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15194. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15195. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15196. {
  15197. BootNotificationInterval = 0;
  15198. if((intervalInt == 0) || (intervalInt >= 10))
  15199. {
  15200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15201. HeartBeatWaitTime = intervalInt;
  15202. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15203. }
  15204. server_sign = TRUE;
  15205. server_pending =FALSE;
  15206. }
  15207. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15208. {
  15209. server_pending = TRUE;
  15210. }
  15211. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15212. srand(time(NULL));
  15213. refreshStartTimer(&clientTime.Heartbeat);
  15214. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15215. SetOcppConnStatus(TRUE);
  15216. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15217. }
  15218. void handleDataTransferResponse(char *payload, int gun_index)
  15219. {
  15220. json_object *DataTransfer = json_tokener_parse(payload);
  15221. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15222. if(!is_error(DataTransfer))
  15223. {
  15224. // Required data
  15225. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15226. // Optional data
  15227. if(json_object_object_get(DataTransfer, "data") != NULL)
  15228. {
  15229. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15230. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15231. if(!is_error(Data))
  15232. {
  15233. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15234. {
  15235. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15236. {
  15237. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15238. }
  15239. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15240. {
  15241. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15242. {
  15243. 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")));
  15244. }
  15245. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15246. {
  15247. 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")));
  15248. }
  15249. }
  15250. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15251. }
  15252. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15253. {
  15254. if(json_object_object_get(Data, "status") != NULL)
  15255. {
  15256. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15257. }
  15258. if(json_object_object_get(Data, "exiResponse") != NULL)
  15259. {
  15260. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15261. }
  15262. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15263. }
  15264. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15265. {
  15266. if(json_object_object_get(Data, "status") != NULL)
  15267. {
  15268. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15269. }
  15270. if(json_object_object_get(Data, "ocspResult") != NULL)
  15271. {
  15272. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15273. }
  15274. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15275. }
  15276. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15277. {
  15278. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15279. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15280. }
  15281. else
  15282. {
  15283. if(json_object_object_get(Data, "msgId") != NULL)
  15284. {
  15285. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15286. {
  15287. 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")));
  15288. }
  15289. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15290. {
  15291. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15292. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15293. }
  15294. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyFeeAct") != NULL)
  15295. {
  15296. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15297. {
  15298. 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")));
  15299. if(json_object_object_get(Data, "occupancySN") != NULL)
  15300. 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")));
  15301. if(json_object_object_get(Data, "startTime") != NULL)
  15302. 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")));
  15303. if(json_object_object_get(Data, "duration") != NULL)
  15304. 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"));
  15305. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15306. 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"));
  15307. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].OccupancyFeeActReq = 0;
  15308. }
  15309. else
  15310. {
  15311. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15312. {
  15313. if(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq)
  15314. {
  15315. strcpy((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].response_status, "Rejected");
  15316. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq = 0;
  15317. }
  15318. }
  15319. }
  15320. }
  15321. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15322. {
  15323. if(json_object_object_get(Data, "occupancySN") != NULL)
  15324. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15325. }
  15326. }
  15327. }
  15328. }
  15329. json_object_put(Data);
  15330. }
  15331. }
  15332. json_object_put(DataTransfer);
  15333. }
  15334. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15335. {
  15336. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15337. //struct json_object *obj;
  15338. // obj = json_tokener_parse(payload);
  15339. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15340. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15341. //No fields are defined.
  15342. }
  15343. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15344. {
  15345. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15346. //struct json_object *obj;
  15347. // obj = json_tokener_parse(payload);
  15348. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15349. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15350. //No fields are defined.
  15351. }
  15352. void handleHeartbeatResponse(char *payload, int gun_index)
  15353. {
  15354. mtrace();
  15355. DEBUG_INFO("handleHeartbeatResponse...\n");
  15356. json_object *Heartbeat;
  15357. Heartbeat = json_tokener_parse(payload);
  15358. if(!is_error(Heartbeat))
  15359. {
  15360. // Required data
  15361. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15362. }
  15363. json_object_put(Heartbeat);
  15364. if(FirstHeartBeat == 0)
  15365. {
  15366. FirstHeartBeat = 1;
  15367. DEBUG_INFO("FirstHeartBeat \n");
  15368. }
  15369. HeartBeatWithNOResponse = 0;
  15370. refreshStartTimer(&clientTime.Heartbeat);
  15371. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15372. }
  15373. void handleMeterValuesResponse(char *payload, int gun_index)
  15374. {
  15375. mtrace();
  15376. DEBUG_INFO("handleMeterValuesResponse...\n");
  15377. isQueueSendable = 1;
  15378. }
  15379. void handleStartTransactionResponse(char *payload, int gun_index)
  15380. {
  15381. mtrace();
  15382. //int transactionIdInt = 0;
  15383. FILE *outfile;
  15384. char data[100]={0};
  15385. DEBUG_INFO("handleStartTransactionResponse...\n");
  15386. json_object *StartTransaction;
  15387. StartTransaction = json_tokener_parse(payload);
  15388. if(!is_error(StartTransaction))
  15389. {
  15390. // Required data
  15391. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15392. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15393. // Optional data
  15394. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15395. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15396. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15397. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15398. }
  15399. json_object_put(StartTransaction);
  15400. OCPP_updatePeriodEnergy(gun_index);
  15401. //-----------Start : write to the Queue TransactionId file -----------------//
  15402. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15403. {}
  15404. else
  15405. {
  15406. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15407. if(log == NULL)
  15408. {
  15409. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15410. return ;
  15411. }
  15412. else
  15413. {
  15414. fclose(log);
  15415. }
  15416. }
  15417. // open file for writing
  15418. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15419. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15420. {
  15421. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15422. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15423. fputs(data, outfile);
  15424. fclose (outfile);
  15425. DEBUG_INFO("Update QueueTransactionId done...\n");
  15426. }
  15427. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15428. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15429. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15430. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15431. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15432. isQueueSendable = 1;
  15433. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15434. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15435. }
  15436. void handleStatusNotificationResponse(char *payload, int gun_index)
  15437. {
  15438. mtrace();
  15439. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15440. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15441. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15442. if(gun_index != 99)
  15443. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15444. }
  15445. void handleStopTransactionnResponse(char *payload, int gun_index)
  15446. {
  15447. mtrace();
  15448. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15449. json_object *StopTransaction;
  15450. StopTransaction = json_tokener_parse(payload);
  15451. if(!is_error(StopTransaction))
  15452. {
  15453. // Optional data
  15454. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15455. {
  15456. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15457. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15458. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15459. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15460. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15461. }
  15462. }
  15463. json_object_put(StopTransaction);
  15464. isQueueSendable = 1;
  15465. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15466. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15467. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15468. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15469. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15470. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15471. }
  15472. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15473. {
  15474. mtrace();
  15475. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15476. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15477. }
  15478. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15479. {
  15480. mtrace();
  15481. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15482. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15483. }
  15484. void handleSignCertificateResponse(char *payload, int gun_index)
  15485. {
  15486. mtrace();
  15487. DEBUG_INFO("handleSignCertificateResponse...\n");
  15488. json_object *SignCertificate;
  15489. SignCertificate = json_tokener_parse(payload);
  15490. if(!is_error(SignCertificate))
  15491. {
  15492. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15493. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15494. }
  15495. json_object_put(SignCertificate);
  15496. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15497. }
  15498. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15499. {
  15500. mtrace();
  15501. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15502. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15503. }
  15504. //==========================================
  15505. // Handle Error routine
  15506. //==========================================
  15507. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15508. {
  15509. mtrace();
  15510. #ifdef SystemLogMessage
  15511. DEBUG_INFO("errorCode: %s\n", errorCode);
  15512. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15513. DEBUG_INFO("errorDetails: %s\n", payload);
  15514. #endif
  15515. }
  15516. //===============================================
  15517. // Common routine
  15518. //===============================================
  15519. int initialConfigurationTable(void)
  15520. {
  15521. //clock_t start_t, end_t, total_t;
  15522. FILE *fp;
  15523. FILE *outfile;
  15524. char str[512]={0};
  15525. int confVersion = 27;
  15526. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15527. //start_t = clock();
  15528. //printf("Starting of the program, start_t = %ld\n", start_t);
  15529. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15530. // Check configuration file size is correct
  15531. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15532. {
  15533. struct stat st;
  15534. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15535. if(st.st_size < 3100)
  15536. {
  15537. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15538. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15539. }
  15540. }
  15541. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15542. {
  15543. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15544. if(outfile == NULL)
  15545. {
  15546. DEBUG_INFO("Error opening file\n");
  15547. return FALSE;
  15548. }
  15549. /*Core Profile*/
  15550. //AllowOfflineTxForUnknownId
  15551. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15555. //AuthorizationCacheEnabled
  15556. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15560. //AuthorizeRemoteTxRequests
  15561. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15565. //BlinkRepeat
  15566. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15570. //ClockAlignedDataInterval
  15571. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15575. //ConnectionTimeOut
  15576. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15578. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15580. else
  15581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15582. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15583. //GetConfigurationMaxKeys
  15584. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15588. // HeartbeatInterval
  15589. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15593. // LightIntensity
  15594. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15598. // LocalAuthorizeOffline
  15599. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15603. // LocalPreAuthorize
  15604. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15608. // MaxEnergyOnInvalidId
  15609. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15613. // MeterValuesAlignedData
  15614. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15616. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15617. 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" );
  15618. else
  15619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15621. // MeterValuesAlignedDataMaxLength
  15622. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15624. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15626. else
  15627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15629. // MeterValuesSampledData
  15630. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15632. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15633. 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" );
  15634. else
  15635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15637. // MeterValuesSampledDataMaxLength
  15638. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15640. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15642. else
  15643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15645. // MeterValueSampleInterval
  15646. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15650. // MinimumStatusDuration
  15651. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15654. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15656. // NumberOfConnectors
  15657. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15660. {
  15661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15662. }
  15663. else
  15664. {
  15665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15666. }
  15667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15668. // ResetRetries
  15669. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15673. // ConnectorPhaseRotation
  15674. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15678. // ConnectorPhaseRotationMaxLength
  15679. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15683. // StopTransactionOnEVSideDisconnect
  15684. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15688. // StopTransactionOnInvalidId
  15689. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15693. // StopTxnAlignedData
  15694. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15698. // StopTxnAlignedDataMaxLength
  15699. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15701. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15702. {
  15703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 8);
  15704. }
  15705. else
  15706. {
  15707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 10);
  15708. }
  15709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15710. // StopTxnSampledData
  15711. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "" );
  15714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15715. // StopTxnSampledDataMaxLength
  15716. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15719. {
  15720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 8);
  15721. }
  15722. else
  15723. {
  15724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 10);
  15725. }
  15726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15727. // SupportedFeatureProfiles
  15728. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15732. // SupportedFeatureProfilesMaxLength
  15733. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15737. // TransactionMessageAttempts
  15738. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15741. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15743. // TransactionMessageRetryInterval
  15744. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15747. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15749. // UnlockConnectorOnEVSideDisconnect
  15750. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15754. // WebSocketPingInterval
  15755. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15758. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15759. // QueueOffLineMeterValues
  15760. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15764. // AuthorizationKey
  15765. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15769. // SecurityProfile
  15770. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15774. // DefaultPrice
  15775. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15779. // CustomDisplayCostAndPrice
  15780. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15784. // CustomIdleFeeAfterStop
  15785. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15789. // TimeOffset
  15790. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15794. // NextTimeOffsetTransitionDateTime
  15795. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15799. // TimeOffsetNextTransition
  15800. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15804. // SystemUptimeSec
  15805. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15809. // FreeVend
  15810. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15814. // FreeVendIdtag
  15815. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15819. // OcppServer
  15820. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15822. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15824. // MaintainServer
  15825. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15827. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15829. // StatusNotificationPeriodically
  15830. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15834. // StatusNotificationInterval
  15835. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15839. // PreAuthAmount
  15840. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15844. // isEnableLocalPowerSharing
  15845. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15849. // PowerSharingServerIP
  15850. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15852. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15854. // EVCCID_PREFIX
  15855. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15859. // OffLineMaxChargingPower
  15860. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15864. // Configuration Version
  15865. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15869. // Charging profile refresh interval
  15870. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15874. // CpoName
  15875. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15879. // Ocpp Software certificated version
  15880. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15884. // Check certificate of download link
  15885. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  15886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  15887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "FALSE");
  15888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  15889. // RFID endian type
  15890. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = 1;
  15891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemName, "RfidEndianType");
  15892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE");
  15893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","RfidEndianType", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData);
  15894. // Authorization timeout
  15895. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = 1;
  15896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemName, "AuthorizeTimeout");
  15897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "15");
  15898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeTimeout", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  15899. // Enable AC charger CCS function
  15900. ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility = 1;
  15901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemName, "Enable15118");
  15902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemData, ShmSysConfigAndInfo->SysConfig.isEnable15118==1?"TRUE":"FALSE");
  15903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","Enable15118", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemData);
  15904. //* Local Auth List Management Profile*/
  15905. #if 0
  15906. //For OCTT Test Case
  15907. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15910. #endif
  15911. #if 1
  15912. //LocalAuthListEnabled
  15913. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15917. #endif
  15918. //LocalAuthListMaxLength
  15919. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15923. //SendLocalListMaxLength
  15924. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15928. //ReserveConnectorZeroSupported
  15929. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15933. //* Smart Charging Profile */
  15934. //ChargeProfileMaxStackLevel
  15935. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15939. // ChargingScheduleAllowedChargingRateUnit
  15940. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15944. // ChargingScheduleMaxPeriods
  15945. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15949. // ConnectorSwitch3to1PhaseSupported
  15950. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15954. // MaxChargingProfilesInstalled
  15955. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15959. fclose(outfile);
  15960. }
  15961. else
  15962. {
  15963. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15964. char keystr[60]={0};
  15965. char readonlystr[10]={0};
  15966. char valuestr[256]={0};
  15967. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15968. if(fp == NULL) {
  15969. DEBUG_INFO("Error opening file");
  15970. return FALSE;
  15971. }
  15972. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15973. {
  15974. //DEBUG_INFO("Get Configuration \n");
  15975. if(strlen(str) > 0)
  15976. {
  15977. json_object *OCPPConfiguration;
  15978. OCPPConfiguration = json_tokener_parse(str);
  15979. if(json_object_object_get(OCPPConfiguration, "key") != NULL)
  15980. strcpy(keystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"key")));
  15981. if(json_object_object_get(OCPPConfiguration, "readonly") != NULL)
  15982. strcpy(readonlystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"readonly")));
  15983. if(json_object_object_get(OCPPConfiguration, "value") != NULL)
  15984. strcpy(valuestr, json_object_get_string(json_object_object_get(OCPPConfiguration,"value")));
  15985. json_object_put(OCPPConfiguration);
  15986. // DEBUG_INFO("keystr=%s\n",keystr);
  15987. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  15988. // DEBUG_INFO("valuestr=%s\n",valuestr);
  15989. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  15990. {
  15991. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15992. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  15994. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15995. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15996. }
  15997. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  15998. {
  15999. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16000. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  16002. }
  16003. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  16004. {
  16005. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  16007. }
  16008. if(strcmp(keystr, "BlinkRepeat") == 0)
  16009. {
  16010. //Charger.BlinkRepeat = Integer.parseInt(value);
  16011. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  16013. }
  16014. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  16015. {
  16016. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  16018. }
  16019. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  16020. {
  16021. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  16023. }
  16024. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16025. {
  16026. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16028. }
  16029. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16030. {
  16031. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16033. HeartBeatWaitTime = atoi(valuestr);
  16034. }
  16035. if(strcmp(keystr, "LightIntensity") == 0)
  16036. {
  16037. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16039. }
  16040. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16041. {
  16042. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16044. }
  16045. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16046. {
  16047. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16049. }
  16050. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16051. {
  16052. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16054. }
  16055. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16056. {
  16057. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16059. }
  16060. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16061. {
  16062. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16064. }
  16065. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16066. {
  16067. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16069. }
  16070. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16071. {
  16072. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16074. }
  16075. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16076. {
  16077. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16079. }
  16080. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16081. {
  16082. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16084. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16085. }
  16086. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16087. {
  16088. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16090. }
  16091. if(strcmp(keystr, "ResetRetries") == 0)
  16092. {
  16093. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16095. }
  16096. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16097. {
  16098. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16100. }
  16101. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16102. {
  16103. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16105. }
  16106. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16107. {
  16108. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16110. }
  16111. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16112. {
  16113. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16115. }
  16116. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16117. {
  16118. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16120. }
  16121. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16122. {
  16123. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16125. }
  16126. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16127. {
  16128. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16130. }
  16131. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16132. {
  16133. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16135. }
  16136. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16137. {
  16138. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16140. }
  16141. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16142. {
  16143. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16145. }
  16146. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16147. {
  16148. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16150. TransactionMessageAttemptsValue = atoi(valuestr);
  16151. }
  16152. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16153. {
  16154. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16156. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16157. }
  16158. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16159. {
  16160. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16162. }
  16163. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16164. {
  16165. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16167. }
  16168. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16169. {
  16170. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16172. }
  16173. if(strcmp(keystr, "AuthorizationKey") == 0)
  16174. {
  16175. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16176. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16178. }
  16179. if(strcmp(keystr, "SecurityProfile") == 0)
  16180. {
  16181. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16183. }
  16184. if(strcmp(keystr, "DefaultPrice") == 0)
  16185. {
  16186. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16188. }
  16189. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16190. {
  16191. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16193. }
  16194. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16195. {
  16196. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16198. }
  16199. if(strcmp(keystr, "TimeOffset") == 0)
  16200. {
  16201. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16203. }
  16204. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16205. {
  16206. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16208. }
  16209. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16210. {
  16211. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16213. }
  16214. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16215. {
  16216. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16218. }
  16219. if(strcmp(keystr, "FreeVend") == 0)
  16220. {
  16221. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16223. }
  16224. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16225. {
  16226. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16228. }
  16229. if(strcmp(keystr, "OcppServer") == 0)
  16230. {
  16231. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16232. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16233. }
  16234. if(strcmp(keystr, "MaintainServer") == 0)
  16235. {
  16236. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16237. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16238. }
  16239. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16240. {
  16241. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16243. }
  16244. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16245. {
  16246. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16248. }
  16249. if(strcmp(keystr, "PreAuthAmount") == 0)
  16250. {
  16251. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16253. }
  16254. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16255. {
  16256. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16258. }
  16259. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16260. {
  16261. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16262. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16263. }
  16264. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16265. {
  16266. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16268. }
  16269. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16270. {
  16271. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16273. }
  16274. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16275. {
  16276. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16278. }
  16279. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16280. {
  16281. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16283. }
  16284. if(strcmp(keystr, "CpoName") == 0)
  16285. {
  16286. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16288. }
  16289. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16290. {
  16291. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16293. }
  16294. if(strcmp(keystr, "AuthDownloadlinkCertificate") == 0)
  16295. {
  16296. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", valuestr);
  16298. }
  16299. if(strcmp(keystr, "RfidEndianType") == 0)
  16300. {
  16301. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE");
  16303. }
  16304. if(strcmp(keystr, "AuthorizeTimeout") == 0)
  16305. {
  16306. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "%s", valuestr);
  16308. }
  16309. if(strcmp(keystr, "Enable15118") == 0)
  16310. {
  16311. ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemData, ShmSysConfigAndInfo->SysConfig.isEnable15118==1?"TRUE":"FALSE");
  16313. }
  16314. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16315. {
  16316. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16318. }
  16319. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16320. {
  16321. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16323. }
  16324. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16325. {
  16326. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16328. }
  16329. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16330. {
  16331. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16333. }
  16334. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16335. {
  16336. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16338. }
  16339. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16340. {
  16341. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16343. }
  16344. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16345. {
  16346. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16348. }
  16349. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16350. {
  16351. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16353. }
  16354. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16355. {
  16356. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16358. }
  16359. }
  16360. }
  16361. fclose(fp);
  16362. }
  16363. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16364. {
  16365. return PASS;
  16366. }
  16367. else
  16368. {
  16369. return FAIL;
  16370. }
  16371. }
  16372. void StoreConfigurationTable(void)
  16373. {
  16374. FILE *outfile;
  16375. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16376. if(outfile == NULL)
  16377. {
  16378. DEBUG_INFO("Error opening file");
  16379. return ;
  16380. }
  16381. /*Core Profile*/
  16382. //AllowOfflineTxForUnknownId
  16383. /*
  16384. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16385. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16388. */
  16389. //DEBUG_INFO("data=%s\n",data);
  16390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16391. //AuthorizationCacheEnabled
  16392. /*
  16393. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16396. */
  16397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16398. //AuthorizeRemoteTxRequests
  16399. /*
  16400. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16403. */
  16404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16405. //BlinkRepeat
  16406. /*
  16407. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16410. */
  16411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16412. //ClockAlignedDataInterval
  16413. /*
  16414. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16417. */
  16418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16419. //ConnectionTimeOut
  16420. /*
  16421. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16424. */
  16425. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16426. //GetConfigurationMaxKeys
  16427. /*
  16428. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16431. */
  16432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16433. // HeartbeatInterval
  16434. /*
  16435. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16438. */
  16439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16440. // LightIntensity
  16441. /*
  16442. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16445. */
  16446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16447. // LocalAuthorizeOffline
  16448. /*
  16449. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16452. */
  16453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16454. // LocalPreAuthorize
  16455. /*
  16456. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16459. */
  16460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16461. // MaxEnergyOnInvalidId
  16462. /*
  16463. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16466. */
  16467. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16469. // MeterValuesAlignedData
  16470. /*
  16471. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16474. */
  16475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16476. // MeterValuesAlignedDataMaxLength
  16477. /*
  16478. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16481. */
  16482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16483. // MeterValuesSampledData
  16484. /*
  16485. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16488. */
  16489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16490. // MeterValuesSampledDataMaxLength
  16491. /*
  16492. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16495. */
  16496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16497. // MeterValueSampleInterval
  16498. /*
  16499. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16502. */
  16503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16504. // MinimumStatusDuration
  16505. /*
  16506. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16508. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16509. */
  16510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16511. // NumberOfConnectors
  16512. /*
  16513. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16516. {
  16517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16518. }
  16519. else
  16520. {
  16521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16522. }
  16523. */
  16524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16525. // ResetRetries
  16526. /*
  16527. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16530. */
  16531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16532. // ConnectorPhaseRotation
  16533. /*
  16534. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16537. */
  16538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16539. // ConnectorPhaseRotationMaxLength
  16540. /*
  16541. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16544. */
  16545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16546. // StopTransactionOnEVSideDisconnect
  16547. /*
  16548. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16551. */
  16552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16553. // StopTransactionOnInvalidId
  16554. /*
  16555. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16558. */
  16559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16560. // StopTxnAlignedData
  16561. /*
  16562. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16565. */
  16566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16567. // StopTxnAlignedDataMaxLength
  16568. /*
  16569. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16572. */
  16573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16574. // StopTxnSampledData
  16575. /*
  16576. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16579. */
  16580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16581. // StopTxnSampledDataMaxLength
  16582. /*
  16583. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16586. */
  16587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16588. // SupportedFeatureProfiles
  16589. /*
  16590. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16593. */
  16594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16595. // SupportedFeatureProfilesMaxLength
  16596. /*
  16597. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16600. */
  16601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16602. // TransactionMessageAttempts
  16603. /*
  16604. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16607. */
  16608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16609. // TransactionMessageRetryInterval
  16610. /*
  16611. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16614. */
  16615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16616. // UnlockConnectorOnEVSideDisconnect
  16617. /*
  16618. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16621. */
  16622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16623. // WebSocketPingInterval
  16624. /*
  16625. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16628. */
  16629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16630. // QueueOffLineMeterValues
  16631. /*
  16632. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16635. */
  16636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16637. // AuthorizationKey
  16638. /*
  16639. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16642. */
  16643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16644. // SecurityProfile
  16645. /*
  16646. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16649. */
  16650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16651. // DefaultPrice
  16652. /*
  16653. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16656. */
  16657. json_object *tmp;
  16658. tmp = json_tokener_parse((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16659. if(!is_error(tmp))
  16660. {
  16661. DEBUG_INFO("JSON string type\n");
  16662. json_object *target = json_object_new_object();
  16663. json_object_object_add(target, "key", json_object_new_string("DefaultPrice"));
  16664. json_object_object_add(target, "readonly", (ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility?json_object_new_boolean(0):json_object_new_boolean(1)));
  16665. json_object_object_add(target, "value", json_object_new_string((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData));
  16666. fprintf(outfile, "%s\n", json_object_to_json_string_ext(target, JSON_C_TO_STRING_PLAIN));
  16667. json_object_put(target);
  16668. }
  16669. else
  16670. {
  16671. DEBUG_INFO("Normal string type\n");
  16672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16673. }
  16674. json_object_put(tmp);
  16675. // CustomDisplayCostAndPrice
  16676. /*
  16677. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16680. */
  16681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16682. // CustomIdleFeeAfterStop
  16683. /*
  16684. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16687. */
  16688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16689. // TimeOffset
  16690. /*
  16691. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16694. */
  16695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16696. // NextTimeOffsetTransitionDateTime
  16697. /*
  16698. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16701. */
  16702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16703. // TimeOffsetNextTransition
  16704. /*
  16705. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16708. */
  16709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16710. // SystemUptimeSec
  16711. /*
  16712. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16715. */
  16716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16717. // FreeVend
  16718. /*
  16719. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16722. */
  16723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16724. // FreeVendIdtag
  16725. /*
  16726. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16729. */
  16730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16731. // OcppServer
  16732. /*
  16733. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16736. */
  16737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16738. // MaintainServer
  16739. /*
  16740. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16743. */
  16744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16745. // StatusNotificationPeriodically
  16746. /*
  16747. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16750. */
  16751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16752. // StatusNotificationInterval
  16753. /*
  16754. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16757. */
  16758. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16759. // PreAuthAmount
  16760. /*
  16761. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16764. */
  16765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16766. // isEnableLocalPowerSharing
  16767. /*
  16768. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16771. */
  16772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16773. // PowerSharingServerIP
  16774. /*
  16775. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16778. */
  16779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16780. // EVCCID_PREFIX
  16781. /*
  16782. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16785. */
  16786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16787. // OffLineMaxChargingPower
  16788. /*
  16789. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16792. */
  16793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16794. // ConfigurationVersion
  16795. /*
  16796. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16799. */
  16800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16801. // CharingProfileRefreshInterval
  16802. /*
  16803. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16806. */
  16807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16808. // CpoName
  16809. /*
  16810. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16813. */
  16814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16815. // OcppSoftwareVersion
  16816. /*
  16817. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16820. */
  16821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16822. // AuthDownloadlinkCertificate
  16823. /*
  16824. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  16825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  16826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE" );
  16827. */
  16828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  16829. // RfidEndianType
  16830. /*
  16831. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = 1;
  16832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemName, "RfidEndianType");
  16833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "BIG" );
  16834. */
  16835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","RfidEndianType", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData);
  16836. // AuthorizeTimeout
  16837. /*
  16838. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = 1;
  16839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemName, "AuthorizeTimeout");
  16840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "60" );
  16841. */
  16842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeTimeout", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  16843. // Enable15118
  16844. /*
  16845. ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility = 1;
  16846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemName, "Enable15118");
  16847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemData, "TRUE" );
  16848. */
  16849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","Enable15118", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemData);
  16850. //* Local Auth List Management Profile*/
  16851. //LocalAuthListEnabled
  16852. /*
  16853. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16856. */
  16857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16858. //LocalAuthListMaxLength
  16859. /*
  16860. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16863. */
  16864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16865. //SendLocalListMaxLength
  16866. /*
  16867. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16870. */
  16871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16872. //ReserveConnectorZeroSupported
  16873. /*
  16874. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16877. */
  16878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16879. //* Smart Charging Profile */
  16880. //ChargeProfileMaxStackLevel
  16881. /*
  16882. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16885. */
  16886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16887. // ChargingScheduleAllowedChargingRateUnit
  16888. /*
  16889. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16892. */
  16893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16894. // ChargingScheduleMaxPeriods
  16895. /*
  16896. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16899. */
  16900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16901. // ConnectorSwitch3to1PhaseSupported
  16902. /*
  16903. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16906. */
  16907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16908. // MaxChargingProfilesInstalled
  16909. /*
  16910. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16913. */
  16914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16915. fclose(outfile);
  16916. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16917. }
  16918. void getKeyValue(char *keyReq)
  16919. {
  16920. int isEmpty = FALSE;
  16921. int isKnowKey = FALSE;
  16922. DEBUG_INFO("keyReq = %s\n", keyReq);
  16923. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16924. isEmpty = TRUE;
  16925. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16926. {
  16927. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16929. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16930. {
  16931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16932. }
  16933. else
  16934. {
  16935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16936. }
  16937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16938. isKnowKey = TRUE;
  16939. }
  16940. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16941. {
  16942. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16945. {
  16946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16947. }
  16948. else
  16949. {
  16950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16951. }
  16952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16953. isKnowKey = TRUE;
  16954. }
  16955. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16956. {
  16957. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16959. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16960. {
  16961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16962. }
  16963. else
  16964. {
  16965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16966. }
  16967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16968. isKnowKey = TRUE;
  16969. }
  16970. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16971. {
  16972. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16974. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16975. {
  16976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16977. }
  16978. else
  16979. {
  16980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16981. }
  16982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16983. isKnowKey = TRUE;
  16984. }
  16985. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16986. {
  16987. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16990. {
  16991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16992. }
  16993. else
  16994. {
  16995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16996. }
  16997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16998. isKnowKey = TRUE;
  16999. }
  17000. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  17001. {
  17002. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  17003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  17004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  17005. {
  17006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  17007. }
  17008. else
  17009. {
  17010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  17011. }
  17012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  17013. isKnowKey = TRUE;
  17014. }
  17015. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  17016. {
  17017. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  17018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  17019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  17020. {
  17021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  17022. }
  17023. else
  17024. {
  17025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  17026. }
  17027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  17028. isKnowKey = TRUE;
  17029. }
  17030. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  17031. {
  17032. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  17033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  17034. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17035. {
  17036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  17037. }
  17038. else
  17039. {
  17040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  17041. }
  17042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  17043. isKnowKey = TRUE;
  17044. }
  17045. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  17046. {
  17047. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  17048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  17049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17050. {
  17051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  17052. }
  17053. else
  17054. {
  17055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  17056. }
  17057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  17058. isKnowKey = TRUE;
  17059. }
  17060. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  17061. {
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  17063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  17064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17065. {
  17066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  17067. }
  17068. else
  17069. {
  17070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  17071. }
  17072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  17073. isKnowKey = TRUE;
  17074. }
  17075. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  17076. {
  17077. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  17078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  17079. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17080. {
  17081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  17082. }
  17083. else
  17084. {
  17085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17086. }
  17087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17088. isKnowKey = TRUE;
  17089. }
  17090. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17091. {
  17092. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17095. {
  17096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17097. }
  17098. else
  17099. {
  17100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17101. }
  17102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17103. isKnowKey = TRUE;
  17104. }
  17105. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17106. {
  17107. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17110. {
  17111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17112. }
  17113. else
  17114. {
  17115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17116. }
  17117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17118. isKnowKey = TRUE;
  17119. }
  17120. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17121. {
  17122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17125. {
  17126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17127. }
  17128. else
  17129. {
  17130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17131. }
  17132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17133. isKnowKey = TRUE;
  17134. }
  17135. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17136. {
  17137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17140. {
  17141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17142. }
  17143. else
  17144. {
  17145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17146. }
  17147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17148. isKnowKey = TRUE;
  17149. }
  17150. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17151. {
  17152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17155. {
  17156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17157. }
  17158. else
  17159. {
  17160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17161. }
  17162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17163. isKnowKey = TRUE;
  17164. }
  17165. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17166. {
  17167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17170. {
  17171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17172. }
  17173. else
  17174. {
  17175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17176. }
  17177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17178. isKnowKey = TRUE;
  17179. }
  17180. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17181. {
  17182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17185. {
  17186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17187. }
  17188. else
  17189. {
  17190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17191. }
  17192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17193. isKnowKey = TRUE;
  17194. }
  17195. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17196. {
  17197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17200. {
  17201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17202. }
  17203. else
  17204. {
  17205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17206. }
  17207. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17209. isKnowKey = TRUE;
  17210. }
  17211. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17212. {
  17213. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17216. {
  17217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17218. }
  17219. else
  17220. {
  17221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17222. }
  17223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17224. isKnowKey = TRUE;
  17225. }
  17226. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17227. {
  17228. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17231. {
  17232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17233. }
  17234. else
  17235. {
  17236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17237. }
  17238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17239. isKnowKey = TRUE;
  17240. }
  17241. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17242. {
  17243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17246. {
  17247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17248. }
  17249. else
  17250. {
  17251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17252. }
  17253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17254. isKnowKey = TRUE;
  17255. }
  17256. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17257. {
  17258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17261. {
  17262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17263. }
  17264. else
  17265. {
  17266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17267. }
  17268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17269. isKnowKey = TRUE;
  17270. }
  17271. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17272. {
  17273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17276. {
  17277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17278. }
  17279. else
  17280. {
  17281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17282. }
  17283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17284. isKnowKey = TRUE;
  17285. }
  17286. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17287. {
  17288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17291. {
  17292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17293. }
  17294. else
  17295. {
  17296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17297. }
  17298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17299. isKnowKey = TRUE;
  17300. }
  17301. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17302. {
  17303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17306. {
  17307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17308. }
  17309. else
  17310. {
  17311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17312. }
  17313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17314. isKnowKey = TRUE;
  17315. }
  17316. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17317. {
  17318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17321. {
  17322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17323. }
  17324. else
  17325. {
  17326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17327. }
  17328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17329. isKnowKey = TRUE;
  17330. }
  17331. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17332. {
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17336. {
  17337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17338. }
  17339. else
  17340. {
  17341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17342. }
  17343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17344. isKnowKey = TRUE;
  17345. }
  17346. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17347. {
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17351. {
  17352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17353. }
  17354. else
  17355. {
  17356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17357. }
  17358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17359. isKnowKey = TRUE;
  17360. }
  17361. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17362. {
  17363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17366. {
  17367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17368. }
  17369. else
  17370. {
  17371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17372. }
  17373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17374. isKnowKey = TRUE;
  17375. }
  17376. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17377. {
  17378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17381. {
  17382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17383. }
  17384. else
  17385. {
  17386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17387. }
  17388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17389. isKnowKey = TRUE;
  17390. }
  17391. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17392. {
  17393. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17396. {
  17397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17398. }
  17399. else
  17400. {
  17401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17402. }
  17403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17404. isKnowKey = TRUE;
  17405. }
  17406. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17407. {
  17408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17411. {
  17412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17413. }
  17414. else
  17415. {
  17416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17417. }
  17418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17419. isKnowKey = TRUE;
  17420. }
  17421. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17422. {
  17423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17426. {
  17427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17428. }
  17429. else
  17430. {
  17431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17432. }
  17433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17434. isKnowKey = TRUE;
  17435. }
  17436. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17437. {
  17438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17441. {
  17442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17443. }
  17444. else
  17445. {
  17446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17447. }
  17448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17449. isKnowKey = TRUE;
  17450. }
  17451. /*
  17452. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17453. {
  17454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17457. {
  17458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17459. }
  17460. else
  17461. {
  17462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17463. }
  17464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17465. isKnowKey = TRUE;
  17466. }*/
  17467. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17468. {
  17469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17472. {
  17473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17474. }
  17475. else
  17476. {
  17477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17478. }
  17479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17480. isKnowKey = TRUE;
  17481. }
  17482. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17483. {
  17484. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17487. {
  17488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17489. }
  17490. else
  17491. {
  17492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17493. }
  17494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17495. isKnowKey = TRUE;
  17496. }
  17497. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17498. {
  17499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17502. {
  17503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17504. }
  17505. else
  17506. {
  17507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17508. }
  17509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17510. isKnowKey = TRUE;
  17511. }
  17512. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17513. {
  17514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17517. {
  17518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17519. }
  17520. else
  17521. {
  17522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17523. }
  17524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17525. isKnowKey = TRUE;
  17526. }
  17527. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17528. {
  17529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17532. {
  17533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17534. }
  17535. else
  17536. {
  17537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17538. }
  17539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17540. isKnowKey = TRUE;
  17541. }
  17542. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17543. {
  17544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17547. {
  17548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17549. }
  17550. else
  17551. {
  17552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17553. }
  17554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17555. isKnowKey = TRUE;
  17556. }
  17557. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17558. {
  17559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17562. {
  17563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17564. }
  17565. else
  17566. {
  17567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17568. }
  17569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17570. isKnowKey = TRUE;
  17571. }
  17572. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17573. {
  17574. struct sysinfo s_info;
  17575. int error = sysinfo(&s_info);
  17576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17579. {
  17580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17581. }
  17582. else
  17583. {
  17584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17585. }
  17586. if(error != 0)
  17587. {
  17588. DEBUG_WARN("System uptime get error: %d\n", error);
  17589. }
  17590. else
  17591. {
  17592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17593. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17594. }
  17595. isKnowKey = TRUE;
  17596. }
  17597. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17598. {
  17599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17602. {
  17603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17604. }
  17605. else
  17606. {
  17607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17608. }
  17609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17610. isKnowKey = TRUE;
  17611. }
  17612. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17613. {
  17614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17617. {
  17618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17619. }
  17620. else
  17621. {
  17622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17623. }
  17624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17625. isKnowKey = TRUE;
  17626. }
  17627. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17628. {
  17629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17632. {
  17633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17634. }
  17635. else
  17636. {
  17637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17638. }
  17639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17640. isKnowKey = TRUE;
  17641. }
  17642. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17643. {
  17644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17647. {
  17648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17649. }
  17650. else
  17651. {
  17652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17653. }
  17654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17655. isKnowKey = TRUE;
  17656. }
  17657. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17658. {
  17659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17662. {
  17663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17664. }
  17665. else
  17666. {
  17667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17668. }
  17669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17670. isKnowKey = TRUE;
  17671. }
  17672. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17673. {
  17674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17677. {
  17678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17679. }
  17680. else
  17681. {
  17682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17683. }
  17684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17685. isKnowKey = TRUE;
  17686. }
  17687. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17688. {
  17689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17692. {
  17693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17694. }
  17695. else
  17696. {
  17697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17698. }
  17699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17700. isKnowKey = TRUE;
  17701. }
  17702. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17703. {
  17704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17707. {
  17708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17709. }
  17710. else
  17711. {
  17712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17713. }
  17714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17715. isKnowKey = TRUE;
  17716. }
  17717. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17718. {
  17719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17722. {
  17723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17724. }
  17725. else
  17726. {
  17727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17728. }
  17729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17730. isKnowKey = TRUE;
  17731. }
  17732. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17733. {
  17734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17737. {
  17738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17739. }
  17740. else
  17741. {
  17742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17743. }
  17744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17745. isKnowKey = TRUE;
  17746. }
  17747. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17748. {
  17749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17752. {
  17753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17754. }
  17755. else
  17756. {
  17757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17758. }
  17759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17760. isKnowKey = TRUE;
  17761. }
  17762. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17763. {
  17764. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17767. {
  17768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17769. }
  17770. else
  17771. {
  17772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17773. }
  17774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17775. isKnowKey = TRUE;
  17776. }
  17777. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17778. {
  17779. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17781. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17782. {
  17783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17784. }
  17785. else
  17786. {
  17787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17788. }
  17789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17790. isKnowKey = TRUE;
  17791. }
  17792. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17793. {
  17794. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17797. {
  17798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17799. }
  17800. else
  17801. {
  17802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17803. }
  17804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17805. isKnowKey = TRUE;
  17806. }
  17807. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17808. {
  17809. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17812. {
  17813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17814. }
  17815. else
  17816. {
  17817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17818. }
  17819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17820. isKnowKey = TRUE;
  17821. }
  17822. if(isEmpty || strcmp(keyReq, "AuthDownloadlinkCertificate") == 0 )
  17823. {
  17824. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthDownloadlinkCertificate].Item, "AuthDownloadlinkCertificate");
  17825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Key, "AuthDownloadlinkCertificate");
  17826. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  17827. {
  17828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "0"/*"FALSE"*/);
  17829. }
  17830. else
  17831. {
  17832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "1"/*"TRUE"*/);
  17833. }
  17834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData );
  17835. isKnowKey = TRUE;
  17836. }
  17837. if(isEmpty || strcmp(keyReq, "RfidEndianType") == 0 )
  17838. {
  17839. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_RfidEndianType].Item, "RfidEndianType");
  17840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].Key, "RfidEndianType");
  17841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility == 1)
  17842. {
  17843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].ReadOnly, "0"/*"FALSE"*/);
  17844. }
  17845. else
  17846. {
  17847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].ReadOnly, "1"/*"TRUE"*/);
  17848. }
  17849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].Value, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE");
  17850. isKnowKey = TRUE;
  17851. }
  17852. if(isEmpty || strcmp(keyReq, "AuthorizeTimeout") == 0 )
  17853. {
  17854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeTimeout].Item, "AuthorizeTimeout");
  17855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].Key, "AuthorizeTimeout");
  17856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility == 1)
  17857. {
  17858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].ReadOnly, "0"/*"FALSE"*/);
  17859. }
  17860. else
  17861. {
  17862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].ReadOnly, "1"/*"TRUE"*/);
  17863. }
  17864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  17865. isKnowKey = TRUE;
  17866. }
  17867. if(isEmpty || strcmp(keyReq, "Enable15118") == 0 )
  17868. {
  17869. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_Enable15118].Item, "Enable15118");
  17870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_Enable15118].Key, "Enable15118");
  17871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility == 1)
  17872. {
  17873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_Enable15118].ReadOnly, "0"/*"FALSE"*/);
  17874. }
  17875. else
  17876. {
  17877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_Enable15118].ReadOnly, "1"/*"TRUE"*/);
  17878. }
  17879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_Enable15118].Value, ShmSysConfigAndInfo->SysConfig.isEnable15118==1?"TRUE":"FALSE");
  17880. isKnowKey = TRUE;
  17881. }
  17882. #if 1
  17883. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17884. {
  17885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17887. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17888. {
  17889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17890. }
  17891. else
  17892. {
  17893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17894. }
  17895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17896. isKnowKey = TRUE;
  17897. }
  17898. #endif
  17899. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17900. {
  17901. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17903. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17904. {
  17905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17906. }
  17907. else
  17908. {
  17909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17910. }
  17911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17912. isKnowKey = TRUE;
  17913. }
  17914. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17915. {
  17916. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17918. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17919. {
  17920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17921. }
  17922. else
  17923. {
  17924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17925. }
  17926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17927. isKnowKey = TRUE;
  17928. }
  17929. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17930. {
  17931. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17933. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17934. {
  17935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17936. }
  17937. else
  17938. {
  17939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17940. }
  17941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17942. isKnowKey = TRUE;
  17943. }
  17944. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17945. {
  17946. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17948. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17949. {
  17950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17951. }
  17952. else
  17953. {
  17954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17955. }
  17956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17957. isKnowKey = TRUE;
  17958. }
  17959. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17960. {
  17961. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17963. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17964. {
  17965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17966. }
  17967. else
  17968. {
  17969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17970. }
  17971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17972. isKnowKey = TRUE;
  17973. }
  17974. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17975. {
  17976. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17978. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17979. {
  17980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17981. }
  17982. else
  17983. {
  17984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17985. }
  17986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17987. isKnowKey = TRUE;
  17988. }
  17989. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17990. {
  17991. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17993. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17994. {
  17995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17996. }
  17997. else
  17998. {
  17999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  18000. }
  18001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  18002. isKnowKey = TRUE;
  18003. }
  18004. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  18005. {
  18006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  18007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  18008. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  18009. {
  18010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  18011. }
  18012. else
  18013. {
  18014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  18015. }
  18016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  18017. isKnowKey = TRUE;
  18018. }
  18019. //=========================================================
  18020. if(!isEmpty && !isKnowKey)
  18021. {
  18022. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  18023. strcpy(unknownkey[UnknownKeynum], keyReq);
  18024. UnknownKeynum = UnknownKeynum + 1;
  18025. }
  18026. }
  18027. void processUnkownKey(void)
  18028. {
  18029. DEBUG_INFO("processUnkownKey...\n");
  18030. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  18031. for(int index=0; index < UnknownKeynum; index++)
  18032. {
  18033. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  18034. {
  18035. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  18036. }
  18037. }
  18038. }
  18039. int setKeyValue(char *key, char *value)
  18040. {
  18041. int isSuccess = NotSupported;
  18042. int check_ascii=0;
  18043. char str[501]={0};
  18044. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  18045. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  18046. {
  18047. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  18048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  18049. {
  18050. strcpy(str, (const char*)value);
  18051. for(int i = 0; str[i]; i++){
  18052. str[i] = tolower(str[i]);
  18053. }
  18054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18055. isSuccess = ConfigurationStatus_Accepted;
  18056. }
  18057. else
  18058. {
  18059. isSuccess = ConfigurationStatus_Rejected;
  18060. }
  18061. }
  18062. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  18063. {
  18064. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  18065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  18066. {
  18067. strcpy(str, (const char*)value);
  18068. for(int i = 0; str[i]; i++){
  18069. str[i] = tolower(str[i]);
  18070. }
  18071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18072. isSuccess = ConfigurationStatus_Accepted;
  18073. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  18074. }
  18075. else
  18076. {
  18077. isSuccess = ConfigurationStatus_Rejected;
  18078. }
  18079. }
  18080. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  18081. {
  18082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  18083. {
  18084. strcpy(str, (const char*)value);
  18085. for(int i = 0; str[i]; i++)
  18086. {
  18087. str[i] = tolower(str[i]);
  18088. }
  18089. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  18090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18091. isSuccess = ConfigurationStatus_Accepted;
  18092. }
  18093. else
  18094. {
  18095. isSuccess = ConfigurationStatus_Rejected;
  18096. }
  18097. }
  18098. if(strcmp(key, "BlinkRepeat") == 0)
  18099. {
  18100. //Charger.BlinkRepeat = Integer.parseInt(value);
  18101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  18102. {
  18103. check_ascii = value[0];
  18104. if( (check_ascii < 48) || (check_ascii > 57) )
  18105. {
  18106. isSuccess = ConfigurationStatus_Rejected;
  18107. }
  18108. else
  18109. {
  18110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  18111. isSuccess = ConfigurationStatus_Accepted;
  18112. }
  18113. }
  18114. else
  18115. {
  18116. isSuccess = ConfigurationStatus_Rejected;
  18117. }
  18118. }
  18119. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  18120. {
  18121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  18122. {
  18123. check_ascii = value[0];
  18124. if( (check_ascii < 48) || (check_ascii > 57) )
  18125. {
  18126. isSuccess = ConfigurationStatus_Rejected;
  18127. }
  18128. else
  18129. {
  18130. if((atoi(value) == 0) || (atoi(value) >= 5))
  18131. {
  18132. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  18133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  18134. isSuccess = ConfigurationStatus_Accepted;
  18135. }
  18136. else
  18137. isSuccess = ConfigurationStatus_Rejected;
  18138. }
  18139. }
  18140. else
  18141. {
  18142. isSuccess = ConfigurationStatus_Rejected;
  18143. }
  18144. }
  18145. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18146. {
  18147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18148. {
  18149. check_ascii = value[0];
  18150. if( (check_ascii < 48) || (check_ascii > 57) )
  18151. {
  18152. isSuccess = ConfigurationStatus_Rejected;
  18153. }
  18154. else
  18155. {
  18156. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18158. isSuccess = ConfigurationStatus_Accepted;
  18159. }
  18160. }
  18161. else
  18162. {
  18163. isSuccess = ConfigurationStatus_Rejected;
  18164. }
  18165. }
  18166. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18167. {
  18168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18169. {
  18170. check_ascii = value[0];
  18171. if( (check_ascii < 48) || (check_ascii > 57) )
  18172. {
  18173. isSuccess = ConfigurationStatus_Rejected;
  18174. }
  18175. else
  18176. {
  18177. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18179. isSuccess = ConfigurationStatus_Accepted;
  18180. }
  18181. }
  18182. else
  18183. {
  18184. isSuccess = ConfigurationStatus_Rejected;
  18185. }
  18186. }
  18187. if(strcmp(key, "HeartbeatInterval") == 0)
  18188. {
  18189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18190. {
  18191. check_ascii = value[0];
  18192. if( (check_ascii < 48) || (check_ascii > 57) )
  18193. {
  18194. isSuccess = ConfigurationStatus_Rejected;
  18195. }
  18196. else
  18197. {
  18198. if((atoi(value) == 0) || (atoi(value) >= 10))
  18199. {
  18200. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18202. HeartBeatWaitTime = atoi(value);
  18203. isSuccess = ConfigurationStatus_Accepted;
  18204. }
  18205. else
  18206. {
  18207. isSuccess = ConfigurationStatus_Rejected;
  18208. }
  18209. }
  18210. }
  18211. else
  18212. {
  18213. isSuccess = ConfigurationStatus_Rejected;
  18214. }
  18215. }
  18216. if(strcmp(key, "LightIntensity") == 0)
  18217. {
  18218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18219. {
  18220. check_ascii = value[0];
  18221. if( (check_ascii < 48) || (check_ascii > 57) )
  18222. {
  18223. isSuccess = ConfigurationStatus_Rejected;
  18224. }
  18225. else
  18226. {
  18227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18228. isSuccess = ConfigurationStatus_Accepted;
  18229. }
  18230. }
  18231. else
  18232. {
  18233. isSuccess = ConfigurationStatus_Rejected;
  18234. }
  18235. }
  18236. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18237. {
  18238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18239. {
  18240. strcpy(str, (const char*)value);
  18241. for(int i = 0; str[i]; i++)
  18242. {
  18243. str[i] = tolower(str[i]);
  18244. }
  18245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18246. isSuccess = ConfigurationStatus_Accepted;
  18247. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18248. }
  18249. else
  18250. {
  18251. isSuccess = ConfigurationStatus_Rejected;
  18252. }
  18253. }
  18254. if(strcmp(key, "LocalPreAuthorize") == 0)
  18255. {
  18256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18257. {
  18258. strcpy(str, (const char*)value);
  18259. for(int i = 0; str[i]; i++)
  18260. {
  18261. str[i] = tolower(str[i]);
  18262. }
  18263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18264. isSuccess = ConfigurationStatus_Accepted;
  18265. }
  18266. else
  18267. {
  18268. isSuccess = ConfigurationStatus_Rejected;
  18269. }
  18270. }
  18271. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18272. {
  18273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18274. {
  18275. check_ascii = value[0];
  18276. if( (check_ascii < 48) || (check_ascii > 57) )
  18277. {
  18278. isSuccess = ConfigurationStatus_Rejected;
  18279. }
  18280. else
  18281. {
  18282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18283. isSuccess = ConfigurationStatus_Accepted;
  18284. }
  18285. }
  18286. else
  18287. {
  18288. isSuccess = ConfigurationStatus_Rejected;
  18289. }
  18290. }
  18291. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18292. {
  18293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18294. {
  18295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18296. isSuccess = ConfigurationStatus_Accepted;
  18297. }
  18298. else
  18299. {
  18300. isSuccess = ConfigurationStatus_Rejected;
  18301. }
  18302. }
  18303. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18304. {
  18305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18306. {
  18307. check_ascii = value[0];
  18308. if( (check_ascii < 48) || (check_ascii > 57) )
  18309. {
  18310. isSuccess = ConfigurationStatus_Rejected;
  18311. }
  18312. else
  18313. {
  18314. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18316. isSuccess = ConfigurationStatus_Accepted;
  18317. }
  18318. }
  18319. else
  18320. {
  18321. isSuccess = ConfigurationStatus_Rejected;
  18322. }
  18323. }
  18324. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18325. {
  18326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18327. {
  18328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18329. isSuccess = ConfigurationStatus_Accepted;
  18330. }
  18331. else
  18332. {
  18333. isSuccess = ConfigurationStatus_Rejected;
  18334. }
  18335. }
  18336. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18337. {
  18338. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18339. {
  18340. check_ascii = value[0];
  18341. if( (check_ascii < 48) || (check_ascii > 57) )
  18342. {
  18343. isSuccess = ConfigurationStatus_Rejected;
  18344. }
  18345. else
  18346. {
  18347. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18349. isSuccess = ConfigurationStatus_Accepted;
  18350. }
  18351. }
  18352. else
  18353. {
  18354. isSuccess = ConfigurationStatus_Rejected;
  18355. }
  18356. }
  18357. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18358. {
  18359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18360. {
  18361. check_ascii = value[0];
  18362. if( (check_ascii < 48) || (check_ascii > 57) )
  18363. {
  18364. isSuccess = ConfigurationStatus_Rejected;
  18365. }
  18366. else
  18367. {
  18368. if((atoi(value) == 0) || (atoi(value) >= 3))
  18369. {
  18370. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18372. isSuccess = ConfigurationStatus_Accepted;
  18373. }
  18374. else
  18375. {
  18376. isSuccess = ConfigurationStatus_Rejected;
  18377. }
  18378. }
  18379. }
  18380. else
  18381. {
  18382. isSuccess = ConfigurationStatus_Rejected;
  18383. }
  18384. }
  18385. if(strcmp(key, "MinimumStatusDuration") == 0)
  18386. {
  18387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18388. {
  18389. check_ascii = value[0];
  18390. if( (check_ascii < 48) || (check_ascii > 57) )
  18391. {
  18392. isSuccess = ConfigurationStatus_Rejected;
  18393. }
  18394. else
  18395. {
  18396. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18397. {
  18398. isSuccess = ConfigurationStatus_Rejected;
  18399. }
  18400. else
  18401. {
  18402. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18404. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18405. isSuccess = ConfigurationStatus_Accepted;
  18406. }
  18407. }
  18408. }
  18409. else
  18410. {
  18411. isSuccess = ConfigurationStatus_Rejected;
  18412. }
  18413. }
  18414. if(strcmp(key, "NumberOfConnectors") == 0)
  18415. {
  18416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18417. {
  18418. check_ascii = value[0];
  18419. if( (check_ascii < 48) || (check_ascii > 57) )
  18420. {
  18421. isSuccess = ConfigurationStatus_Rejected;
  18422. }
  18423. else
  18424. {
  18425. //Charger.ResetRetries = Integer.parseInt(value);
  18426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18427. isSuccess = ConfigurationStatus_Accepted;
  18428. }
  18429. }
  18430. else
  18431. {
  18432. isSuccess = ConfigurationStatus_Rejected;
  18433. }
  18434. }
  18435. if(strcmp(key, "ResetRetries") == 0)
  18436. {
  18437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18438. {
  18439. check_ascii = value[0];
  18440. if( (check_ascii < 48) || (check_ascii > 57) )
  18441. {
  18442. isSuccess = ConfigurationStatus_Rejected;
  18443. }
  18444. else
  18445. {
  18446. //Charger.ResetRetries = Integer.parseInt(value);
  18447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18448. isSuccess = ConfigurationStatus_Accepted;
  18449. }
  18450. }
  18451. else
  18452. {
  18453. isSuccess = ConfigurationStatus_Rejected;
  18454. }
  18455. }
  18456. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18457. {
  18458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18459. {
  18460. strcpy(str, (const char*)value);
  18461. for(int i = 0; str[i]; i++)
  18462. {
  18463. str[i] = tolower(str[i]);
  18464. }
  18465. if(strcmp(str, "notapplicable")== 0)
  18466. {
  18467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18468. isSuccess = ConfigurationStatus_Accepted;
  18469. }
  18470. else if(strcmp(str, "unknown")== 0)
  18471. {
  18472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18473. isSuccess = ConfigurationStatus_Accepted;
  18474. }
  18475. else if(strcmp(str, "rst")== 0)
  18476. {
  18477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18478. isSuccess = ConfigurationStatus_Accepted;
  18479. }
  18480. else if(strcmp(str, "rts")== 0)
  18481. {
  18482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18483. isSuccess = ConfigurationStatus_Accepted;
  18484. }
  18485. else if(strcmp(str, "srt")== 0)
  18486. {
  18487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18488. isSuccess = ConfigurationStatus_Accepted;
  18489. }
  18490. else if(strcmp(str, "str")== 0)
  18491. {
  18492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18493. isSuccess = ConfigurationStatus_Accepted;
  18494. }
  18495. else if(strcmp(str, "trs")== 0)
  18496. {
  18497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18498. isSuccess = ConfigurationStatus_Accepted;
  18499. }
  18500. else if(strcmp(str, "tsr")== 0)
  18501. {
  18502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18503. isSuccess = ConfigurationStatus_Accepted;
  18504. }
  18505. else
  18506. {
  18507. isSuccess = ConfigurationStatus_Rejected;
  18508. }
  18509. }
  18510. else
  18511. {
  18512. isSuccess = ConfigurationStatus_Rejected;
  18513. }
  18514. }
  18515. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18516. {
  18517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18518. {
  18519. check_ascii = value[0];
  18520. if( (check_ascii < 48) || (check_ascii > 57) )
  18521. {
  18522. isSuccess = ConfigurationStatus_Rejected;
  18523. }
  18524. else
  18525. {
  18526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18527. isSuccess = ConfigurationStatus_Accepted;
  18528. }
  18529. }
  18530. else
  18531. {
  18532. isSuccess = ConfigurationStatus_Rejected;
  18533. }
  18534. }
  18535. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18536. {
  18537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18538. {
  18539. strcpy(str, (const char*)value);
  18540. for(int i = 0; str[i]; i++)
  18541. {
  18542. str[i] = tolower(str[i]);
  18543. }
  18544. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18546. isSuccess = ConfigurationStatus_Accepted;
  18547. }
  18548. else
  18549. {
  18550. isSuccess = ConfigurationStatus_Rejected;
  18551. }
  18552. }
  18553. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18554. {
  18555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18556. {
  18557. strcpy(str, (const char*)value);
  18558. for(int i = 0; str[i]; i++)
  18559. {
  18560. str[i] = tolower(str[i]);
  18561. }
  18562. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18564. isSuccess = ConfigurationStatus_Accepted;
  18565. }
  18566. else
  18567. {
  18568. isSuccess = ConfigurationStatus_Rejected;
  18569. }
  18570. }
  18571. if(strcmp(key, "StopTxnAlignedData") == 0)
  18572. {
  18573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18574. {
  18575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18576. isSuccess = ConfigurationStatus_Accepted;
  18577. }
  18578. else
  18579. {
  18580. isSuccess = ConfigurationStatus_Rejected;
  18581. }
  18582. }
  18583. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18584. {
  18585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18586. {
  18587. check_ascii = value[0];
  18588. if( (check_ascii < 48) || (check_ascii > 57) )
  18589. {
  18590. isSuccess = ConfigurationStatus_Rejected;
  18591. }
  18592. else
  18593. {
  18594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18595. isSuccess = ConfigurationStatus_Accepted;
  18596. }
  18597. }
  18598. else
  18599. {
  18600. isSuccess = ConfigurationStatus_Rejected;
  18601. }
  18602. }
  18603. if(strcmp(key, "StopTxnSampledData") == 0)
  18604. {
  18605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18606. {
  18607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18608. isSuccess = ConfigurationStatus_Accepted;
  18609. }
  18610. else
  18611. {
  18612. isSuccess = ConfigurationStatus_Rejected;
  18613. }
  18614. }
  18615. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18616. {
  18617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18618. {
  18619. check_ascii = value[0];
  18620. if( (check_ascii < 48) || (check_ascii > 57) )
  18621. {
  18622. isSuccess = ConfigurationStatus_Rejected;
  18623. }
  18624. else
  18625. {
  18626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18627. isSuccess = ConfigurationStatus_Accepted;
  18628. }
  18629. }
  18630. else
  18631. {
  18632. isSuccess = ConfigurationStatus_Rejected;
  18633. }
  18634. }
  18635. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18636. {
  18637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18638. {
  18639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18640. isSuccess = ConfigurationStatus_Accepted;
  18641. }
  18642. else
  18643. {
  18644. isSuccess = ConfigurationStatus_Rejected;
  18645. }
  18646. }
  18647. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18648. {
  18649. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18650. {
  18651. check_ascii = value[0];
  18652. if( (check_ascii < 48) || (check_ascii > 57) )
  18653. {
  18654. isSuccess = ConfigurationStatus_Rejected;
  18655. }
  18656. else
  18657. {
  18658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18659. isSuccess = ConfigurationStatus_Accepted;
  18660. }
  18661. }
  18662. else
  18663. {
  18664. isSuccess = ConfigurationStatus_Rejected;
  18665. }
  18666. }
  18667. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18668. {
  18669. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18670. {
  18671. check_ascii = value[0];
  18672. if( (check_ascii < 48) || (check_ascii > 57) )
  18673. {
  18674. isSuccess = ConfigurationStatus_Rejected;
  18675. }
  18676. else
  18677. {
  18678. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18680. TransactionMessageAttemptsValue = atoi(value);
  18681. isSuccess = ConfigurationStatus_Accepted;
  18682. }
  18683. }
  18684. else
  18685. {
  18686. isSuccess = ConfigurationStatus_Rejected;
  18687. }
  18688. }
  18689. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18690. {
  18691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18692. {
  18693. check_ascii = value[0];
  18694. if( (check_ascii < 48) || (check_ascii > 57) )
  18695. {
  18696. isSuccess = ConfigurationStatus_Rejected;
  18697. }
  18698. else
  18699. {
  18700. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18702. TransactionMessageRetryIntervalValue = atoi(value);
  18703. isSuccess = ConfigurationStatus_Accepted;
  18704. }
  18705. }
  18706. else
  18707. {
  18708. isSuccess = ConfigurationStatus_Rejected;
  18709. }
  18710. }
  18711. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18712. {
  18713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18714. {
  18715. strcpy(str, (const char*)value);
  18716. for(int i = 0; str[i]; i++)
  18717. {
  18718. str[i] = tolower(str[i]);
  18719. }
  18720. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18722. isSuccess = ConfigurationStatus_Accepted;
  18723. }
  18724. else
  18725. {
  18726. isSuccess = ConfigurationStatus_Rejected;
  18727. }
  18728. }
  18729. if(strcmp(key, "WebSocketPingInterval") == 0)
  18730. {
  18731. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18732. {
  18733. check_ascii = value[0];
  18734. if( (check_ascii < 48) || (check_ascii > 57) )
  18735. {
  18736. isSuccess = ConfigurationStatus_Rejected;
  18737. }
  18738. else
  18739. {
  18740. if((atoi(value) == 0) || (atoi(value) >= 10))
  18741. {
  18742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18743. isSuccess = ConfigurationStatus_Accepted;
  18744. }
  18745. else
  18746. isSuccess = ConfigurationStatus_Rejected;
  18747. }
  18748. }
  18749. else
  18750. {
  18751. isSuccess = ConfigurationStatus_Rejected;
  18752. }
  18753. }
  18754. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18755. {
  18756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18757. {
  18758. strcpy(str, (const char*)value);
  18759. for(int i = 0; str[i]; i++)
  18760. {
  18761. str[i] = tolower(str[i]);
  18762. }
  18763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18764. isSuccess = ConfigurationStatus_Accepted;
  18765. }
  18766. else
  18767. {
  18768. isSuccess = ConfigurationStatus_Rejected;
  18769. }
  18770. }
  18771. if(strcmp(key, "AuthorizationKey") == 0)
  18772. {
  18773. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18774. {
  18775. strcpy(str, (const char*)value);
  18776. int strlength = strlen(str);
  18777. char capture[3];
  18778. char stackItem = 0;
  18779. char password[21] = {0};
  18780. printf("String length: %d\n", strlength);
  18781. for(int idx=0; idx<(strlength/2); idx++)
  18782. {
  18783. capture[0] = str[(idx*2)];
  18784. capture[1] = str[(idx*2)+1];
  18785. capture[2] = 0;
  18786. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  18787. sprintf(password,"%s%c", password, stackItem);
  18788. }
  18789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  18790. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18791. isSuccess = ConfigurationStatus_Accepted;
  18792. }
  18793. else
  18794. {
  18795. isSuccess = ConfigurationStatus_Rejected;
  18796. }
  18797. }
  18798. if(strcmp(key, "SecurityProfile") == 0)
  18799. {
  18800. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18801. {
  18802. check_ascii = value[0];
  18803. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18804. {
  18805. isSuccess = ConfigurationStatus_Rejected;
  18806. }
  18807. else if(check_ascii == 0x33)
  18808. {
  18809. isSuccess = NotSupported;
  18810. }
  18811. else
  18812. {
  18813. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18814. {
  18815. if(((check_ascii - 0x30) == 1) ||
  18816. ((check_ascii - 0x30) == 2) ||
  18817. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18818. {
  18819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18820. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18821. isSuccess = ConfigurationStatus_Accepted;
  18822. }
  18823. else
  18824. isSuccess = ConfigurationStatus_Rejected;
  18825. }
  18826. else
  18827. isSuccess = ConfigurationStatus_Rejected;
  18828. }
  18829. }
  18830. else
  18831. {
  18832. isSuccess = ConfigurationStatus_Rejected;
  18833. }
  18834. }
  18835. if(strcmp(key, "DefaultPrice") == 0)
  18836. {
  18837. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18838. {
  18839. strcpy(str, (const char*)value);
  18840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18841. isSuccess = ConfigurationStatus_Accepted;
  18842. }
  18843. else
  18844. {
  18845. isSuccess = ConfigurationStatus_Rejected;
  18846. }
  18847. }
  18848. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18849. {
  18850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18851. {
  18852. strcpy(str, (const char*)value);
  18853. for(int i = 0; str[i]; i++)
  18854. {
  18855. str[i] = tolower(str[i]);
  18856. }
  18857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18858. isSuccess = ConfigurationStatus_Accepted;
  18859. }
  18860. else
  18861. {
  18862. isSuccess = ConfigurationStatus_Rejected;
  18863. }
  18864. }
  18865. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18866. {
  18867. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18868. {
  18869. strcpy(str, (const char*)value);
  18870. for(int i = 0; str[i]; i++)
  18871. {
  18872. str[i] = tolower(str[i]);
  18873. }
  18874. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18875. isSuccess = ConfigurationStatus_Accepted;
  18876. }
  18877. else
  18878. {
  18879. isSuccess = ConfigurationStatus_Rejected;
  18880. }
  18881. }
  18882. if(strcmp(key, "TimeOffset") == 0)
  18883. {
  18884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18885. {
  18886. strcpy(str, (const char*)value);
  18887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18888. isSuccess = ConfigurationStatus_Accepted;
  18889. }
  18890. else
  18891. {
  18892. isSuccess = ConfigurationStatus_Rejected;
  18893. }
  18894. }
  18895. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18896. {
  18897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18898. {
  18899. strcpy(str, (const char*)value);
  18900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18901. isSuccess = ConfigurationStatus_Accepted;
  18902. }
  18903. else
  18904. {
  18905. isSuccess = ConfigurationStatus_Rejected;
  18906. }
  18907. }
  18908. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18909. {
  18910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18911. {
  18912. strcpy(str, (const char*)value);
  18913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18914. isSuccess = ConfigurationStatus_Accepted;
  18915. }
  18916. else
  18917. {
  18918. isSuccess = ConfigurationStatus_Rejected;
  18919. }
  18920. }
  18921. if(strcmp(key, "SystemUptimeSec") == 0)
  18922. {
  18923. isSuccess = NotSupported;
  18924. }
  18925. if(strcmp(key, "FreeVend") == 0)
  18926. {
  18927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18928. {
  18929. strcpy(str, (const char*)value);
  18930. for(int i = 0; str[i]; i++)
  18931. {
  18932. str[i] = tolower(str[i]);
  18933. }
  18934. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18936. isSuccess = ConfigurationStatus_Accepted;
  18937. }
  18938. else
  18939. {
  18940. isSuccess = ConfigurationStatus_Rejected;
  18941. }
  18942. }
  18943. if(strcmp(key, "FreeVendIdtag") == 0)
  18944. {
  18945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18946. {
  18947. strcpy(str, (const char*)value);
  18948. if(strlen(str) <= 20)
  18949. {
  18950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18951. isSuccess = ConfigurationStatus_Accepted;
  18952. }
  18953. else
  18954. {
  18955. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18956. isSuccess = ConfigurationStatus_Rejected;
  18957. }
  18958. }
  18959. else
  18960. {
  18961. isSuccess = ConfigurationStatus_Rejected;
  18962. }
  18963. }
  18964. if(strcmp(key, "OcppServer") == 0)
  18965. {
  18966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18967. {
  18968. strcpy(str, (const char*)value);
  18969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18970. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18971. isSuccess = ConfigurationStatus_Accepted;
  18972. }
  18973. else
  18974. {
  18975. isSuccess = ConfigurationStatus_Rejected;
  18976. }
  18977. }
  18978. if(strcmp(key, "MaintainServer") == 0)
  18979. {
  18980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18981. {
  18982. strcpy(str, (const char*)value);
  18983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18984. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18985. isSuccess = ConfigurationStatus_Accepted;
  18986. }
  18987. else
  18988. {
  18989. isSuccess = ConfigurationStatus_Rejected;
  18990. }
  18991. }
  18992. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18993. {
  18994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18995. {
  18996. strcpy(str, (const char*)value);
  18997. for(int i = 0; str[i]; i++)
  18998. {
  18999. str[i] = tolower(str[i]);
  19000. }
  19001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  19002. isSuccess = ConfigurationStatus_Accepted;
  19003. }
  19004. else
  19005. {
  19006. isSuccess = ConfigurationStatus_Rejected;
  19007. }
  19008. }
  19009. if(strcmp(key, "StatusNotificationInterval") == 0)
  19010. {
  19011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  19012. {
  19013. check_ascii = value[0];
  19014. if( (check_ascii < 48) || (check_ascii > 57) )
  19015. {
  19016. isSuccess = ConfigurationStatus_Rejected;
  19017. }
  19018. else
  19019. {
  19020. if((atoi(value) == 0) || (atoi(value) >= 10))
  19021. {
  19022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  19023. isSuccess = ConfigurationStatus_Accepted;
  19024. }
  19025. else
  19026. isSuccess = ConfigurationStatus_Rejected;
  19027. }
  19028. }
  19029. else
  19030. {
  19031. isSuccess = ConfigurationStatus_Rejected;
  19032. }
  19033. }
  19034. if(strcmp(key, "PreAuthAmount") == 0)
  19035. {
  19036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  19037. {
  19038. check_ascii = value[0];
  19039. if( (check_ascii < 48) || (check_ascii > 57) )
  19040. {
  19041. isSuccess = ConfigurationStatus_Rejected;
  19042. }
  19043. else
  19044. {
  19045. if(atof(value) >= 0)
  19046. {
  19047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  19048. isSuccess = ConfigurationStatus_Accepted;
  19049. }
  19050. else
  19051. isSuccess = ConfigurationStatus_Rejected;
  19052. }
  19053. }
  19054. else
  19055. {
  19056. isSuccess = ConfigurationStatus_Rejected;
  19057. }
  19058. }
  19059. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  19060. {
  19061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  19062. {
  19063. check_ascii = value[0];
  19064. if( (check_ascii < 48) || (check_ascii > 57) )
  19065. {
  19066. isSuccess = ConfigurationStatus_Rejected;
  19067. }
  19068. else
  19069. {
  19070. if(atoi(value) >= 0)
  19071. {
  19072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  19073. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  19074. isSuccess = ConfigurationStatus_Accepted;
  19075. }
  19076. else
  19077. isSuccess = ConfigurationStatus_Rejected;
  19078. }
  19079. }
  19080. else
  19081. {
  19082. isSuccess = ConfigurationStatus_Rejected;
  19083. }
  19084. }
  19085. if(strcmp(key, "PowerSharingServerIP") == 0)
  19086. {
  19087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  19088. {
  19089. strcpy(str, (const char*)value);
  19090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  19091. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  19092. isSuccess = ConfigurationStatus_Accepted;
  19093. }
  19094. else
  19095. {
  19096. isSuccess = ConfigurationStatus_Rejected;
  19097. }
  19098. }
  19099. if(strcmp(key, "EVCCID_PREFIX") == 0)
  19100. {
  19101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  19102. {
  19103. strcpy(str, (const char*)value);
  19104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  19105. isSuccess = ConfigurationStatus_Accepted;
  19106. }
  19107. else
  19108. {
  19109. isSuccess = ConfigurationStatus_Rejected;
  19110. }
  19111. }
  19112. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  19113. {
  19114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  19115. {
  19116. if(atoi(value) > modelnameInfo.ratedPower)
  19117. {
  19118. isSuccess = ConfigurationStatus_Rejected;
  19119. }
  19120. else{
  19121. strcpy(str, (const char*)value);
  19122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  19123. isSuccess = ConfigurationStatus_Accepted;
  19124. }
  19125. }
  19126. else
  19127. {
  19128. isSuccess = ConfigurationStatus_Rejected;
  19129. }
  19130. }
  19131. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  19132. {
  19133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  19134. {
  19135. if((atoi(value) != 0) && (atoi(value) < 5))
  19136. {
  19137. isSuccess = ConfigurationStatus_Rejected;
  19138. }
  19139. else{
  19140. strcpy(str, (const char*)value);
  19141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  19142. isSuccess = ConfigurationStatus_Accepted;
  19143. }
  19144. }
  19145. else
  19146. {
  19147. isSuccess = ConfigurationStatus_Rejected;
  19148. }
  19149. }
  19150. if(strcmp(key, "CpoName") == 0)
  19151. {
  19152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19153. {
  19154. strcpy(str, (const char*)value);
  19155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19156. isSuccess = ConfigurationStatus_Accepted;
  19157. }
  19158. else
  19159. {
  19160. isSuccess = ConfigurationStatus_Rejected;
  19161. }
  19162. }
  19163. if(strcmp(key, "OcppSoftwareVersion") == 0)
  19164. {
  19165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  19166. {
  19167. strcpy(str, (const char*)value);
  19168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", str );
  19169. isSuccess = ConfigurationStatus_Accepted;
  19170. }
  19171. else
  19172. {
  19173. isSuccess = ConfigurationStatus_Rejected;
  19174. }
  19175. }
  19176. if(strcmp(key, "AuthDownloadlinkCertificate") == 0)
  19177. {
  19178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  19179. {
  19180. strcpy(str, (const char*)value);
  19181. for(int i = 0; str[i]; i++)
  19182. {
  19183. str[i] = tolower(str[i]);
  19184. }
  19185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19186. isSuccess = ConfigurationStatus_Accepted;
  19187. }
  19188. else
  19189. {
  19190. isSuccess = ConfigurationStatus_Rejected;
  19191. }
  19192. }
  19193. if(strcmp(key, "RfidEndianType") == 0)
  19194. {
  19195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility == 1)
  19196. {
  19197. strcpy(str, (const char*)value);
  19198. for(int i = 0; str[i]; i++)
  19199. {
  19200. str[i] = tolower(str[i]);
  19201. }
  19202. if((strcmp(str, "big")==0) || (strcmp(str, "little")==0))
  19203. {
  19204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "%s", str );
  19205. ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = (strcmp(str, "big")==0)?1:0;
  19206. isSuccess = ConfigurationStatus_Accepted;
  19207. }
  19208. else
  19209. isSuccess = ConfigurationStatus_Rejected;
  19210. }
  19211. else
  19212. {
  19213. isSuccess = ConfigurationStatus_Rejected;
  19214. }
  19215. }
  19216. if(strcmp(key, "AuthorizeTimeout") == 0)
  19217. {
  19218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility == 1)
  19219. {
  19220. strcpy(str, (const char*)value);
  19221. check_ascii = value[0];
  19222. if((check_ascii < 48) || (check_ascii > 57))
  19223. {
  19224. isSuccess = ConfigurationStatus_Rejected;
  19225. }
  19226. else
  19227. {
  19228. if((atoi(value) >= 10) && (atoi(value) <= 300))
  19229. {
  19230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "%s", str );
  19231. isSuccess = ConfigurationStatus_Accepted;
  19232. }
  19233. else
  19234. {
  19235. isSuccess = ConfigurationStatus_Rejected;
  19236. }
  19237. }
  19238. }
  19239. else
  19240. {
  19241. isSuccess = ConfigurationStatus_Rejected;
  19242. }
  19243. }
  19244. if(strcmp(key, "Enable15118") == 0)
  19245. {
  19246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility == 1)
  19247. {
  19248. strcpy(str, (const char*)value);
  19249. for(int i = 0; str[i]; i++)
  19250. {
  19251. str[i] = tolower(str[i]);
  19252. }
  19253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[Enable15118].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  19254. ShmSysConfigAndInfo->SysConfig.isEnable15118 = (strcmp(str, "true")==0)?1:0;
  19255. isSuccess = ConfigurationStatus_Accepted;
  19256. }
  19257. else
  19258. {
  19259. isSuccess = ConfigurationStatus_Rejected;
  19260. }
  19261. }
  19262. #if 0
  19263. //For OCPP Test Case
  19264. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19265. {
  19266. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19267. {
  19268. strcpy(str, (const char*)value);
  19269. for(int i = 0; str[i]; i++)
  19270. {
  19271. str[i] = tolower(str[i]);
  19272. }
  19273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19274. isSuccess = ConfigurationStatus_Accepted;
  19275. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19276. }
  19277. else
  19278. {
  19279. isSuccess = ConfigurationStatus_Rejected;
  19280. }
  19281. }
  19282. #endif
  19283. #if 1
  19284. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19285. {
  19286. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19287. {
  19288. strcpy(str, (const char*)value);
  19289. for(int i = 0; str[i]; i++)
  19290. {
  19291. str[i] = tolower(str[i]);
  19292. }
  19293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19294. isSuccess = ConfigurationStatus_Accepted;
  19295. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19296. }
  19297. else
  19298. {
  19299. isSuccess = ConfigurationStatus_Rejected;
  19300. }
  19301. }
  19302. #endif
  19303. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19304. {
  19305. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19306. {
  19307. check_ascii = value[0];
  19308. if( (check_ascii < 48) || (check_ascii > 57) )
  19309. {
  19310. isSuccess = ConfigurationStatus_Rejected;
  19311. }
  19312. else
  19313. {
  19314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19315. isSuccess = ConfigurationStatus_Accepted;
  19316. }
  19317. }
  19318. else
  19319. {
  19320. isSuccess = ConfigurationStatus_Rejected;
  19321. }
  19322. }
  19323. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19324. {
  19325. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19326. {
  19327. check_ascii = value[0];
  19328. if( (check_ascii < 48) || (check_ascii > 57) )
  19329. {
  19330. isSuccess = ConfigurationStatus_Rejected;
  19331. }
  19332. else
  19333. {
  19334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19335. isSuccess = ConfigurationStatus_Accepted;
  19336. }
  19337. }
  19338. else
  19339. {
  19340. isSuccess = ConfigurationStatus_Rejected;
  19341. }
  19342. }
  19343. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19344. {
  19345. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19346. {
  19347. strcpy(str, (const char*)value);
  19348. for(int i = 0; str[i]; i++)
  19349. {
  19350. str[i] = tolower(str[i]);
  19351. }
  19352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19353. isSuccess = ConfigurationStatus_Accepted;
  19354. }
  19355. else
  19356. {
  19357. isSuccess = ConfigurationStatus_Rejected;
  19358. }
  19359. }
  19360. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19361. {
  19362. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19363. {
  19364. check_ascii = value[0];
  19365. if( (check_ascii < 48) || (check_ascii > 57) )
  19366. {
  19367. isSuccess = ConfigurationStatus_Rejected;
  19368. }
  19369. else
  19370. {
  19371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19372. isSuccess = ConfigurationStatus_Accepted;
  19373. }
  19374. }
  19375. else
  19376. {
  19377. isSuccess = ConfigurationStatus_Rejected;
  19378. }
  19379. }
  19380. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19381. {
  19382. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19383. {
  19384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19385. isSuccess = ConfigurationStatus_Accepted;
  19386. }
  19387. else
  19388. {
  19389. isSuccess = ConfigurationStatus_Rejected;
  19390. }
  19391. }
  19392. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19393. {
  19394. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19395. {
  19396. check_ascii = value[0];
  19397. if( (check_ascii < 48) || (check_ascii > 57) )
  19398. {
  19399. isSuccess = ConfigurationStatus_Rejected;
  19400. }
  19401. else
  19402. {
  19403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19404. isSuccess = ConfigurationStatus_Accepted;
  19405. }
  19406. }
  19407. else
  19408. {
  19409. isSuccess = ConfigurationStatus_Rejected;
  19410. }
  19411. }
  19412. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19413. {
  19414. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19415. {
  19416. strcpy(str, (const char*)value);
  19417. for(int i = 0; str[i]; i++)
  19418. {
  19419. str[i] = tolower(str[i]);
  19420. }
  19421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19422. isSuccess = ConfigurationStatus_Accepted;
  19423. }
  19424. else
  19425. {
  19426. isSuccess = ConfigurationStatus_Rejected;
  19427. }
  19428. }
  19429. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19430. {
  19431. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19432. {
  19433. check_ascii = value[0];
  19434. if( (check_ascii < 48) || (check_ascii > 57) )
  19435. {
  19436. isSuccess = ConfigurationStatus_Rejected;
  19437. }
  19438. else
  19439. {
  19440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19441. isSuccess = ConfigurationStatus_Accepted;
  19442. }
  19443. }
  19444. else
  19445. {
  19446. isSuccess = ConfigurationStatus_Rejected;
  19447. }
  19448. }
  19449. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19450. return isSuccess;
  19451. }
  19452. int TransactionMessageAttemptsGet(void)
  19453. {
  19454. return TransactionMessageAttemptsValue;
  19455. }
  19456. int FirstHeartBeatResponse(void)
  19457. {
  19458. return FirstHeartBeat;
  19459. }
  19460. int TransactionMessageRetryIntervalGet(void)
  19461. {
  19462. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19463. }
  19464. int ReadHttpStatus(int sock)
  19465. {
  19466. //char c;
  19467. char buff[1024]="",*ptr=buff+1;
  19468. int bytes_received, status;
  19469. DEBUG_INFO("Begin Response ..\n");
  19470. while((bytes_received = recv(sock, ptr, 1, 0))){
  19471. if(bytes_received==-1){
  19472. perror("ReadHttpStatus");
  19473. exit(1);
  19474. }
  19475. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19476. ptr++;
  19477. }
  19478. *ptr=0;
  19479. ptr=buff+1;
  19480. sscanf(ptr,"%*s %d ", &status);
  19481. DEBUG_INFO("%s\n",ptr);
  19482. DEBUG_INFO("status=%d\n",status);
  19483. DEBUG_INFO("End Response ..\n");
  19484. return (bytes_received>0)?status:0;
  19485. }
  19486. //the only filed that it parsed is 'Content-Length'
  19487. int ParseHeader(int sock)
  19488. {
  19489. //char c;
  19490. char buff[1024]="",*ptr=buff+4;
  19491. int bytes_received;
  19492. DEBUG_INFO("Begin HEADER ..\n");
  19493. while((bytes_received = recv(sock, ptr, 1, 0))){
  19494. if(bytes_received==-1){
  19495. perror("Parse Header");
  19496. exit(1);
  19497. }
  19498. if(
  19499. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19500. (ptr[-1]=='\r') && (*ptr=='\n' )
  19501. ) break;
  19502. ptr++;
  19503. }
  19504. *ptr=0;
  19505. ptr=buff+4;
  19506. //printf("%s",ptr);
  19507. if(bytes_received){
  19508. ptr=strstr(ptr,"Content-Length:");
  19509. if(ptr){
  19510. sscanf(ptr,"%*s %d",&bytes_received);
  19511. }else
  19512. bytes_received=-1; //unknown size
  19513. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19514. }
  19515. DEBUG_INFO("End HEADER ..\n");
  19516. return bytes_received ;
  19517. }
  19518. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19519. {
  19520. int result = TRUE;
  19521. char rmFileCmd[300]={0};
  19522. char FilePath[256]={0};
  19523. char ftpbuf[2048];
  19524. int systemresult;
  19525. sprintf(FilePath,"/mnt/%s",filename);
  19526. system("ping 8.8.8.8 &");
  19527. if((access(FilePath,F_OK))!=-1)
  19528. {
  19529. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19530. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19531. system(rmFileCmd);
  19532. }
  19533. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19534. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19535. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  19536. else
  19537. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19538. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19539. systemresult = system(ftpbuf);
  19540. if(systemresult != 0)
  19541. {
  19542. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19543. result = FALSE;
  19544. }
  19545. system("pkill ping");
  19546. return result;
  19547. }
  19548. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19549. {
  19550. int result = TRUE;
  19551. char rmFileCmd[300]={0};
  19552. char FilePath[256]={0};
  19553. char ftpbuf[2048];
  19554. int systemresult;
  19555. sprintf(FilePath,"/mnt/%s",filename);
  19556. system("ping 8.8.8.8 &");
  19557. if((access(FilePath,F_OK))!=-1)
  19558. {
  19559. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19560. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19561. system(rmFileCmd);
  19562. }
  19563. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19564. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19565. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19566. systemresult = system(ftpbuf);
  19567. if(systemresult != 0)
  19568. {
  19569. DEBUG_WARN("scp error!\n");
  19570. result = FALSE;
  19571. }
  19572. system("pkill ping");
  19573. return result;
  19574. }
  19575. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19576. {
  19577. int result = TRUE;
  19578. char rmFileCmd[300]={0};
  19579. char FilePath[256]={0};
  19580. char ftpbuf[2048];
  19581. int systemresult;
  19582. sprintf(FilePath,"/mnt/%s",filename);
  19583. system("ping 8.8.8.8 &");
  19584. if((access(FilePath,F_OK))!=-1)
  19585. {
  19586. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19587. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19588. system(rmFileCmd);
  19589. }
  19590. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19591. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19592. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  19593. else
  19594. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19595. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19596. systemresult = system(ftpbuf);
  19597. if(systemresult != 0)
  19598. {
  19599. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19600. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --ca-certificate=/root/cacert.pem",filename, url);
  19601. else
  19602. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --no-check-certificate",filename, url);
  19603. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19604. systemresult = system(ftpbuf);
  19605. if(systemresult != 0)
  19606. {
  19607. DEBUG_WARN("FTP download fail!\n");
  19608. result = FALSE;
  19609. }
  19610. }
  19611. system("pkill ping");
  19612. return result;
  19613. }
  19614. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19615. {
  19616. char rmFileCmd[100]={0};
  19617. char FilePath[100]={0};
  19618. char buf[512];
  19619. int systemresult = 0;
  19620. //DEBUG_INFO("filename=%s\n",filename);
  19621. //DEBUG_INFO("url=%s\n",url);
  19622. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19623. if((access(FilePath,F_OK))!=-1)
  19624. {
  19625. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19626. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19627. system(rmFileCmd);
  19628. }
  19629. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19630. if(fp == NULL)
  19631. {
  19632. DEBUG_INFO("log is NULL\n");
  19633. return FALSE;
  19634. }
  19635. else
  19636. {
  19637. fprintf(fp, "%s\n", url);
  19638. fprintf(fp, "%s\n", filename);
  19639. fclose(fp);
  19640. }
  19641. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19642. if(phpFP == NULL)
  19643. {
  19644. DEBUG_INFO("PHP upload fail.\n");
  19645. return FALSE;
  19646. }
  19647. else
  19648. {
  19649. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19650. {
  19651. if(strstr(buf, "result") != NULL)
  19652. {
  19653. sscanf(buf, "result: %d", &systemresult);
  19654. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19655. }
  19656. }
  19657. pclose(phpFP);
  19658. }
  19659. if(systemresult != 1)
  19660. {
  19661. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19662. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19663. if(phpFP == NULL)
  19664. {
  19665. DEBUG_WARN("PHP PUT upload fail.\n");
  19666. return FALSE;
  19667. }
  19668. else
  19669. {
  19670. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19671. {
  19672. if(strstr(buf, "result") != NULL)
  19673. {
  19674. sscanf(buf, "result: %d", &systemresult);
  19675. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19676. }
  19677. }
  19678. pclose(phpFP);
  19679. }
  19680. }
  19681. if(systemresult != 1)
  19682. {
  19683. DEBUG_WARN("PHP PUT upload fail.\n");
  19684. return FALSE;
  19685. }
  19686. return TRUE;
  19687. }
  19688. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19689. {
  19690. int result = FALSE;
  19691. char ftpbuf[200];
  19692. int systemresult;
  19693. /*
  19694. // Domaind name transfer to IP address
  19695. struct hostent* server;
  19696. char *IPbuffer;
  19697. server = gethostbyname(location);
  19698. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19699. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19700. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19701. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19702. systemresult = system(ftpbuf);
  19703. if(systemresult != 0)
  19704. {
  19705. DEBUG_INFO("ftpput error!\n");
  19706. }
  19707. else
  19708. {
  19709. result = TRUE;
  19710. DEBUG_INFO("ftpput OK!\n");
  19711. }
  19712. return result;
  19713. }
  19714. int GetOcppServerURL()
  19715. {
  19716. int result = FALSE;
  19717. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19718. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19719. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19720. struct yuarel url;
  19721. char urlStr[512];
  19722. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19723. {
  19724. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19725. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19726. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19727. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19728. if(yuarel_parse(&url, urlStr) != -1)
  19729. {
  19730. sprintf(OcppProtocol, "%s", url.scheme);
  19731. sprintf(OcppHost, "%s", url.host);
  19732. if(url.path == NULL)
  19733. OcppTempPath[0] = '\0';
  19734. else
  19735. {
  19736. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19737. {
  19738. sprintf(OcppTempPath, "%s/", url.path);
  19739. }
  19740. else
  19741. {
  19742. sprintf(OcppTempPath, "%s", url.path);
  19743. }
  19744. }
  19745. if(url.port == 0)
  19746. {
  19747. if(strcmp(OcppProtocol, "wss") == 0)
  19748. OcppPort = 443;
  19749. else
  19750. OcppPort = 80;
  19751. }
  19752. else
  19753. OcppPort = url.port;
  19754. result = TRUE;
  19755. }
  19756. }
  19757. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19758. {
  19759. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19760. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19761. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19762. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19763. if(yuarel_parse(&url, urlStr) != -1)
  19764. {
  19765. sprintf(OcppProtocol, "%s", url.scheme);
  19766. sprintf(OcppHost, "%s", url.host);
  19767. if(url.path == NULL)
  19768. OcppTempPath[0] = '\0';
  19769. else
  19770. sprintf(OcppTempPath, "%s", url.path);
  19771. if(url.port == 0)
  19772. {
  19773. if(strcmp(OcppProtocol, "wss") == 0)
  19774. OcppPort = 443;
  19775. else
  19776. OcppPort = 80;
  19777. }
  19778. else
  19779. OcppPort = url.port;
  19780. result = TRUE;
  19781. }
  19782. }
  19783. else
  19784. {
  19785. strcpy(OcppHost,"");
  19786. }
  19787. return result;
  19788. }
  19789. int GetOcppPath()
  19790. {
  19791. int result = FALSE;
  19792. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19793. {
  19794. if(OcppTempPath == NULL)
  19795. {
  19796. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19797. }
  19798. else
  19799. {
  19800. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19801. }
  19802. result = TRUE;
  19803. goto End;
  19804. }
  19805. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19806. {
  19807. if(OcppTempPath == NULL)
  19808. {
  19809. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19810. }
  19811. else
  19812. {
  19813. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19814. }
  19815. result = TRUE;
  19816. goto End;
  19817. }
  19818. else
  19819. {
  19820. strcpy(OcppPath,"");
  19821. }
  19822. End:
  19823. return result;
  19824. }
  19825. int GetOcppPort()
  19826. {
  19827. return OcppPort;
  19828. }
  19829. int GetOcppConnStatus(void)
  19830. {
  19831. return ShmOCPP16Data->OcppConnStatus;
  19832. }
  19833. void SetOcppConnStatus(uint8_t status)
  19834. {
  19835. ShmOCPP16Data->OcppConnStatus = status;
  19836. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19837. }
  19838. int GetHeartBeatWithNOResponse(void)
  19839. {
  19840. return HeartBeatWithNOResponse;
  19841. }
  19842. void SetHeartBeatWithNOResponse(void)
  19843. {
  19844. HeartBeatWithNOResponse = 0;
  19845. }
  19846. void GetStartTransactionIdTag(int gun_index)
  19847. {
  19848. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19849. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19850. }
  19851. int GetStartTransactionId(int gun_index)
  19852. {
  19853. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19854. }
  19855. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19856. {
  19857. char ch;
  19858. FILE *fptr1;
  19859. int temptransactionId;
  19860. char str[100]={0};
  19861. temptransactionId = 0;
  19862. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19863. {
  19864. DEBUG_INFO("IdTag is empty.\n");
  19865. return temptransactionId;
  19866. }
  19867. /*------ Read the file ----------------*/
  19868. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19869. if (!fptr1)
  19870. {
  19871. DEBUG_INFO("QueueTransactionId file open error.\n");
  19872. //printf(" File not found or unable to open the input file!!\n");
  19873. return temptransactionId;
  19874. }
  19875. ch=fgetc(fptr1);
  19876. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19877. rewind(fptr1);
  19878. if(ch!=EOF)
  19879. {
  19880. // printf("%c",ch);
  19881. while (fgets(str, 100, fptr1) != NULL)
  19882. {
  19883. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19884. if(str[0]=='\0')
  19885. {
  19886. break;
  19887. }
  19888. char *revbuf[8] = {0}; // Variable store string split
  19889. int num = 0;// Quantity after string split
  19890. DEBUG_INFO("Transaction queue data= %s\n", str);
  19891. splitstring(str,",",revbuf,&num); // String split
  19892. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19893. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19894. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19895. DEBUG_INFO("------------------------------\n");
  19896. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19897. {
  19898. if(isStopTransaction)
  19899. {
  19900. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19901. {
  19902. temptransactionId = atoi(revbuf[2]);
  19903. //break;
  19904. }
  19905. }
  19906. else
  19907. {
  19908. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19909. {
  19910. temptransactionId = atoi(revbuf[2]);
  19911. //break;
  19912. }
  19913. }
  19914. }
  19915. }
  19916. }
  19917. else
  19918. DEBUG_INFO("EOF\n");
  19919. fclose(fptr1);
  19920. /*------- End of reading ---------------*/
  19921. return temptransactionId;
  19922. }
  19923. void SetTransactionIdZero(int transactionId)
  19924. {
  19925. char ch;
  19926. FILE *fptr1, *fptr2;
  19927. int temptransactionId = 0;
  19928. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19929. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19930. if (!fptr1)
  19931. {
  19932. //printf(" File not found or unable to open the input file!!\n");
  19933. return ;
  19934. }
  19935. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19936. if (!fptr2)
  19937. {
  19938. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19939. fclose(fptr1);
  19940. return ;
  19941. }
  19942. ch=fgetc(fptr1);
  19943. rewind(fptr1);
  19944. if(ch!=EOF)
  19945. {
  19946. // copy all contents to the temporary file except the specific line
  19947. while (fgets(str, 100, fptr1) != NULL)
  19948. {
  19949. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19950. if(str[0]=='\0')
  19951. {
  19952. break;
  19953. }
  19954. char *revbuf[8] = {0};
  19955. int num = 0;
  19956. strcpy(strtemp, str);
  19957. splitstring(str,",",revbuf,&num);
  19958. if(revbuf[2][0] != '\0')
  19959. {
  19960. temptransactionId = atoi(revbuf[2]);
  19961. if(transactionId != temptransactionId)
  19962. {
  19963. fprintf(fptr2, "%s\n", strtemp);
  19964. }
  19965. }
  19966. }
  19967. }
  19968. fclose(fptr1);
  19969. fclose(fptr2);
  19970. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19971. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19972. /*------ Read the file ----------------*/
  19973. }
  19974. int InternetDisconnect(void)
  19975. {
  19976. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19977. }
  19978. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19979. void storeTempStopTransaction(int gun_index)
  19980. {
  19981. char guid[37]={0};
  19982. int tempIndex = 0;
  19983. char TempStopTransaction[256];
  19984. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19985. DEBUG_INFO("storeTempStopTransaction...\n");
  19986. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19987. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19988. //=========================== Stop Transaction Time ===============================================
  19989. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  19990. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19991. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19992. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19993. {
  19994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19995. {
  19996. tempIndex = ((gun_index==2) ? 1: 0);
  19997. }
  19998. else
  19999. {
  20000. tempIndex = gun_index;
  20001. }
  20002. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20003. {
  20004. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20005. {
  20006. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  20007. }
  20008. }// END OF CHAdeMO_QUANTITY
  20009. }
  20010. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20011. {
  20012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20013. {
  20014. tempIndex = ((gun_index==2) ? 1: 0);
  20015. }
  20016. else
  20017. {
  20018. tempIndex = gun_index;
  20019. }
  20020. for (int index = 0; index < CCS_QUANTITY; index++)
  20021. {
  20022. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20023. {
  20024. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  20025. }
  20026. }// END OF CCS_QUANTITY
  20027. }
  20028. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20029. {
  20030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20031. {
  20032. tempIndex = ((gun_index==2) ? 1: 0);
  20033. }
  20034. else
  20035. {
  20036. tempIndex = gun_index;
  20037. }
  20038. for (int index = 0; index < GB_QUANTITY; index++)
  20039. {
  20040. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20041. {
  20042. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  20043. }
  20044. }// END OF GB_QUANTITY
  20045. }
  20046. else if(gunType[gun_index] == GUN_TYPE_DO)
  20047. {
  20048. tempIndex = gun_index;
  20049. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20050. {
  20051. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20052. {
  20053. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  20054. }
  20055. }
  20056. }
  20057. else
  20058. {
  20059. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20060. {
  20061. tempIndex = 2;
  20062. }
  20063. else
  20064. {
  20065. tempIndex = gun_index;
  20066. }
  20067. for (int index = 0; index < AC_QUANTITY; index++)
  20068. {
  20069. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20070. {
  20071. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  20072. }
  20073. }// END OF AC_QUANTITY
  20074. }
  20075. //======================================== Message create ==============================================
  20076. json_object *StopTransaction = json_object_new_object();
  20077. json_object *transactionDatas = json_object_new_array();
  20078. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  20079. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  20080. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  20081. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  20082. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  20083. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  20084. meterValueBufferQuery(gun_index, transactionDatas);
  20085. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  20086. random_uuid(guid);
  20087. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  20088. ,MESSAGE_TYPE_CALL
  20089. ,guid
  20090. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  20091. json_object_put(StopTransaction);
  20092. // Check File "TempStopTransaction" Exist
  20093. if((access(TempStopTransaction,F_OK))!=-1)
  20094. {
  20095. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  20096. fclose(fopen(TempStopTransaction, "w"));
  20097. }
  20098. else
  20099. {
  20100. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  20101. FILE *log = fopen(TempStopTransaction, "w+");
  20102. if(log == NULL)
  20103. {
  20104. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  20105. return ;
  20106. }
  20107. else
  20108. {
  20109. fclose(log);
  20110. }
  20111. }
  20112. //Add TempStopTransaction | Update TempStopTransaction
  20113. // open file for writing
  20114. FILE *outfile;
  20115. outfile = fopen (TempStopTransaction, "a");
  20116. //DEBUG_INFO("data = %s\n", queuedata);
  20117. fputs(queuedata, outfile);
  20118. fputs("\n", outfile);
  20119. fclose (outfile);
  20120. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20121. OCPP_updatePeriodEnergy(gun_index);
  20122. }
  20123. void checkTempStopTransaction(int gun_index)
  20124. {
  20125. FILE *fptr1;
  20126. char ch;
  20127. char str[QUEUE_MESSAGE_LENGTH]={0};
  20128. char guid[37]={0};
  20129. char tempdata[65]={0};
  20130. char connectorStr[2]={0};
  20131. char TempStopTransaction[256];
  20132. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20133. fptr1 = fopen(TempStopTransaction, "r");
  20134. //TempStopTransaction格式: 槍號,StopTransaction封包
  20135. if (!fptr1)
  20136. {
  20137. //printf(" File not found or unable to open the input file!!\n");
  20138. return ;
  20139. }
  20140. ch=fgetc(fptr1);
  20141. //printf(" Now the content of the file %s is : \n",fname);
  20142. rewind(fptr1);
  20143. if(ch!=EOF)
  20144. {
  20145. // copy all contents to the temporary file except the specific line
  20146. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  20147. {
  20148. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20149. if(str[0]=='\0')
  20150. {
  20151. break;
  20152. }
  20153. //TempStopTransaction格式: 槍號,StopTransaction封包
  20154. strncpy(connectorStr, str, 1);
  20155. if(atoi(connectorStr) != (gun_index+1))
  20156. {
  20157. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  20158. fclose(fptr1);
  20159. return ;
  20160. }
  20161. //random_uuid(guid);
  20162. strncpy(guid, str+6, 36); //copy guid
  20163. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  20164. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  20165. {
  20166. //DEBUG_INFO("StopTransaction mapitem pass\n");
  20167. }
  20168. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  20169. OCPP_insert_transaction_msg(NO, str);
  20170. memset(str,0,ARRAY_SIZE(str));
  20171. }
  20172. }
  20173. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  20174. fclose(fptr1);
  20175. remove(TempStopTransaction); // remove the original file
  20176. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20177. }
  20178. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  20179. {
  20180. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20181. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  20182. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  20183. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  20184. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  20185. }
  20186. void FillTransactionId(int ConnectorId, int TransactionId)
  20187. {
  20188. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20189. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  20190. }
  20191. int GetWebSocketPingInterval(void)
  20192. {
  20193. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  20194. }
  20195. int GetServerSign(void)
  20196. {
  20197. return server_sign;
  20198. }
  20199. uint8_t GetOcppSecurityProfile()
  20200. {
  20201. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  20202. }
  20203. void MergeCertificates()
  20204. {
  20205. char cmdBuf[2048]={0};
  20206. if(access(ROOTCA_CS,F_OK) != -1)
  20207. {
  20208. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  20209. }
  20210. else
  20211. {
  20212. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  20213. }
  20214. system(cmdBuf);
  20215. }
  20216. void GetOcppChargerBoxId(uint8_t *data)
  20217. {
  20218. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20219. }
  20220. void GetOcppSecurityPassword(uint8_t *data)
  20221. {
  20222. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  20223. }
  20224. void SetOcppVersion(uint8_t *version)
  20225. {
  20226. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  20227. DEBUG_INFO("ocpp version: %s\n", version);
  20228. if(strstr((char*)version, "ocpp1.6") != NULL)
  20229. {
  20230. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  20231. }
  20232. else if(strstr((char*)version, "ocpp2.0") != NULL)
  20233. {
  20234. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  20235. system("pkill OcppBackend");
  20236. }
  20237. }
  20238. void SetServerSign(int value)
  20239. {
  20240. server_sign = value;
  20241. }
  20242. int GetBootNotificationInterval(void)
  20243. {
  20244. return BootNotificationInterval;
  20245. }
  20246. int GetInternetConn(void)
  20247. {
  20248. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  20249. }
  20250. int GetBackendConnectionTimeout(void)
  20251. {
  20252. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20253. }
  20254. int isConnectorInitMode(int gun_index)
  20255. {
  20256. int tempIndex = 0;
  20257. int result = TRUE;
  20258. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20259. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20260. {
  20261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20262. {
  20263. tempIndex = ((gun_index==2) ? 1: 0);
  20264. }
  20265. else
  20266. {
  20267. tempIndex = gun_index;
  20268. }
  20269. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20270. {
  20271. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20272. {
  20273. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20274. } //end of the same index
  20275. }//end of for CHAdeMO_QUANTITY
  20276. }
  20277. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20278. {
  20279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20280. {
  20281. tempIndex = ((gun_index==2) ? 1: 0);
  20282. }
  20283. else
  20284. {
  20285. tempIndex = gun_index;
  20286. }
  20287. for (int index = 0; index < CCS_QUANTITY; index++)
  20288. {
  20289. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20290. {
  20291. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20292. } //end of the same index
  20293. } // end of for CCS_QUANTITY
  20294. }
  20295. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20296. {
  20297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20298. {
  20299. tempIndex = ((gun_index==2) ? 1: 0);
  20300. }
  20301. else
  20302. {
  20303. tempIndex = gun_index;
  20304. }
  20305. for (int index = 0; index < GB_QUANTITY; index++)
  20306. {
  20307. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20308. {
  20309. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20310. } //end of the same index
  20311. } // end of for GB_QUANTITY
  20312. }
  20313. else if(gunType[gun_index] == GUN_TYPE_DO)
  20314. {
  20315. tempIndex = gun_index;
  20316. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20317. {
  20318. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20319. {
  20320. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20321. } //end of the same index
  20322. }
  20323. }
  20324. else
  20325. {
  20326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20327. {
  20328. tempIndex = 2;
  20329. }
  20330. else
  20331. {
  20332. tempIndex = gun_index;
  20333. }
  20334. for (int index = 0; index < AC_QUANTITY; index++)
  20335. {
  20336. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20337. {
  20338. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20339. }//end of the same index
  20340. }//end of for AC_QUANTITY
  20341. }
  20342. return result;
  20343. }
  20344. void refreshProcDogTimer()
  20345. {
  20346. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20347. }
  20348. void InitialSystemValue(void)
  20349. {
  20350. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20351. locallistVersion=0;
  20352. BootNotificationInterval = 0;
  20353. authorizeRetryTimes = 0;
  20354. GunStatusInterval = 10;
  20355. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20356. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20357. //Heart Beat
  20358. HeartBeatWithNOResponse = 0;
  20359. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20360. if(HeartBeatWaitTime == 0)
  20361. FirstHeartBeat = TRUE;
  20362. else
  20363. FirstHeartBeat = FALSE;
  20364. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20365. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20366. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20367. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20368. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20369. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20370. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20371. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20372. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20373. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20374. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20375. //Status && ConnectorPlugIn Setting
  20376. Connector0PreviousSystemStatus = 99;
  20377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20378. {
  20379. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20380. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20381. }
  20382. for (int index = 0; index < CCS_QUANTITY; index++)
  20383. {
  20384. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20385. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20386. }
  20387. for (int index = 0; index < GB_QUANTITY; index++)
  20388. {
  20389. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20390. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20391. }
  20392. for (int index = 0; index < AC_QUANTITY; index++)
  20393. {
  20394. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20395. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20396. }
  20397. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20398. {
  20399. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20400. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20401. }
  20402. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20403. {
  20404. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20405. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20406. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20407. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20408. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20409. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20410. }
  20411. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20412. refreshStartTimer(&clientTime.Heartbeat);
  20413. sleep(1);
  20414. }
  20415. void LWS_Send(char *str)
  20416. {
  20417. //=====================================================
  20418. // Check InternetConn 0: disconnected, 1: connected
  20419. //====================================================
  20420. if(GetOcppConnStatus() == 0)
  20421. {
  20422. DEBUG_INFO("offline now !!!\n");
  20423. return;
  20424. }
  20425. // Only disable isWebsocketSendable operation initiated by charger
  20426. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20427. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20428. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20429. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20430. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20431. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20432. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20433. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20434. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20435. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20436. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20437. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20438. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20439. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20440. {
  20441. isWebsocketSendable = 0;
  20442. }
  20443. pthread_mutex_lock(&lock_send);
  20444. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20445. sprintf((char *)SendBuffer, "%s", str);
  20446. SendBufLen = strlen(str);
  20447. pthread_mutex_unlock(&lock_send);
  20448. lws_callback_on_writable(wsi_client);
  20449. //lws_service(context, 0);
  20450. //sleep(1);
  20451. }
  20452. void LWS_SendNow(char *str)
  20453. {
  20454. //=====================================================
  20455. // Check InternetConn 0: disconnected, 1: connected
  20456. //====================================================
  20457. if(GetOcppConnStatus() == 0)
  20458. {
  20459. DEBUG_INFO("offline now !!!\n");
  20460. return;
  20461. }
  20462. // Only disable isWebsocketSendable operation initiated by charger
  20463. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20464. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20465. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20466. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20467. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20468. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20469. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20470. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20471. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20472. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20473. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20474. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20475. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20476. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20477. {
  20478. isWebsocketSendable = 0;
  20479. }
  20480. pthread_mutex_lock(&lock_send);
  20481. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20482. sprintf((char *)SendBuffer, "%s", str);
  20483. SendBufLen = strlen(str);
  20484. pthread_mutex_unlock(&lock_send);
  20485. lws_callback_on_writable(wsi_client);
  20486. lws_service(context, 0);
  20487. //sleep(1);
  20488. }